Something similar to [NSLocale currentLocale] in Objective-C.
You can install react-native-i18n and use this function:
import React, { NativeModules } from 'react-native'
...
function getLocale () {
if (React.Platform.OS === 'android') {
return NativeModules.RNI18n.getCurrentLocale(locale => locale.replace(/_/, '-'))
} else {
return NativeModules.RNI18n.locale.replace(/_/, '-')
}
}
Works both under Android and iOS.
iOS 13 workaround here:
locale = NativeModules.SettingsManager.settings.AppleLocale // "fr_FR"
console.log(" ==> Current settings: ", NativeModules.SettingsManager.settings)
if (locale === undefined) {
// iOS 13 workaround, take first of AppleLanguages array
locale = NativeModules.SettingsManager.settings.AppleLanguages[0]
if (locale == undefined) {
return "en" // default language
}
}