rn,lang: fix language detection to take region into account
If we have a regional variant, prefer that.
This commit is contained in:
parent
a45cbf41ef
commit
9be78c60eb
|
@ -2,6 +2,10 @@
|
||||||
|
|
||||||
import { NativeModules } from 'react-native';
|
import { NativeModules } from 'react-native';
|
||||||
|
|
||||||
|
import LANGUAGES_RESOURCES from '../../../../lang/languages.json';
|
||||||
|
|
||||||
|
const LANGUAGES = Object.keys(LANGUAGES_RESOURCES);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The singleton language detector for React Native which uses the system-wide
|
* The singleton language detector for React Native which uses the system-wide
|
||||||
* locale.
|
* locale.
|
||||||
|
@ -16,8 +20,14 @@ export default {
|
||||||
|
|
||||||
detect() {
|
detect() {
|
||||||
const { LocaleDetector } = NativeModules;
|
const { LocaleDetector } = NativeModules;
|
||||||
|
const [ lang, region ] = LocaleDetector.locale.replace(/_/, '-').split('-');
|
||||||
|
const locale = `${lang}${region}`;
|
||||||
|
|
||||||
return LocaleDetector.locale.replace(/[_-]/, '');
|
if (LANGUAGES.includes(locale)) {
|
||||||
|
return locale;
|
||||||
|
}
|
||||||
|
|
||||||
|
return lang;
|
||||||
},
|
},
|
||||||
|
|
||||||
init: Function.prototype,
|
init: Function.prototype,
|
||||||
|
|
Loading…
Reference in New Issue