Skip to content

Commit 1812c82

Browse files
filipesilvavikerman
authored andcommitted
fix(@angular-devkit/build-angular): temporarily disable localize for multiple locales
Related to #15974
1 parent b9aad55 commit 1812c82

File tree

8 files changed

+74
-27
lines changed

8 files changed

+74
-27
lines changed

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

+16-5
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,21 @@ export async function configureI18nBuild<T extends BrowserBuilderSchema | Server
9595
context: BuilderContext,
9696
options: T,
9797
): Promise<{
98-
buildOptions: T,
99-
i18n: I18nOptions,
98+
buildOptions: T;
99+
i18n: I18nOptions;
100100
}> {
101101
if (!context.target) {
102102
throw new Error('The builder requires a target.');
103103
}
104104

105-
const buildOptions = { ... options };
105+
const buildOptions = { ...options };
106+
107+
if (
108+
buildOptions.localize === true ||
109+
(Array.isArray(buildOptions.localize) && buildOptions.localize.length > 1)
110+
) {
111+
throw new Error('Using the localize option for multiple locales is temporarily disabled.');
112+
}
106113

107114
const tsConfig = readTsconfig(buildOptions.tsConfig, context.workspaceRoot);
108115
const usingIvy = tsConfig.options.enableIvy !== false;
@@ -162,14 +169,18 @@ export async function configureI18nBuild<T extends BrowserBuilderSchema | Server
162169
process.on('exit', () => {
163170
try {
164171
rimraf.sync(tempPath);
165-
} catch { }
172+
} catch {}
166173
});
167174
}
168175

169176
return { buildOptions, i18n };
170177
}
171178

172-
function mergeDeprecatedI18nOptions(i18n: I18nOptions, i18nLocale: string | undefined, i18nFile: string | undefined): I18nOptions {
179+
function mergeDeprecatedI18nOptions(
180+
i18n: I18nOptions,
181+
i18nLocale: string | undefined,
182+
i18nFile: string | undefined,
183+
): I18nOptions {
173184
if (i18nFile !== undefined && i18nLocale === undefined) {
174185
throw new Error(`Option 'i18nFile' cannot be used without the 'i18nLocale' option.`);
175186
}

tests/legacy-cli/e2e/tests/build/aot/aot-i18n.ts

+2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ export default async function () {
3636
},
3737
];
3838

39+
await replaceInFile('src/app/app.component.ts', `title = 'test-project';`, `title = 'test-project';minutes=3;`);
40+
3941
await updateJsonFile('angular.json', workspaceJson => {
4042
const appArchitect = workspaceJson.projects['test-project'].architect;
4143
const browserConfigs = appArchitect['build'].configurations;

tests/legacy-cli/e2e/tests/i18n/ivy-localize-app-shell.ts

+3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ import { readNgVersion } from '../../utils/version';
1414
const snapshots = require('../../ng-snapshot/package.json');
1515

1616
export default async function () {
17+
// TEMP: disable pending i18n updates
18+
return;
19+
1720
const isSnapshotBuild = getGlobalVariable('argv')['ng-snapshots'];
1821

1922
await updateJsonFile('package.json', packageJson => {

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

+12-4
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', '--localize', '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

+10-6
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,8 +107,7 @@ export default async function() {
102107
}
103108
}
104109

105-
// Build each locale and verify the output.
106-
await ng('build', '--i18n-missing-translation', 'error');
110+
await ng('build');
107111
for (const { lang, translation } of langTranslations) {
108112
await expectFileToMatch(`${baseDir}/${lang}/main.js`, translation);
109113
await expectToFail(() => expectFileToMatch(`${baseDir}/${lang}/main.js`, '$localize`'));
@@ -147,5 +151,5 @@ export default async function() {
147151
await appendToFile('src/app/app.component.html', '<p i18n>Other content</p>');
148152
await ng('build', '--i18n-missing-translation', 'ignore');
149153
await expectFileToMatch(`${baseDir}/fr/main.js`, /Other content/);
150-
await expectToFail(() => ng('build', '--i18n-missing-translation', 'error'));
154+
await expectToFail(() => ng('build'));
151155
}

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

+14-5
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,7 +107,7 @@ export default async function() {
102107
}
103108

104109
// Build each locale and verify the output.
105-
await ng('build', '--i18n-missing-translation', 'error');
110+
await ng('build');
106111
for (const { lang, translation } of langTranslations) {
107112
await expectFileToMatch(`${baseDir}/${lang}/main.js`, translation);
108113
await expectToFail(() => expectFileToMatch(`${baseDir}/${lang}/main.js`, '$localize`'));
@@ -142,9 +147,13 @@ export default async function() {
142147
}
143148
}
144149

150+
// Verify locale data registration (currently only for single locale builds)
151+
await ng('build', '--optimization', 'false', '--i18n-missing-translation', 'error');
152+
await expectFileToMatch(`${baseDir}/fr/main.js`, 'registerLocaleData');
153+
145154
// Verify missing translation behaviour.
146155
await appendToFile('src/app/app.component.html', '<p i18n>Other content</p>');
147156
await ng('build', '--i18n-missing-translation', 'ignore');
148157
await expectFileToMatch(`${baseDir}/fr/main.js`, /Other content/);
149-
await expectToFail(() => ng('build', '--i18n-missing-translation', 'error'));
158+
await expectToFail(() => ng('build'));
150159
}

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

+13-6
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ export default async function () {
4242

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

@@ -72,8 +73,14 @@ export default async function () {
7273
];
7374

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

7885
// Add locale definitions to the project
7986
// tslint:disable-next-line: no-any
@@ -158,8 +165,8 @@ export default async function () {
158165
}
159166

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

164171
for (const { lang, translation } of langTranslations) {
165172
await expectFileToMatch(`${serverbaseDir}/${lang}/main.js`, translation);
@@ -205,5 +212,5 @@ export default async function () {
205212
await appendToFile('src/app/app.component.html', '<p i18n>Other content</p>');
206213
await ng(...serverBuildArgs, '--i18n-missing-translation', 'ignore');
207214
await expectFileToMatch(`${serverbaseDir}/fr/main.js`, /Other content/);
208-
await expectToFail(() => ng(...serverBuildArgs, '--i18n-missing-translation', 'error'));
215+
await expectToFail(() => ng(...serverBuildArgs));
209216
}

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

+4-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ import { expectToFail } from '../../utils/utils';
1414
import { readNgVersion } from '../../utils/version';
1515

1616
export default async function() {
17+
// TEMP: disable pending i18n updates
18+
return;
19+
1720
let localizeVersion = '@angular/localize@' + readNgVersion();
1821
if (getGlobalVariable('argv')['ng-snapshots']) {
1922
localizeVersion = require('../../ng-snapshot/package.json').dependencies['@angular/localize'];
@@ -62,7 +65,7 @@ export default async function() {
6265
appArchitect['build'].options.serviceWorker = true;
6366

6467
// Enable localization for all locales
65-
appArchitect['build'].options.localize = true;
68+
// appArchitect['build'].options.localize = true;
6669

6770
// Add locale definitions to the project
6871
// tslint:disable-next-line: no-any

0 commit comments

Comments
 (0)