Skip to content

Commit b2d4415

Browse files
alan-agius4dgp1130
authored andcommittedDec 9, 2022
fix(@angular-devkit/build-angular): update locale setting snippet to 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)
1 parent a0da91d commit b2d4415

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed
 

‎packages/angular_devkit/build_angular/src/utils/i18n-inlining.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ function emittedFilesToInlineOptions(
4242
code: fs.readFileSync(originalPath, 'utf8'),
4343
outputPath,
4444
missingTranslation,
45-
setLocale: emittedFile.name === 'main' || emittedFile.name === 'vendor',
45+
setLocale: emittedFile.name === 'main',
4646
};
4747
originalFiles.push(originalPath);
4848

‎packages/angular_devkit/build_angular/src/utils/process-bundle.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ async function inlineLocalesDirect(ast: ParseResult, options: InlineOptions) {
272272

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

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

0 commit comments

Comments
 (0)
Please sign in to comment.