Skip to content

Commit

Permalink
fix(@angular-devkit/build-angular): update locale setting snippet to …
Browse files Browse the repository at this point in the history
…use `globalThis`.

This commit changes how we set the `LOCALE_ID` when using the `localize` option

- We now include the locale setting snippet only in the main bundle.
- We use `globalThis` to set the the value globally and be accessible across module boundaries. This is important as in some causes such as when using MF `@angular/core` can be located in a bundles others than `main` and `vendor`.

(cherry picked from commit afe9fea)
  • Loading branch information
alan-agius4 authored and dgp1130 committed Dec 9, 2022
1 parent a0da91d commit b2d4415
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
Expand Up @@ -42,7 +42,7 @@ function emittedFilesToInlineOptions(
code: fs.readFileSync(originalPath, 'utf8'),
outputPath,
missingTranslation,
setLocale: emittedFile.name === 'main' || emittedFile.name === 'vendor',
setLocale: emittedFile.name === 'main',
};
originalFiles.push(originalPath);

Expand Down
Expand Up @@ -272,7 +272,7 @@ async function inlineLocalesDirect(ast: ParseResult, options: InlineOptions) {

let outputSource: import('webpack').sources.Source = content;
if (options.setLocale) {
const setLocaleText = `var $localize=Object.assign(void 0===$localize?{}:$localize,{locale:"${locale}"});\n`;
const setLocaleText = `globalThis.$localize=Object.assign(globalThis.$localize || {},{locale:"${locale}"});\n`;

// If locale data is provided, load it and prepend to file
let localeDataSource;
Expand Down

0 comments on commit b2d4415

Please sign in to comment.