mirror of
https://github.com/digitalocean/nginxconfig.io.git
synced 2025-08-29 07:16:34 +08:00
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:
@@ -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;
|
||||
}
|
||||
};
|
||||
|
Reference in New Issue
Block a user