1
0
Fork 0
mirror of https://github.com/betaflight/betaflight-configurator.git synced 2025-07-24 08:45:28 +03:00

Merge pull request #953 from McGiverGim/fix_locale_fallback

Fix locale fallback
This commit is contained in:
Michael Keller 2018-02-27 14:00:52 +13:00 committed by GitHub
commit b9ad30e49b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

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;
}