From 831ca00af6979a75091bc4b13e2911bc7b60fef7 Mon Sep 17 00:00:00 2001 From: Charles Lyding <19598772+clydin@users.noreply.github.com> Date: Tue, 3 Mar 2020 11:58:35 -0500 Subject: [PATCH] fix(@angular-devkit/build-angular): provide locale data discovery fallbacks This synchronizes the behavior with the FW's wherein the language code will be used if the data for the full locale is not found. The user will still be notified in the event this occurs. --- .../build_angular/src/utils/i18n-options.ts | 18 +++++++- .../tests/i18n/ivy-localize-locale-data.ts | 46 +++++++++++++++++++ 2 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 tests/legacy-cli/e2e/tests/i18n/ivy-localize-locale-data.ts diff --git a/packages/angular_devkit/build_angular/src/utils/i18n-options.ts b/packages/angular_devkit/build_angular/src/utils/i18n-options.ts index d2eade0b36aa..e00faf950ed0 100644 --- a/packages/angular_devkit/build_angular/src/utils/i18n-options.ts +++ b/packages/angular_devkit/build_angular/src/utils/i18n-options.ts @@ -206,7 +206,18 @@ export async function configureI18nBuild { + const appProject = workspaceJson.projects['test-project']; + // tslint:disable-next-line: no-any + const i18n: Record = appProject.i18n; + + i18n.sourceLocale = 'fr-Abcd'; + appProject.architect['build'].options.localize = ['fr-Abcd']; + }); + + const { stderr: err1 } = await ng('build'); + if (!err1.includes(`Locale data for 'fr-Abcd' cannot be found. Using locale data for 'fr'.`)) { + throw new Error('locale data fallback warning not shown'); + } + + // Update angular.json + await updateJsonFile('angular.json', workspaceJson => { + const appProject = workspaceJson.projects['test-project']; + // tslint:disable-next-line: no-any + const i18n: Record = appProject.i18n; + + i18n.sourceLocale = 'en-US'; + appProject.architect['build'].options.localize = ['en-US']; + }); + + const { stderr: err2 } = await ng('build'); + if (err2.includes(`Locale data for 'en-US' cannot be found. No locale data will be included for this locale.`)) { + throw new Error('locale data not found warning shown'); + } + +}