refactor(core): replace references to goog.LOCALE with goog.getLocale() (#43089)

It is necessary in order to distinguish 2 different reasons for referencing the compiled-in locale.

1. Some code just needs to pass the locale value on to logic that actually uses it.
2. Other code uses the locale value to select locale-specific user-visible data and behavior.

Code modified by this change is of the first kind and should use `goog.getLocale()` in the future.

Note: there are still references to the `goog.LOCALE` in Angular codebase, but they are of second type.

PR Close #43089
This commit is contained in:
Andrew Kushnir 2021-08-09 10:46:51 -07:00
parent 892bd929f2
commit cb988aebb0
2 changed files with 5 additions and 4 deletions

View File

@ -44,16 +44,16 @@ export function _localeFactory(locale?: string): string {
/**
* Work out the locale from the potential global properties.
*
* * Closure Compiler: use `goog.LOCALE`.
* * Closure Compiler: use `goog.getLocale()`.
* * Ivy enabled: use `$localize.locale`
*/
export function getGlobalLocale(): string {
if (typeof ngI18nClosureMode !== 'undefined' && ngI18nClosureMode &&
typeof goog !== 'undefined' && goog.LOCALE !== 'en') {
// * The default `goog.LOCALE` value is `en`, while Angular used `en-US`.
typeof goog !== 'undefined' && goog.getLocale() !== 'en') {
// * The default `goog.getLocale()` value is `en`, while Angular used `en-US`.
// * In order to preserve backwards compatibility, we use Angular default value over
// Closure Compiler's one.
return goog.LOCALE;
return goog.getLocale();
} else {
// KEEP `typeof $localize !== 'undefined' && $localize.locale` IN SYNC WITH THE LOCALIZE
// COMPILE-TIME INLINER.

1
packages/goog.d.ts vendored
View File

@ -18,6 +18,7 @@ declare namespace goog {
export const DEBUG: boolean;
export const LOCALE: string;
export const getMsg: (input: string, placeholders?: {[key: string]: string}) => string;
export const getLocale: () => string;
}
/**