Browse Source

Normalize language format

j8
Óscar Carretero 4 years ago
parent
commit
62c06441b1
1 changed files with 21 additions and 2 deletions
  1. 21
    2
      react/features/base/i18n/customNavigatorDetector.js

+ 21
- 2
react/features/base/i18n/customNavigatorDetector.js View File

36
             }
36
             }
37
         }
37
         }
38
 
38
 
39
-        // Fix language format (en-US => enUS)
40
-        found = found.map<string>(f => f.replace(/[-_]+/g, ''));
39
+        found = found.map<string>(normalizeLanguage);
41
 
40
 
42
         return found.length > 0 ? found : undefined;
41
         return found.length > 0 ? found : undefined;
43
     },
42
     },
47
      */
46
      */
48
     name: 'customNavigatorDetector'
47
     name: 'customNavigatorDetector'
49
 };
48
 };
49
+
50
+/**
51
+ * Normalize language format.
52
+ *
53
+ * (en-US => enUS)
54
+ * (en-gb => enGB)
55
+ * (es-es => es).
56
+ *
57
+ * @param {string} language - Language.
58
+ * @returns {string} The normalized language.
59
+ */
60
+function normalizeLanguage(language) {
61
+    const [ lang, variant ] = language.replace('_', '-').split('-');
62
+
63
+    if (!variant || lang === variant) {
64
+        return lang;
65
+    }
66
+
67
+    return lang + variant.toUpperCase();
68
+}

Loading…
Cancel
Save