-
Notifications
You must be signed in to change notification settings - Fork 26.6k
Description
Which @angular/* package(s) are the source of the bug?
common
Is this a regression?
No
Description
When loading locales dynamically and not using registerLocaleData
which happens, if you load locales as script form a asset folder for example, there is an issue with locales that are cached in the locale_data_api
. Those are not updated:
angular/packages/core/src/i18n/locale_data_api.ts
Lines 103 to 112 in c11527f
export function getLocaleData(normalizedLocale: string): any { | |
if (!(normalizedLocale in LOCALE_DATA)) { | |
LOCALE_DATA[normalizedLocale] = | |
global.ng && | |
global.ng.common && | |
global.ng.common.locales && | |
global.ng.common.locales[normalizedLocale]; | |
} | |
return LOCALE_DATA[normalizedLocale]; | |
} |
when getLocaleData
is called with a locale that isn't loaded yet, it will set the cached LOCALE_DATA
for the specific locale, but this won't be updated the next time getLocaleData
is called, if the locale is loaded by that time. so this will always mismatch and throw an error. registerLocaleData
on the other hand overwrites the Local in LOCALE_DATA
whenever called.
I think the correct behavior would be to check not only if normalizedLocale
is in LOCALE_DATA
but if it holds valid locale data and if not, try to reload the locale from global
.
Please provide a link to a minimal reproduction of the bug
No response
Please provide the exception or error you saw
NG0701
Please provide the environment you discovered this bug in (run ng version
)
Angular CLI: 19.2.11
Node: 20.18.0
Package Manager: npm 10.8.2
OS: win32 x64
Angular: 19.2.10
... animations, common, compiler, compiler-cli, core, forms
... language-service, localize, platform-browser
... platform-browser-dynamic, router
Package Version
---------------------------------------------------------
@angular-devkit/architect 0.1902.11
@angular-devkit/build-angular 19.2.11
@angular-devkit/core 19.2.11
@angular-devkit/schematics 19.2.11
@angular/cdk 19.2.15
@angular/cli 19.2.11
@schematics/angular 19.2.11
rxjs 7.8.2
typescript 5.8.3
zone.js 0.15.0
Anything else?
I can provide a PR if needed