@@ -9,6 +9,7 @@ import { ALERT_OPTION_MAX_HEIGHT, DEFAULT_LOCALE, SETTINGS_LANGUAGE } from '~/ut
99import { showError } from '@shared/utils/showError' ;
1010import { createGlobalEventListener , globalObservable } from '@shared/utils/svelte/ui' ;
1111import { showAlertOptionSelect } from '~/utils/ui' ;
12+ import { clearCurrentLocale , getCurrentLocale } from '@shared/helpers/lang' ;
1213const supportedLanguages = SUPPORTED_LOCALES ;
1314dayjs . extend ( LocalizedFormat ) ;
1415
@@ -61,7 +62,7 @@ function setLang(newLang) {
6162 DEV_LOG && console . log ( 'setLang' , newLang , actualNewLang ) ;
6263 if ( __IOS__ ) {
6364 overrideNativeLocale ( actualNewLang ) ;
64- currentLocale = null ;
65+ clearCurrentLocale ( ) ;
6566 } else {
6667 // Application.android.foregroundActivity?.recreate();
6768 try {
@@ -83,7 +84,7 @@ function setLang(newLang) {
8384 DEV_LOG && console . log ( 'appLocale' , appLocale . toLanguageTags ( ) , actualNewLang ) ;
8485 // Call this on the main thread as it may require Activity.restart()
8586 androidx . appcompat . app . AppCompatDelegate [ 'setApplicationLocales' ] ( appLocale ) ;
86- currentLocale = null ;
87+ clearCurrentLocale ( ) ;
8788 // TODO: check why getEmptyLocaleList does not reset the locale to system
8889 actualNewLang = getActualLanguage ( newLang ) ;
8990 } catch ( error ) {
@@ -161,7 +162,8 @@ prefs.on(`key:${SETTINGS_LANGUAGE}`, () => {
161162 const newLanguage = ApplicationSettings . getString ( SETTINGS_LANGUAGE , DEFAULT_LOCALE ) ;
162163 DEV_LOG && console . log ( 'language changed' , newLanguage ) ;
163164 // on pref change we are updating
164- if ( newLanguage === lang ) {
165+ // if "auto" then getActualLanguage will return lang value and we still need to update
166+ if ( newLanguage !== 'auto' && getActualLanguage ( newLanguage ) === lang ) {
165167 return ;
166168 }
167169 setLang ( newLanguage ) ;
@@ -176,19 +178,12 @@ prefs.on('key:clock_24', () => {
176178 globalObservable . notify ( { eventName : SETTINGS_LANGUAGE , data : lang , clock_24 : true } ) ;
177179} ) ;
178180
179- let currentLocale : any = null ;
180181export function getLocaleDisplayName ( locale ?, canReturnEmpty = false ) {
181182 if ( __IOS__ ) {
182- if ( ! currentLocale ) {
183- currentLocale = NSLocale . alloc ( ) . initWithLocaleIdentifier ( lang ) ;
184- }
185- const localeStr = ( currentLocale as NSLocale ) . displayNameForKeyValue ( NSLocaleIdentifier , locale || lang ) ;
183+ const localeStr = ( getCurrentLocale ( lang ) as NSLocale ) . displayNameForKeyValue ( NSLocaleIdentifier , locale || lang ) ;
186184 return localeStr ? capitalize ( localeStr ) : canReturnEmpty ? undefined : locale || lang ;
187185 } else {
188- if ( ! currentLocale ) {
189- currentLocale = java . util . Locale . forLanguageTag ( lang ) ;
190- }
191- return capitalize ( java . util . Locale . forLanguageTag ( locale || lang ) . getDisplayName ( currentLocale as java . util . Locale ) ) ;
186+ return capitalize ( java . util . Locale . forLanguageTag ( locale || lang ) . getDisplayName ( getCurrentLocale ( lang ) as java . util . Locale ) ) ;
192187 }
193188}
194189export function getCurrentISO3Language ( ) {
0 commit comments