Simplifiing the code by turning it into a for-loop

pull/4692/head
Frank Elsinga 4 weeks ago committed by GitHub
parent 00a734e5b0
commit e3f0c60777
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -63,12 +63,22 @@ const rtlLangs = [ "fa", "ar-SY", "ur" ];
* @returns {string} the locale that should be displayed * @returns {string} the locale that should be displayed
*/ */
export function currentLocale() { export function currentLocale() {
const potentialLocales = [ localStorage.locale, navigator.language, ...navigator.languages ]; for (const locale of [ localStorage.locale, navigator.language, ...navigator.languages ]) {
const availableLocales = potentialLocales // localstorage might not have a value or there might not be a language in `navigator.language`
.filter(l => !!l) if (!locale) {
.map(l => l.split("-")[0] in messages ? l.split("-")[0] : l) continue
.filter(l => l in messages); }
return availableLocales[0] || "en"; if (locale in messages) {
return locale;
}
// some locales are further specified such as "en-US".
// If we only have a generic locale for this, we can use it too
const genericLocale = l.split("-")[0];
if (genericLocale in messages) {
return genericLocale;
}
}
return "en";
} }
export const localeDirection = () => { export const localeDirection = () => {

Loading…
Cancel
Save