diff --git a/lib/core/services/user-preferences.service.spec.ts b/lib/core/services/user-preferences.service.spec.ts index ffa5cbf95d..e2ce0eb1cb 100644 --- a/lib/core/services/user-preferences.service.spec.ts +++ b/lib/core/services/user-preferences.service.spec.ts @@ -135,6 +135,14 @@ describe('UserPreferencesService', () => { expect(preferences.locale).toBe('fake-store-locate'); }); + it('should not store in the storage the locale if the app.config.json does not have a value', () => { + preferences.locale = 'fake-store-locate'; + spyOn(translate, 'getBrowserCultureLang').and.returnValue('fake-locate-browser'); + expect(preferences.locale).toBe('fake-store-locate'); + + expect(storage.getItem(UserPreferenceValues.Locale)).toBe(null); + }); + it('should stream the page size value when is set', (done) => { preferences.paginationSize = 5; changeDisposable = preferences.onChange.subscribe((userPreferenceStatus) => { diff --git a/lib/core/services/user-preferences.service.ts b/lib/core/services/user-preferences.service.ts index b4c39410f3..3602e8ae43 100644 --- a/lib/core/services/user-preferences.service.ts +++ b/lib/core/services/user-preferences.service.ts @@ -52,11 +52,19 @@ export class UserPreferencesService { } private initUserPreferenceStatus() { - this.set(UserPreferenceValues.Locale, (this.locale || this.getDefaultLocale())); + this.initUserLanguage(); this.set(UserPreferenceValues.PaginationSize, this.paginationSize); this.set(UserPreferenceValues.SupportedPageSizes, JSON.stringify(this.supportedPageSizes)); } + private initUserLanguage() { + if (this.locale || this.appConfig.get(UserPreferenceValues.Locale)) { + this.set(UserPreferenceValues.Locale, (this.locale || this.getDefaultLocale())); + } else { + this.setWithoutStore(UserPreferenceValues.Locale, (this.locale || this.getDefaultLocale())); + } + } + /** * Sets up a callback to notify when a property has changed. * @param property The property to watch @@ -102,6 +110,19 @@ export class UserPreferencesService { this.onChangeSubject.next(this.userPreferenceStatus); } + /** + * Sets a preference property. + * @param property Name of the property + * @param value New value for the property + */ + setWithoutStore(property: string, value: any) { + if (!property) { + return; + } + this.userPreferenceStatus[property] = value; + this.onChangeSubject.next(this.userPreferenceStatus); + } + /** * Check if an item is present in the storage * @param property Name of the property