Skip to content

Commit 1728add

Browse files
committed
fix(@angular-devkit/build-angular): temporarily disable localize for multiple locales
Related to angular#15974
1 parent 1baf826 commit 1728add

File tree

5 files changed

+64
-21
lines changed

5 files changed

+64
-21
lines changed

packages/angular_devkit/build_angular/src/utils/i18n-options.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,11 @@ export async function configureI18nBuild<T extends BrowserBuilderSchema | Server
105105

106106
const buildOptions = { ... options };
107107

108+
if (buildOptions.localize === true
109+
|| (Array.isArray(buildOptions.localize) && buildOptions.localize.length > 1)) {
110+
throw new Error('Using the localize option for multiple locales is temporarily disabled.');
111+
}
112+
108113
const tsConfig = readTsconfig(buildOptions.tsConfig, context.workspaceRoot);
109114
const usingIvy = tsConfig.options.enableIvy !== false;
110115
const metadata = await context.getProjectMetadata(context.target);

tests/legacy-cli/e2e/tests/i18n/ivy-localize-dl.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ export default async function() {
3030

3131
// Set configurations for each locale.
3232
const langTranslations = [
33-
{ lang: 'en-US', translation: 'Hello i18n!' },
33+
// TODO: re-enable all locales once localeData support is added.
34+
// { lang: 'en-US', translation: 'Hello i18n!' },
3435
{ lang: 'fr', translation: 'Bonjour i18n!' },
3536
];
3637

@@ -53,7 +54,11 @@ export default async function() {
5354
];
5455

5556
// Enable localization for all locales
56-
appArchitect['build'].options.localize = true;
57+
// TODO: re-enable all locales once localeData support is added.
58+
// appArchitect['build'].options.localize = true;
59+
appArchitect['build'].options.localize = ['fr'];
60+
// Always error on missing translations.
61+
appArchitect['build'].options.i18nMissingTranslation = 'error';
5762

5863
// Add locale definitions to the project
5964
// tslint:disable-next-line: no-any
@@ -103,7 +108,10 @@ export default async function() {
103108
}
104109

105110
// Build each locale and verify the output.
106-
await ng('build', '--i18n-missing-translation', 'error');
111+
// NOTE: this should not fail in general, but multi-locale translation is currently disabled.
112+
// TODO: remove expectToFail once localeData support is added.
113+
await expectToFail(() => ng('build', '--locale', 'true'));
114+
await ng('build');
107115
for (const { lang, translation } of langTranslations) {
108116
await expectFileToMatch(`${baseDir}/${lang}/main-es5.js`, translation);
109117
await expectFileToMatch(`${baseDir}/${lang}/main-es2015.js`, translation);
@@ -155,5 +163,5 @@ export default async function() {
155163
await ng('build', '--i18n-missing-translation', 'ignore');
156164
await expectFileToMatch(`${baseDir}/fr/main-es5.js`, /Other content/);
157165
await expectFileToMatch(`${baseDir}/fr/main-es2015.js`, /Other content/);
158-
await expectToFail(() => ng('build', '--i18n-missing-translation', 'error'));
166+
await expectToFail(() => ng('build'));
159167
}

tests/legacy-cli/e2e/tests/i18n/ivy-localize-es2015.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,10 @@ export default async function() {
3232

3333
// Set configurations for each locale.
3434
const langTranslations = [
35-
{ lang: 'en-US', translation: 'Hello i18n!' },
35+
// TODO: re-enable all locales once localeData support is added.
36+
// { lang: 'en-US', translation: 'Hello i18n!' },
37+
// { lang: 'de', translation: 'Hallo i18n!' },
3638
{ lang: 'fr', translation: 'Bonjour i18n!' },
37-
{ lang: 'de', translation: 'Hallo i18n!' },
3839
];
3940

4041
await updateJsonFile('angular.json', workspaceJson => {
@@ -55,7 +56,11 @@ export default async function() {
5556
];
5657

5758
// Enable localization for all locales
58-
appArchitect['build'].options.localize = true;
59+
// TODO: re-enable all locales once localeData support is added.
60+
// appArchitect['build'].options.localize = true;
61+
appArchitect['build'].options.localize = ['fr'];
62+
// Always error on missing translations.
63+
appArchitect['build'].options.i18nMissingTranslation = 'error';
5964

6065
// Add locale definitions to the project
6166
// tslint:disable-next-line: no-any
@@ -102,9 +107,13 @@ export default async function() {
102107
}
103108
}
104109

105-
// Build each locale and verify the output.
106-
await ng('build', '--i18n-missing-translation', 'error');
110+
// NOTE: this should not fail in general, but multi-locale translation is currently disabled.
111+
// TODO: remove expectToFail when functionality is re-enabled.
112+
await expectToFail(() => ng('build'));
107113
for (const { lang, translation } of langTranslations) {
114+
// NOTE: remove this extra single build once the above expectToFail is removed.
115+
await ng('build', '-c', lang);
116+
108117
await expectFileToMatch(`${baseDir}/${lang}/main.js`, translation);
109118
await expectToFail(() => expectFileToMatch(`${baseDir}/${lang}/main.js`, '$localize`'));
110119
await expectFileNotToExist(`${baseDir}/${lang}/main-es5.js`);
@@ -147,5 +156,5 @@ export default async function() {
147156
await appendToFile('src/app/app.component.html', '<p i18n>Other content</p>');
148157
await ng('build', '--i18n-missing-translation', 'ignore');
149158
await expectFileToMatch(`${baseDir}/fr/main.js`, /Other content/);
150-
await expectToFail(() => ng('build', '--i18n-missing-translation', 'error'));
159+
await expectToFail(() => ng('build'));
151160
}

tests/legacy-cli/e2e/tests/i18n/ivy-localize-es5.ts

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@ export default async function() {
3131

3232
// Set configurations for each locale.
3333
const langTranslations = [
34-
{ lang: 'en-US', translation: 'Hello i18n!' },
34+
// TODO: re-enable all locales once localeData support is added.
35+
// { lang: 'en-US', translation: 'Hello i18n!' },
36+
// { lang: 'de', translation: 'Hallo i18n!' },
3537
{ lang: 'fr', translation: 'Bonjour i18n!' },
36-
{ lang: 'de', translation: 'Hallo i18n!' },
3738
];
3839

3940
await updateJsonFile('angular.json', workspaceJson => {
@@ -54,7 +55,11 @@ export default async function() {
5455
];
5556

5657
// Enable localization for all locales
57-
appArchitect['build'].options.localize = true;
58+
// TODO: re-enable all locales once localeData support is added.
59+
// appArchitect['build'].options.localize = true;
60+
appArchitect['build'].options.localize = ['fr'];
61+
// Always error on missing translations.
62+
appArchitect['build'].options.i18nMissingTranslation = 'error';
5863

5964
// Add locale definitions to the project
6065
// tslint:disable-next-line: no-any
@@ -102,9 +107,15 @@ export default async function() {
102107
}
103108

104109
// Build each locale and verify the output.
105-
await ng('build', '--i18n-missing-translation', 'error');
110+
// NOTE: this should not fail in general, but multi-locale translation is currently disabled.
111+
// TODO: remove expectToFail when functionality is re-enabled.
112+
await expectToFail(() => ng('build'));
106113
for (const { lang, translation } of langTranslations) {
114+
// NOTE: remove this extra single build once the above expectToFail is removed.
115+
await ng('build', '-c', lang);
116+
107117
await expectFileToMatch(`${baseDir}/${lang}/main.js`, translation);
118+
await expectFileToMatch(`${baseDir}/${lang}/main.js`, 'registerLocaleData');
108119
await expectToFail(() => expectFileToMatch(`${baseDir}/${lang}/main.js`, '$localize`'));
109120
await expectFileNotToExist(`${baseDir}/${lang}/main-es2015.js`);
110121
await expectFileToMatch(`${baseDir}/${lang}/main.js`, lang);
@@ -142,9 +153,13 @@ export default async function() {
142153
}
143154
}
144155

156+
// Verify locale data registration (currently only for single locale builds)
157+
await ng('build', '--optimization', 'false', '-c', 'fr', '--i18n-missing-translation', 'error');
158+
await expectFileToMatch(`${baseDir}/fr/main.js`, 'registerLocaleData');
159+
145160
// Verify missing translation behaviour.
146161
await appendToFile('src/app/app.component.html', '<p i18n>Other content</p>');
147162
await ng('build', '--i18n-missing-translation', 'ignore');
148163
await expectFileToMatch(`${baseDir}/fr/main.js`, /Other content/);
149-
await expectToFail(() => ng('build', '--i18n-missing-translation', 'error'));
164+
await expectToFail(() => ng('build'));
150165
}

tests/legacy-cli/e2e/tests/i18n/ivy-localize-server.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ export default async function () {
4343

4444
// Set configurations for each locale.
4545
const langTranslations = [
46-
{ lang: 'en-US', translation: 'Hello i18n!' },
46+
// TODO: re-enable all locales once localeData support is added.
47+
// { lang: 'en-US', translation: 'Hello i18n!' },
4748
{ lang: 'fr', translation: 'Bonjour i18n!' },
4849
];
4950

@@ -73,8 +74,13 @@ export default async function () {
7374
];
7475

7576
// Enable localization for all locales
76-
buildOptions.localize = true;
77-
serverOptions.localize = true;
77+
// TODO: re-enable all locales once localeData support is added.
78+
// buildOptions.localize = true;
79+
// serverOptions.localize = true;
80+
buildOptions.localize = ['fr'];
81+
serverOptions.localize = ['fr'];
82+
// Always error on missing translations.
83+
appArchitect['build'].options.i18nMissingTranslation = 'error';
7884

7985
// Add locale definitions to the project
8086
// tslint:disable-next-line: no-any
@@ -159,8 +165,8 @@ export default async function () {
159165
}
160166

161167
// Build each locale and verify the output.
162-
await ng('build', '--i18n-missing-translation', 'error');
163-
await ng(...serverBuildArgs, '--i18n-missing-translation', 'error');
168+
await ng('build');
169+
await ng(...serverBuildArgs);
164170

165171
for (const { lang, translation } of langTranslations) {
166172
await expectFileToMatch(`${serverbaseDir}/${lang}/main.js`, translation);
@@ -206,5 +212,5 @@ export default async function () {
206212
await appendToFile('src/app/app.component.html', '<p i18n>Other content</p>');
207213
await ng(...serverBuildArgs, '--i18n-missing-translation', 'ignore');
208214
await expectFileToMatch(`${serverbaseDir}/fr/main.js`, /Other content/);
209-
await expectToFail(() => ng(...serverBuildArgs, '--i18n-missing-translation', 'error'));
215+
await expectToFail(() => ng(...serverBuildArgs));
210216
}

0 commit comments

Comments
 (0)