@@ -44,15 +44,13 @@ function igxRegisterI18n(resourceStrings: IResourceStrings, locale: string) {
4444
4545/** Get current resource strings based on default. Result is truncated result, containing only relevant locale strings. */
4646export function getCurrentResourceStrings < T > ( defaultEN : T , init = true , locale ?: string ) {
47- const igxResourceStringKeys = Object . keys ( defaultEN ) ;
48- if ( init ) {
49- igxRegisterI18n ( defaultEN , getI18nManager ( ) . defaultLocale ) ;
50- }
51-
52- // Append back `igx_` prefix for compatibility with older versions.
5347 const resourceStrings = getI18nManager ( ) . getCurrentResourceStrings ( locale ) ;
54- const normalizedResourceStrings : T = { } as T ;
5548 const resourceStringsKeys = Object . keys ( resourceStrings ) ;
49+ const normalizedResourceStrings : T = { } as T ;
50+ const newResourceStrings : T = { } as T ;
51+
52+ // Append back `igx_` prefix for compatibility with older versions.
53+ const igxResourceStringKeys = Object . keys ( defaultEN ) ;
5654 for ( const igxKey of igxResourceStringKeys ) {
5755 let coreKey = igxKey ;
5856 if ( coreKey . startsWith ( "igx_" ) ) {
@@ -62,9 +60,15 @@ export function getCurrentResourceStrings<T>(defaultEN: T, init = true, locale?:
6260 normalizedResourceStrings [ igxKey ] = resourceStrings [ coreKey ] ;
6361 } else {
6462 normalizedResourceStrings [ igxKey ] = defaultEN [ igxKey ] ;
63+ newResourceStrings [ coreKey ] = defaultEN [ igxKey ] ;
6564 }
6665 }
6766
67+ if ( init ) {
68+ // Register only new resources. We don't want to accidentally override any default set by user.
69+ getI18nManager ( ) . registerI18n ( newResourceStrings , getI18nManager ( ) . defaultLocale ) ;
70+ }
71+
6872 return normalizedResourceStrings ;
6973}
7074
@@ -96,7 +100,8 @@ export function onResourceChangeHandle(destroyObj: Subject<any> | DestroyRef, ca
96100 * Note: Legacy method. We suggest using the new `registerI18n` and `setCurrentI18n` methods exposed.
97101 */
98102export function changei18n ( resourceStrings : IResourceStrings ) {
99- igxRegisterI18n ( resourceStrings , getI18nManager ( ) . defaultLocale ) ;
103+ // Register to current locale, since the user might have already set `lang` tag on root html.
104+ igxRegisterI18n ( resourceStrings , getI18nManager ( ) . currentLocale ) ;
100105}
101106
102107/**
0 commit comments