get current device locale & enable fallback

This commit is contained in:
KraXen72
2024-06-05 13:23:18 +02:00
parent 55366eb043
commit afbd57773f
2 changed files with 17 additions and 3 deletions
+14 -3
View File
@@ -16,18 +16,29 @@ export const i18n = new I18n({ 'en-US': en })
*/
i18n.translations = {
en, "en-US": en,
sk, 'sk_SK': sk
sk
}
// important!
i18n.defaultLocale = 'en'
i18n.enableFallback = true;
i18n.locale = Platform.OS === 'ios'
// i wanted to use Intl.Locale to parse this and get the base language
// however, seems like Intl.Locale is either not implemented in hermes or not workiking for this version
// also, react native provides locales in the en_US format, whereas js expect them in en-US format
// this is smaller than a full intl polyfill and does what we need
const fullLocaleRN: string = (Platform.OS === 'ios'
? NativeModules.SettingsManager.settings.AppleLocale
: NativeModules.I18nManager.localeIdentifier
).toString().replaceAll('_', '-')
const localeJSFormat = fullLocaleRN.includes("-")
? fullLocaleRN.split("-")[0]
: fullLocaleRN.slice(0, 2)
i18n.locale = localeJSFormat
console.log(i18n.locale)
/**
* Builds up valid keypaths for translations.
+3
View File
@@ -16,6 +16,9 @@
},
"payCommon": {
"amountToPayLabel": "Suma na zaplatenie",
"receive": "Prijať",
"receiveEcash": "Prijať ecash",
"receiveOffline": "Prijať offline",
"send": "Poslať"
},
"sendScreen": {