Skip to content

Commit

Permalink
fix(@angular-devkit/build-angular): correct set locale when using esb…
Browse files Browse the repository at this point in the history
…uild based builders

In some cases the `$localize.locale` was being set prior to `$localize` being set through `@angular/localize`. This caused `$localize.locale` to be reset to `en-US`.

This change moves the order in which `$localize.locale` is set.

Partially addresses: #26350
  • Loading branch information
alan-agius4 committed Nov 27, 2023
1 parent 4da732d commit 876ca1e
Showing 1 changed file with 6 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -398,20 +398,6 @@ function getEsBuildCommonPolyfillsOptions(
// Locale data should go first so that project provided polyfill code can augment if needed.
let needLocaleDataPlugin = false;
if (i18nOptions.shouldInline) {
// When inlining, a placeholder is used to allow the post-processing step to inject the $localize locale identifier
polyfills.unshift('angular:locale/placeholder');
buildOptions.plugins?.push(
createVirtualModulePlugin({
namespace: 'angular:locale/placeholder',
entryPointOnly: false,
loadContent: () => ({
contents: `(globalThis.$localize ??= {}).locale = "___NG_LOCALE_INSERT___";\n`,
loader: 'js',
resolveDir: workspaceRoot,
}),
}),
);

// Add locale data for all active locales
// TODO: Inject each individually within the inlining process itself
for (const locale of i18nOptions.inlineLocales) {
Expand Down Expand Up @@ -476,8 +462,12 @@ function getEsBuildCommonPolyfillsOptions(
.map((file) => `import '${file.replace(/\\/g, '/')}';`)
.join('\n');

// If not inlining translations and source locale is defined, inject the locale specifier
if (!i18nOptions.shouldInline && i18nOptions.hasDefinedSourceLocale) {
// The below should be done after loading `$localize` as otherwise the locale will be overridden.
if (i18nOptions.shouldInline) {
// When inlining, a placeholder is used to allow the post-processing step to inject the $localize locale identifier.
contents += '(globalThis.$localize ??= {}).locale = "___NG_LOCALE_INSERT___";\n';
} else if (i18nOptions.hasDefinedSourceLocale) {
// If not inlining translations and source locale is defined, inject the locale specifier.
contents += `(globalThis.$localize ??= {}).locale = "${i18nOptions.sourceLocale}";\n`;
}

Expand Down

0 comments on commit 876ca1e

Please sign in to comment.