From 09576e9683d83a81032aadea5669f53f5f23f823 Mon Sep 17 00:00:00 2001 From: Andrew Kushnir Date: Thu, 11 Jul 2019 14:54:49 -0700 Subject: [PATCH] fix(ivy): use goog.LOCALE for Closure Compiler to define default LOCALE_ID (#31519) Prior to this commit, default value for LOCALE_ID was not setup for Closure Compiler. In Closure Compiler, we can use `goog.LOCALE` as a default value, which will be replaced at build time with current locale. PR Close #31519 --- packages/core/src/application_module.ts | 11 ++++++++++- packages/goog.d.ts | 1 + 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/core/src/application_module.ts b/packages/core/src/application_module.ts index a28a3905a6..aee1f02a3e 100644 --- a/packages/core/src/application_module.ts +++ b/packages/core/src/application_module.ts @@ -30,7 +30,16 @@ export function _keyValueDiffersFactory() { } export function _localeFactory(locale?: string): string { - return locale || 'en-US'; + if (locale) { + return locale; + } + // Use `goog.LOCALE` as default value for `LOCALE_ID` token for Closure Compiler. + // Note: default `goog.LOCALE` value is `en`, when Angular used `en-US`. In order to preserve + // backwards compatibility, we use Angular default value over Closure Compiler's one. + if (ngI18nClosureMode && typeof goog !== 'undefined' && goog.LOCALE !== 'en') { + return goog.LOCALE; + } + return 'en-US'; } /** diff --git a/packages/goog.d.ts b/packages/goog.d.ts index f347fc0f85..25c828eb15 100644 --- a/packages/goog.d.ts +++ b/packages/goog.d.ts @@ -16,6 +16,7 @@ declare namespace goog { * as it is sometimes true. */ export const DEBUG: boolean; + export const LOCALE: string; export const getMsg: (input: string, placeholders?: {[key: string]: string}) => string; }