Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat(localize): support for language codes with 3 characters (#520)
  • Loading branch information
kmahelona authored Jul 12, 2023
commit 6d67da3ac10cfa81f0962d97ec3a7d86ba3c8509
6 changes: 5 additions & 1 deletion packages/localize/index.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ export function androidLaunchEventLocalizationHandler() {
}

export function overrideLocale(locale: string): boolean {
ApplicationSettings.setString('__app__language__', locale.substring(0, 2));
let language_code = locale.substring(0, 2);
if (locale.indexOf('-') < 0 && locale.length == 3) {
language_code = locale;
}
ApplicationSettings.setString('__app__language__', language_code);
return true;
}
9 changes: 7 additions & 2 deletions packages/localize/index.ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ export function androidLaunchEventLocalizationHandler() {
}

export function overrideLocale(locale: string): boolean {
const path = NSBundle.mainBundle.pathForResourceOfType(locale.substring(0, 2), 'lproj');
let language_code = locale.substring(0, 2);
if (locale.indexOf('-') < 0 && locale.length == 3) {
language_code = locale;
}

const path = NSBundle.mainBundle.pathForResourceOfType(language_code, 'lproj');

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

return true;
}