Skip to content

Commit b9ad30e

Browse files
authored
Merge pull request #953 from McGiverGim/fix_locale_fallback
Fix locale fallback
2 parents e854411 + fbfb523 commit b9ad30e

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/js/localization.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,27 @@ function getValidLocale(userLocale) {
123123

124124
if (userLocale == 'DEFAULT') {
125125
userLocale = window.navigator.userLanguage || window.navigator.language;
126+
console.log('Detected locale ' + userLocale);
127+
128+
// The i18next can fallback automatically to the dialect, but needs to be used with hyphen and
129+
// we use underscore because the eventPage.js uses Chrome localization that needs underscore.
130+
// If at some moment we get rid of the Chrome localization we can remove all of this
131+
userLocale = userLocale.replace('-','_');
132+
// Locale not found
133+
if (languagesAvailables.indexOf(userLocale) == -1) {
134+
// Is a composite locale?
135+
var underscorePosition = userLocale.indexOf('_');
136+
if (underscorePosition != -1) {
137+
userLocale = userLocale.substring(0, underscorePosition);
138+
// Locale dialect fallback not found
139+
if (languagesAvailables.indexOf(userLocale) == -1) {
140+
userLocale = 'en'; // Fallback language
141+
}
142+
} else {
143+
userLocale = 'en';
144+
}
145+
}
126146
}
147+
127148
return userLocale;
128149
}

0 commit comments

Comments
 (0)