Skip to content

Commit 6d67da3

Browse files
authored
feat(localize): support for language codes with 3 characters (#520)
1 parent e87f9c8 commit 6d67da3

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

packages/localize/index.android.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ export function androidLaunchEventLocalizationHandler() {
4141
}
4242

4343
export function overrideLocale(locale: string): boolean {
44-
ApplicationSettings.setString('__app__language__', locale.substring(0, 2));
44+
let language_code = locale.substring(0, 2);
45+
if (locale.indexOf('-') < 0 && locale.length == 3) {
46+
language_code = locale;
47+
}
48+
ApplicationSettings.setString('__app__language__', language_code);
4549
return true;
4650
}

packages/localize/index.ios.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,12 @@ export function androidLaunchEventLocalizationHandler() {
3030
}
3131

3232
export function overrideLocale(locale: string): boolean {
33-
const path = NSBundle.mainBundle.pathForResourceOfType(locale.substring(0, 2), 'lproj');
33+
let language_code = locale.substring(0, 2);
34+
if (locale.indexOf('-') < 0 && locale.length == 3) {
35+
language_code = locale;
36+
}
37+
38+
const path = NSBundle.mainBundle.pathForResourceOfType(language_code, 'lproj');
3439

3540
if (!path) {
3641
return false;
@@ -39,7 +44,7 @@ export function overrideLocale(locale: string): boolean {
3944
bundle = NSBundle.bundleWithPath(path);
4045
NSUserDefaults.standardUserDefaults.setObjectForKey([locale], 'AppleLanguages');
4146
NSUserDefaults.standardUserDefaults.synchronize();
42-
ApplicationSettings.setString('__app__language__', locale.substring(0, 2));
47+
ApplicationSettings.setString('__app__language__', language_code);
4348

4449
return true;
4550
}

0 commit comments

Comments
 (0)