Skip to content

Commit

Permalink
fix(@angular-devkit/build-angular): replace fallback locale for en-US
Browse files Browse the repository at this point in the history
Pre version 14, the locale for `en-US` was `en-US-POSIX`. now in version 14, this has changed to `en-US`.

List of all available locales https://github.com/unicode-org/cldr-json/blob/7033ea9b03aad6ef9cc64057d9cb88fec3fecc53/cldr-json/cldr-core/availableLocales.json#L64

Closes #23334

(cherry picked from commit 1f66ede)
  • Loading branch information
alan-agius4 authored and clydin committed Jun 9, 2022
1 parent bb6c200 commit 9d88c96
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
12 changes: 4 additions & 8 deletions packages/angular_devkit/build_angular/src/utils/i18n-options.ts
Expand Up @@ -200,14 +200,14 @@ export async function configureI18nBuild<T extends BrowserBuilderSchema | Server
localeDataPath = findLocaleDataPath(first.toLowerCase(), localeResolver);
if (localeDataPath) {
context.logger.warn(
`Locale data for '${locale}' cannot be found. Using locale data for '${first}'.`,
`Locale data for '${locale}' cannot be found. Using locale data for '${first}'.`,
);
}
}
}
if (!localeDataPath) {
context.logger.warn(
`Locale data for '${locale}' cannot be found. No locale data will be included for this locale.`,
`Locale data for '${locale}' cannot be found. No locale data will be included for this locale.`,
);
} else {
desc.dataPath = localeDataPath;
Expand Down Expand Up @@ -268,12 +268,8 @@ function findLocaleDataPath(locale: string, resolver: (locale: string) => string
try {
return resolver(scrubbedLocale);
} catch {
if (scrubbedLocale === 'en-US') {
// fallback to known existing en-US locale data as of 9.0
return findLocaleDataPath('en-US-POSIX', resolver);
}

return null;
// fallback to known existing en-US locale data as of 14.0
return scrubbedLocale === 'en-US' ? findLocaleDataPath('en', resolver) : null;
}
}

Expand Down
10 changes: 7 additions & 3 deletions tests/legacy-cli/e2e/tests/i18n/ivy-localize-es2015.ts
@@ -1,4 +1,4 @@
import { expectFileNotToExist, expectFileToMatch, readFile, writeFile } from '../../utils/fs';
import { expectFileNotToExist, expectFileToMatch, readFile } from '../../utils/fs';
import { ng } from '../../utils/process';
import { expectToFail } from '../../utils/utils';
import { externalServer, langTranslations, setupI18nConfig } from './setup';
Expand All @@ -7,9 +7,13 @@ export default async function () {
// Setup i18n tests and config.
await setupI18nConfig();

await writeFile('.browserslistrc', 'Chrome 65');
const { stderr } = await ng('build', '--source-map');
if (/Locale data for .+ cannot be found/.test(stderr)) {
throw new Error(
`A warning for a locale not found was shown. This should not happen.\n\nSTDERR:\n${stderr}\n`,
);
}

await ng('build', '--source-map');
for (const { lang, outputPath, translation } of langTranslations) {
await expectFileToMatch(`${outputPath}/main.js`, translation.helloPartial);
await expectToFail(() => expectFileToMatch(`${outputPath}/main.js`, '$localize`'));
Expand Down
Expand Up @@ -25,7 +25,7 @@ export default async function () {
});

const { stderr: err1 } = await ng('build');
if (!err1.includes(`Locale data for 'fr-Abcd' cannot be found. Using locale data for 'fr'.`)) {
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');
}

Expand Down

0 comments on commit 9d88c96

Please sign in to comment.