When the browser returns a regional language, check if the language code is available

pull/1/head
yflory 8 years ago
parent f94db93897
commit 2e418c1723

@ -1,11 +1,6 @@
(function () {
var LS_LANG = "CRYPTPAD_LANG";
var getStoredLanguage = function () { return localStorage.getItem(LS_LANG); };
var getBrowserLanguage = function () { return navigator.language || navigator.userLanguage; };
var getLanguage = function () { return getStoredLanguage() || getBrowserLanguage(); };
var language = getLanguage();
// add your module to this map so it gets used
var map = {
'fr': 'Français',
@ -15,6 +10,19 @@ var map = {
'pt-br': 'Português do Brasil'
};
var getStoredLanguage = function () { return localStorage.getItem(LS_LANG); };
var getBrowserLanguage = function () { return navigator.language || navigator.userLanguage; };
var getLanguage = function () {
if (getStoredLanguage()) { return getStoredLanguage(); }
var l = getBrowserLanguage() || '';
if (Object.keys(map).indexOf(l) !== -1) {
return l;
}
// Edge returns 'fr-FR' --> transform it to 'fr' and check again
return Object.keys(map).indexOf(l.split('-')[0]) !== -1 ? l.split('-')[0] : 'en';
};
var language = getLanguage();
var req = ['/customize/translations/messages.js'];
if (language && map[language]) { req.push('/customize/translations/messages.' + language + '.js'); }
req.push('/bower_components/jquery/dist/jquery.min.js');

Loading…
Cancel
Save