Skip to content

Commit b2d4415

Browse files
alan-agius4dgp1130
authored andcommitted
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy