Fix locale fallback

10.3.x-maintenance
Miguel Angel Mulero Martinez 2018-02-26 20:30:53 +01:00
parent e8544110f8
commit fbfb523b4d
1 changed files with 21 additions and 0 deletions

View File

@ -123,6 +123,27 @@ function getValidLocale(userLocale) {
if (userLocale == 'DEFAULT') {
userLocale = window.navigator.userLanguage || window.navigator.language;
console.log('Detected locale ' + userLocale);
// The i18next can fallback automatically to the dialect, but needs to be used with hyphen and
// we use underscore because the eventPage.js uses Chrome localization that needs underscore.
// If at some moment we get rid of the Chrome localization we can remove all of this
userLocale = userLocale.replace('-','_');
// Locale not found
if (languagesAvailables.indexOf(userLocale) == -1) {
// Is a composite locale?
var underscorePosition = userLocale.indexOf('_');
if (underscorePosition != -1) {
userLocale = userLocale.substring(0, underscorePosition);
// Locale dialect fallback not found
if (languagesAvailables.indexOf(userLocale) == -1) {
userLocale = 'en'; // Fallback language
}
} else {
userLocale = 'en';
}
}
}
return userLocale;
}