Skip to content

Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.

Normalize language format

Óscar Carretero62c06441b1be
diff --git a/react/features/base/i18n/customNavigatorDetector.js b/react/features/base/i18n/customNavigatorDetector.js
index 768f2dfd00..01c4f5d8ca 100644
--- a/react/features/base/i18n/customNavigatorDetector.js
+++ b/react/features/base/i18n/customNavigatorDetector.js
@@ -36,8 +36,7 @@ export default {
}
}
- // Fix language format (en-US => enUS)
- found = found.map<string>(f => f.replace(/[-_]+/g, ''));
+ found = found.map<string>(normalizeLanguage);
return found.length > 0 ? found : undefined;
},
@@ -47,3 +46,23 @@ export default {
*/
name: 'customNavigatorDetector'
};
+
+/**
+ * Normalize language format.
+ *
+ * (en-US => enUS)
+ * (en-gb => enGB)
+ * (es-es => es).
+ *
+ * @param {string} language - Language.
+ * @returns {string} The normalized language.
+ */
+function normalizeLanguage(language) {
+ const [ lang, variant ] = language.replace('_', '-').split('-');
+
+ if (!variant || lang === variant) {
+ return lang;
+ }
+
+ return lang + variant.toUpperCase();
+}