Browse Source

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

If we have a regional variant, prefer that.
master
Saúl Ibarra Corretgé 5 years ago
parent
commit
9be78c60eb
1 changed files with 11 additions and 1 deletions
  1. 11
    1
      react/features/base/i18n/languageDetector.native.js

+ 11
- 1
react/features/base/i18n/languageDetector.native.js View File

@@ -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,

Loading…
Cancel
Save