Skip to content

Commit a2ebf14

Browse files
committed
refactor(@angular-devkit/build-angular): re-enable multi-localize support
1 parent 4afca00 commit a2ebf14

File tree

6 files changed

+15
-39
lines changed

6 files changed

+15
-39
lines changed

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

-8
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,6 @@ export async function configureI18nBuild<T extends BrowserBuilderSchema | Server
106106
}
107107

108108
const buildOptions = { ...options };
109-
110-
if (
111-
buildOptions.localize === true ||
112-
(Array.isArray(buildOptions.localize) && buildOptions.localize.length > 1)
113-
) {
114-
throw new Error('Using the localize option for multiple locales is temporarily disabled.');
115-
}
116-
117109
const tsConfig = readTsconfig(buildOptions.tsConfig, context.workspaceRoot);
118110
const usingIvy = tsConfig.options.enableIvy !== false;
119111
const metadata = await context.getProjectMetadata(context.target);

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

+10-12
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,21 @@ export default async function() {
1414
config.angularCompilerOptions.disableTypeScriptVersionCheck = true;
1515
});
1616

17-
// TODO: re-enable all locales once localeData support is added.
18-
const tempLangTranslations = langTranslations.filter(l => l.lang == 'fr');
19-
2017
// Build each locale and verify the output.
21-
// NOTE: this should not fail in general, but multi-locale translation is currently disabled.
22-
// TODO: remove expectToFail once localeData support is added.
23-
await expectToFail(() => ng('build', '--localize', 'true'));
2418
await ng('build');
25-
for (const { lang, outputPath, translation } of tempLangTranslations) {
19+
for (const { lang, outputPath, translation } of langTranslations) {
2620
await expectFileToMatch(`${outputPath}/main-es5.js`, translation.helloPartial);
2721
await expectFileToMatch(`${outputPath}/main-es2015.js`, translation.helloPartial);
2822
await expectToFail(() => expectFileToMatch(`${outputPath}/main-es5.js`, '$localize`'));
2923
await expectToFail(() => expectFileToMatch(`${outputPath}/main-es2015.js`, '$localize`'));
3024

3125
// Verify the locale ID is present
32-
await expectFileToMatch(`${outputPath}/main-es5.js`, lang);
33-
await expectFileToMatch(`${outputPath}/main-es2015.js`, lang);
26+
await expectFileToMatch(`${outputPath}/vendor-es5.js`, lang);
27+
await expectFileToMatch(`${outputPath}/vendor-es2015.js`, lang);
3428

3529
// Verify the locale data is registered using the global files
36-
await expectFileToMatch(`${outputPath}/main-es5.js`, '.ng.common.locales');
37-
await expectFileToMatch(`${outputPath}/main-es2015.js`, '.ng.common.locales');
30+
await expectFileToMatch(`${outputPath}/vendor-es5.js`, '.ng.common.locales');
31+
await expectFileToMatch(`${outputPath}/vendor-es2015.js`, '.ng.common.locales');
3832

3933
// Execute Application E2E tests with dev server
4034
await ng('e2e', `--configuration=${lang}`, '--port=0');
@@ -60,7 +54,11 @@ export default async function() {
6054
await expectFileToMatch(`${baseDir}/fr/main-es2015.js`, /Other content/);
6155
await expectToFail(() => ng('build'));
6256
try {
63-
await execAndWaitForOutputToMatch('ng', ['serve', '--port=0'], /No translation found for/);
57+
await execAndWaitForOutputToMatch(
58+
'ng',
59+
['serve', '--configuration=fr', '--port=0'],
60+
/No translation found for/,
61+
);
6462
} finally {
6563
killAllProcesses();
6664
}

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

+1-5
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,8 @@ export default async function() {
1515
config.angularCompilerOptions.disableTypeScriptVersionCheck = true;
1616
});
1717

18-
19-
// TODO: re-enable all locales once localeData support is added.
20-
const tempLangTranslations = langTranslations.filter(l => l.lang == 'fr');
21-
2218
await ng('build');
23-
for (const { lang, outputPath, translation } of tempLangTranslations) {
19+
for (const { lang, outputPath, translation } of langTranslations) {
2420
await expectFileToMatch(`${outputPath}/main.js`, translation.helloPartial);
2521
await expectToFail(() => expectFileToMatch(`${outputPath}/main.js`, '$localize`'));
2622
await expectFileNotToExist(`${outputPath}/main-es5.js`);

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

+1-4
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,9 @@ export default async function() {
1414
config.angularCompilerOptions.disableTypeScriptVersionCheck = true;
1515
});
1616

17-
// TODO: re-enable all locales once localeData support is added.
18-
const tempLangTranslations = langTranslations.filter(l => l.lang == 'fr');
19-
2017
// Build each locale and verify the output.
2118
await ng('build');
22-
for (const { lang, outputPath, translation } of tempLangTranslations) {
19+
for (const { lang, outputPath, translation } of langTranslations) {
2320
await expectFileToMatch(`${outputPath}/main.js`, translation.helloPartial);
2421
await expectToFail(() => expectFileToMatch(`${outputPath}/main.js`, '$localize`'));
2522
await expectFileNotToExist(`${outputPath}/main-es2015.js`);

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

+1-4
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@ export default async function () {
3232
const serverbaseDir = 'dist/test-project/server';
3333
const serverBuildArgs = ['run', 'test-project:server'];
3434

35-
// TODO: re-enable all locales once localeData support is added.
36-
const tempLangTranslations = langTranslations.filter(l => l.lang == 'fr');
37-
3835
// Add server-specific config.
3936
await updateJsonFile('angular.json', workspaceJson => {
4037
const appProject = workspaceJson.projects['test-project'];
@@ -106,7 +103,7 @@ export default async function () {
106103
await ng('build');
107104
await ng(...serverBuildArgs);
108105

109-
for (const { lang, translation } of tempLangTranslations) {
106+
for (const { lang, translation } of langTranslations) {
110107
await expectFileToMatch(`${serverbaseDir}/${lang}/main.js`, translation.helloPartial);
111108
await expectToFail(() => expectFileToMatch(`${serverbaseDir}/${lang}/main.js`, '$localize`'));
112109

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

+2-6
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@ import { updateJsonFile } from '../../utils/project';
77
import { expectToFail } from '../../utils/utils';
88
import { readNgVersion } from '../../utils/version';
99

10-
1110
// Configurations for each locale.
1211
export const baseDir = 'dist/test-project';
1312
export const langTranslations = [
1413
{
15-
lang: 'en-US', outputPath: `${baseDir}/en`,
14+
lang: 'en-US', outputPath: `${baseDir}/en-US`,
1615
translation: {
1716
helloPartial: 'Hello',
1817
hello: 'Hello i18n!',
@@ -59,7 +58,6 @@ export const langTranslations = [
5958
];
6059
export const sourceLocale = langTranslations[0].lang;
6160
export const externalServer = (outputPath: string) => {
62-
// Ivy i18n doesn't yet work with `ng serve` so we must use a separate server.
6361
const app = express();
6462
app.use(express.static(resolve(outputPath)));
6563

@@ -142,9 +140,7 @@ export async function setupI18nConfig(useLocalize = true) {
142140

143141
if (useLocalize) {
144142
// Enable localization for all locales
145-
// TODO: re-enable all locales once localeData support is added.
146-
// appArchitect['build'].options.localize = true;
147-
appArchitect['build'].options.localize = ['fr'];
143+
appArchitect['build'].options.localize = true;
148144
}
149145

150146
// Add i18n config items (app, build, serve, e2e).

0 commit comments

Comments
 (0)