Skip to content

Commit 1ee68c8

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

File tree

4 files changed

+46
-10
lines changed

4 files changed

+46
-10
lines changed

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

+5
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

+10-3
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ export default async function() {
5454

5555
// Enable localization for all locales
5656
appArchitect['build'].options.localize = true;
57+
// Always error on missing translations.
58+
appArchitect['build'].options.i18nMissingTranslation = 'error';
5759

5860
// Add locale definitions to the project
5961
// tslint:disable-next-line: no-any
@@ -103,8 +105,13 @@ export default async function() {
103105
}
104106

105107
// Build each locale and verify the output.
106-
await ng('build', '--i18n-missing-translation', 'error');
108+
// NOTE: this should not fail in general, but multi-locale translation is currently disabled.
109+
// TODO: remove expectToFail when functionality is re-enabled.
110+
await expectToFail(() => ng('build'));
107111
for (const { lang, translation } of langTranslations) {
112+
// NOTE: remove this extra single build once the above expectToFail is removed.
113+
await ng('build', '-c', lang);
114+
108115
await expectFileToMatch(`${baseDir}/${lang}/main-es5.js`, translation);
109116
await expectFileToMatch(`${baseDir}/${lang}/main-es2015.js`, translation);
110117
await expectToFail(() => expectFileToMatch(`${baseDir}/${lang}/main-es5.js`, '$localize`'));
@@ -152,8 +159,8 @@ export default async function() {
152159

153160
// Verify missing translation behaviour.
154161
await appendToFile('src/app/app.component.html', '<p i18n>Other content</p>');
155-
await ng('build', '--i18n-missing-translation', 'ignore');
162+
await ng('build', '--i18n-missing-translation', 'ignore', '-c', 'fr');
156163
await expectFileToMatch(`${baseDir}/fr/main-es5.js`, /Other content/);
157164
await expectFileToMatch(`${baseDir}/fr/main-es2015.js`, /Other content/);
158-
await expectToFail(() => ng('build', '--i18n-missing-translation', 'error'));
165+
await expectToFail(() => ng('build', '-c', 'fr'));
159166
}

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

+13-4
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export default async function() {
4242
const appArchitect = appProject.architect || appProject.targets;
4343
const serveConfigs = appArchitect['serve'].configurations;
4444
const e2eConfigs = appArchitect['e2e'].configurations;
45+
const buildConfigs = appArchitect['build'].configurations;
4546

4647
// Make default builds prod.
4748
appArchitect['build'].options.optimization = true;
@@ -56,6 +57,8 @@ export default async function() {
5657

5758
// Enable localization for all locales
5859
appArchitect['build'].options.localize = true;
60+
// Always error on missing translations.
61+
appArchitect['build'].options.i18nMissingTranslation = 'error';
5962

6063
// Add locale definitions to the project
6164
// tslint:disable-next-line: no-any
@@ -66,6 +69,8 @@ export default async function() {
6669
} else {
6770
i18n.locales[lang] = `src/locale/messages.${lang}.xlf`;
6871
}
72+
73+
buildConfigs[lang] = { localize: [lang] };
6974
serveConfigs[lang] = { browserTarget: `test-project:build:${lang}` };
7075
e2eConfigs[lang] = {
7176
specs: [`./src/app.${lang}.e2e-spec.ts`],
@@ -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`);
@@ -145,7 +154,7 @@ export default async function() {
145154

146155
// Verify missing translation behaviour.
147156
await appendToFile('src/app/app.component.html', '<p i18n>Other content</p>');
148-
await ng('build', '--i18n-missing-translation', 'ignore');
157+
await ng('build', '--i18n-missing-translation', 'ignore', '-c', 'fr');
149158
await expectFileToMatch(`${baseDir}/fr/main.js`, /Other content/);
150-
await expectToFail(() => ng('build', '--i18n-missing-translation', 'error'));
159+
await expectToFail(() => ng('build', '-c', 'fr'));
151160
}

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

+18-3
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export default async function() {
4141
const appArchitect = appProject.architect || appProject.targets;
4242
const serveConfigs = appArchitect['serve'].configurations;
4343
const e2eConfigs = appArchitect['e2e'].configurations;
44+
const buildConfigs = appArchitect['build'].configurations;
4445

4546
// Make default builds prod.
4647
appArchitect['build'].options.optimization = true;
@@ -55,6 +56,8 @@ export default async function() {
5556

5657
// Enable localization for all locales
5758
appArchitect['build'].options.localize = true;
59+
// Always error on missing translations.
60+
appArchitect['build'].options.i18nMissingTranslation = 'error';
5861

5962
// Add locale definitions to the project
6063
// tslint:disable-next-line: no-any
@@ -65,6 +68,8 @@ export default async function() {
6568
} else {
6669
i18n.locales[lang] = `src/locale/messages.${lang}.xlf`;
6770
}
71+
72+
buildConfigs[lang] = { localize: [lang] };
6873
serveConfigs[lang] = { browserTarget: `test-project:build:${lang}` };
6974
e2eConfigs[lang] = {
7075
specs: [`./src/app.${lang}.e2e-spec.ts`],
@@ -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>');
147-
await ng('build', '--i18n-missing-translation', 'ignore');
162+
await ng('build', '--i18n-missing-translation', 'ignore', '-c', 'fr');
148163
await expectFileToMatch(`${baseDir}/fr/main.js`, /Other content/);
149-
await expectToFail(() => ng('build', '--i18n-missing-translation', 'error'));
164+
await expectToFail(() => ng('build', '-c', 'fr'));
150165
}

0 commit comments

Comments
 (0)