Skip to content

Commit

Permalink
fix(@angular-devkit/build-angular): enable locale data transform for …
Browse files Browse the repository at this point in the history
…single localization
  • Loading branch information
clydin authored and vikerman committed Oct 30, 2019
1 parent 7148a16 commit 8fa93e1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export function createI18nOptions(
Object.keys(i18n.locales).forEach(locale => i18n.inlineLocales.add(locale));
} else if (inline) {
for (const locale of inline) {
if (!i18n.locales[locale]) {
if (!i18n.locales[locale] && i18n.sourceLocale !== locale) {
throw new Error(`Requested inline locale '${locale}' is not defined for the project.`);
}

Expand Down Expand Up @@ -146,6 +146,12 @@ export async function configureI18nBuild<T extends BrowserBuilderSchema | Server
if (usedFormats.size > 0) {
buildOptions.i18nFormat = [...usedFormats][0];
}

// If only one locale is specified set the deprecated option to enable the webpack plugin
// transform to register the locale directly in the output bundle.
if (i18n.inlineLocales.size === 1) {
buildOptions.i18nLocale = [...i18n.inlineLocales][0];
}
}

// If inlining store the output in a temporary location to facilitate post-processing
Expand Down
8 changes: 8 additions & 0 deletions tests/legacy-cli/e2e/tests/i18n/ivy-localize-dl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export default async function() {
const appArchitect = appProject.architect || appProject.targets;
const serveConfigs = appArchitect['serve'].configurations;
const e2eConfigs = appArchitect['e2e'].configurations;
const buildConfigs = appArchitect['build'].configurations;

// Make default builds prod.
appArchitect['build'].options.optimization = true;
Expand All @@ -63,6 +64,8 @@ export default async function() {
} else {
i18n.locales[lang] = `src/locale/messages.${lang}.xlf`;
}

buildConfigs[lang] = { localize: [lang] };
serveConfigs[lang] = { browserTarget: `test-project:build:${lang}` };
e2eConfigs[lang] = {
specs: [`./src/app.${lang}.e2e-spec.ts`],
Expand Down Expand Up @@ -142,6 +145,11 @@ export default async function() {
}
}

// Verify locale data registration (currently only for single locale builds)
await ng('build', '--optimization', 'false', '-c', 'fr', '--i18n-missing-translation', 'error');
await expectFileToMatch(`${baseDir}/fr/main-es5.js`, 'registerLocaleData');
await expectFileToMatch(`${baseDir}/fr/main-es2015.js`, 'registerLocaleData');

// Verify missing translation behaviour.
await appendToFile('src/app/app.component.html', '<p i18n>Other content</p>');
await ng('build', '--i18n-missing-translation', 'ignore');
Expand Down

0 comments on commit 8fa93e1

Please sign in to comment.