Add unit testing for browser language (#197)

* Add unit testing

* Update unit testing

* Update unit testing

* fix a big heap of formatting typo
This commit is contained in:
墨娘
2020-12-23 01:06:52 +08:00
committed by GitHub
parent 0d920fa9bc
commit d1bf984d0b
6 changed files with 3561 additions and 86 deletions

View File

@@ -38,7 +38,8 @@ export default () => {
if (typeof window.navigator.language === 'string')
userLocales.add(window.navigator.language);
if (Intl && 'DateTimeFormat' in Intl)
userLocales.add(Intl.DateTimeFormat().resolvedOptions().locale);
if (Intl.DateTimeFormat().resolvedOptions().locale !== 'und')
userLocales.add(Intl.DateTimeFormat().resolvedOptions().locale);
// Try to find an exact region/language match
const i18nPackLocales = Object.keys(i18nPacks);
@@ -53,7 +54,9 @@ export default () => {
}, {});
// Try to match a user language to a pack language
const langMatch = [...userLocales.values()].find(x => i18nPackLanguages.includes(x.split('-')[0].toLowerCase()));
const langMatch = [...userLocales.values()].find(x => Object.keys(i18nPackLanguages).includes(x.split('-')[0].toLowerCase()));
if (langMatch) return i18nPackLanguages[langMatch.split('-')[0].toLowerCase()];
return false;
}
};