diff --git a/lib/core/services/user-preferences.service.spec.ts b/lib/core/services/user-preferences.service.spec.ts index e675192f44..e95b9dc999 100644 --- a/lib/core/services/user-preferences.service.spec.ts +++ b/lib/core/services/user-preferences.service.spec.ts @@ -194,6 +194,24 @@ describe('UserPreferencesService', () => { expect(storage.getItem(textOrientation)).toBe(null); })); + it('should default to browser locale for textOrientation when locale is not defined in configuration', (done) => { + appConfig.config.languages = [ + { + key: 'fake-locale-browser', + direction: 'rtl' + } + ]; + spyOn(translate, 'getBrowserCultureLang').and.returnValue('fake-locale-browser'); + preferences = new UserPreferencesService(translate, appConfig, storage); + appConfig.load(); + + changeDisposable = preferences.onChange + .subscribe((userPreferenceStatus) => { + expect(userPreferenceStatus['textOrientation']).toBe('rtl'); + done(); + }); + }); + it('should not store in the storage the locale if the app.config.json does not have a value', () => { preferences = new UserPreferencesService(translate, appConfig, storage); preferences.locale = 'fake-store-locate'; diff --git a/lib/core/services/user-preferences.service.ts b/lib/core/services/user-preferences.service.ts index 0d93388ed8..0c4be0fb21 100644 --- a/lib/core/services/user-preferences.service.ts +++ b/lib/core/services/user-preferences.service.ts @@ -70,7 +70,7 @@ export class UserPreferencesService { const locale = this.locale || this.getDefaultLocale(); this.setWithoutStore(UserPreferenceValues.Locale, locale); - this.setWithoutStore('textOrientation', (this.locale || this.getDefaultLocale())); + this.setWithoutStore('textOrientation', this.getLanguageByKey(locale).direction || 'ltr'); } } @@ -225,7 +225,7 @@ export class UserPreferencesService { private getLanguageByKey(key: string): LanguageItem { return ( this.appConfig - .get>(AppConfigValues.APP_CONFIG_LANGUAGES_KEY) + .get>(AppConfigValues.APP_CONFIG_LANGUAGES_KEY, [ { key: 'en' }]) .find((language) => key.includes(language.key)) || { key: 'en' } ); }