Skip to content

Commit e511a12

Browse files
committed
fix(android): fix errors after changing language
1 parent 7c45fae commit e511a12

3 files changed

Lines changed: 650 additions & 586 deletions

File tree

app/helpers/locale.ts

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { ALERT_OPTION_MAX_HEIGHT, DEFAULT_LOCALE, SETTINGS_LANGUAGE } from '~/ut
99
import { showError } from '@shared/utils/showError';
1010
import { createGlobalEventListener, globalObservable } from '@shared/utils/svelte/ui';
1111
import { showAlertOptionSelect } from '~/utils/ui';
12+
import { clearCurrentLocale, getCurrentLocale } from '@shared/helpers/lang';
1213
const supportedLanguages = SUPPORTED_LOCALES;
1314
dayjs.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;
180181
export 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
}
194189
export function getCurrentISO3Language() {

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@
3838
},
3939
"dependencies": {
4040
"@akylas/kiss-orm": "2.1.14",
41-
"@akylas/nativescript": "8.9.13",
41+
"@akylas/nativescript": "8.9.14",
4242
"@akylas/nativescript-app-tools": "file:tools",
43-
"@akylas/nativescript-app-utils": "2.2.10",
43+
"@akylas/nativescript-app-utils": "2.2.11",
4444
"@akylas/nativescript-inapp-purchase": "0.0.4",
4545
"@akylas/nativescript-inappbrowser": "3.1.8",
4646
"@akylas/non-playstore": "portal:plugin_non_playstore",

0 commit comments

Comments
 (0)