|
@@ -2,6 +2,10 @@
|
2
|
2
|
|
3
|
3
|
import { NativeModules } from 'react-native';
|
4
|
4
|
|
|
5
|
+import LANGUAGES_RESOURCES from '../../../../lang/languages.json';
|
|
6
|
+
|
|
7
|
+const LANGUAGES = Object.keys(LANGUAGES_RESOURCES);
|
|
8
|
+
|
5
|
9
|
/**
|
6
|
10
|
* The singleton language detector for React Native which uses the system-wide
|
7
|
11
|
* locale.
|
|
@@ -16,8 +20,14 @@ export default {
|
16
|
20
|
|
17
|
21
|
detect() {
|
18
|
22
|
const { LocaleDetector } = NativeModules;
|
|
23
|
+ const [ lang, region ] = LocaleDetector.locale.replace(/_/, '-').split('-');
|
|
24
|
+ const locale = `${lang}${region}`;
|
|
25
|
+
|
|
26
|
+ if (LANGUAGES.includes(locale)) {
|
|
27
|
+ return locale;
|
|
28
|
+ }
|
19
|
29
|
|
20
|
|
- return LocaleDetector.locale.replace(/[_-]/, '');
|
|
30
|
+ return lang;
|
21
|
31
|
},
|
22
|
32
|
|
23
|
33
|
init: Function.prototype,
|