Skip to content

Commit 335f055

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

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
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: 9 additions & 2 deletions
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`'));
@@ -155,5 +162,5 @@ export default async function() {
155162
await ng('build', '--i18n-missing-translation', 'ignore');
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'));
159166
}

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ export default async function() {
5555

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

5961
// Add locale definitions to the project
6062
// tslint:disable-next-line: no-any
@@ -102,9 +104,15 @@ export default async function() {
102104
}
103105

104106
// Build each locale and verify the output.
105-
await ng('build', '--i18n-missing-translation', 'error');
107+
// NOTE: this should not fail in general, but multi-locale translation is currently disabled.
108+
// TODO: remove expectToFail when functionality is re-enabled.
109+
await expectToFail(() => ng('build'));
106110
for (const { lang, translation } of langTranslations) {
111+
// NOTE: remove this extra single build once the above expectToFail is removed.
112+
await ng('build', '-c', lang);
113+
107114
await expectFileToMatch(`${baseDir}/${lang}/main.js`, translation);
115+
await expectFileToMatch(`${baseDir}/${lang}/main.js`, 'registerLocaleData');
108116
await expectToFail(() => expectFileToMatch(`${baseDir}/${lang}/main.js`, '$localize`'));
109117
await expectFileNotToExist(`${baseDir}/${lang}/main-es2015.js`);
110118
await expectFileToMatch(`${baseDir}/${lang}/main.js`, lang);
@@ -142,9 +150,13 @@ export default async function() {
142150
}
143151
}
144152

153+
// Verify locale data registration (currently only for single locale builds)
154+
await ng('build', '--optimization', 'false', '-c', 'fr', '--i18n-missing-translation', 'error');
155+
await expectFileToMatch(`${baseDir}/fr/main.js`, 'registerLocaleData');
156+
145157
// Verify missing translation behaviour.
146158
await appendToFile('src/app/app.component.html', '<p i18n>Other content</p>');
147159
await ng('build', '--i18n-missing-translation', 'ignore');
148160
await expectFileToMatch(`${baseDir}/fr/main.js`, /Other content/);
149-
await expectToFail(() => ng('build', '--i18n-missing-translation', 'error'));
161+
await expectToFail(() => ng('build'));
150162
}

0 commit comments

Comments
 (0)