浏览代码

rn,lang: fix language detection to take region into account

If we have a regional variant, prefer that.
master
Saúl Ibarra Corretgé 5 年前
父节点
当前提交
9be78c60eb
共有 1 个文件被更改,包括 11 次插入1 次删除
  1. 11
    1
      react/features/base/i18n/languageDetector.native.js

+ 11
- 1
react/features/base/i18n/languageDetector.native.js 查看文件

2
 
2
 
3
 import { NativeModules } from 'react-native';
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
  * The singleton language detector for React Native which uses the system-wide
10
  * The singleton language detector for React Native which uses the system-wide
7
  * locale.
11
  * locale.
16
 
20
 
17
     detect() {
21
     detect() {
18
         const { LocaleDetector } = NativeModules;
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
     init: Function.prototype,
33
     init: Function.prototype,

正在加载...
取消
保存