Skip to content

Commit 8fa93e1

Browse files
clydinvikerman
authored andcommitted
fix(@angular-devkit/build-angular): enable locale data transform for single localization
1 parent 7148a16 commit 8fa93e1

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

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

+7-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export function createI18nOptions(
8080
Object.keys(i18n.locales).forEach(locale => i18n.inlineLocales.add(locale));
8181
} else if (inline) {
8282
for (const locale of inline) {
83-
if (!i18n.locales[locale]) {
83+
if (!i18n.locales[locale] && i18n.sourceLocale !== locale) {
8484
throw new Error(`Requested inline locale '${locale}' is not defined for the project.`);
8585
}
8686

@@ -146,6 +146,12 @@ export async function configureI18nBuild<T extends BrowserBuilderSchema | Server
146146
if (usedFormats.size > 0) {
147147
buildOptions.i18nFormat = [...usedFormats][0];
148148
}
149+
150+
// If only one locale is specified set the deprecated option to enable the webpack plugin
151+
// transform to register the locale directly in the output bundle.
152+
if (i18n.inlineLocales.size === 1) {
153+
buildOptions.i18nLocale = [...i18n.inlineLocales][0];
154+
}
149155
}
150156

151157
// If inlining store the output in a temporary location to facilitate post-processing

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

+8
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export default async function() {
3939
const appArchitect = appProject.architect || appProject.targets;
4040
const serveConfigs = appArchitect['serve'].configurations;
4141
const e2eConfigs = appArchitect['e2e'].configurations;
42+
const buildConfigs = appArchitect['build'].configurations;
4243

4344
// Make default builds prod.
4445
appArchitect['build'].options.optimization = true;
@@ -63,6 +64,8 @@ export default async function() {
6364
} else {
6465
i18n.locales[lang] = `src/locale/messages.${lang}.xlf`;
6566
}
67+
68+
buildConfigs[lang] = { localize: [lang] };
6669
serveConfigs[lang] = { browserTarget: `test-project:build:${lang}` };
6770
e2eConfigs[lang] = {
6871
specs: [`./src/app.${lang}.e2e-spec.ts`],
@@ -142,6 +145,11 @@ export default async function() {
142145
}
143146
}
144147

148+
// Verify locale data registration (currently only for single locale builds)
149+
await ng('build', '--optimization', 'false', '-c', 'fr', '--i18n-missing-translation', 'error');
150+
await expectFileToMatch(`${baseDir}/fr/main-es5.js`, 'registerLocaleData');
151+
await expectFileToMatch(`${baseDir}/fr/main-es2015.js`, 'registerLocaleData');
152+
145153
// Verify missing translation behaviour.
146154
await appendToFile('src/app/app.component.html', '<p i18n>Other content</p>');
147155
await ng('build', '--i18n-missing-translation', 'ignore');

0 commit comments

Comments
 (0)