-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathregion.js
More file actions
41 lines (32 loc) · 1.13 KB
/
region.js
File metadata and controls
41 lines (32 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Locale redirect functionality
function getBrowserLocales(options = {}) {
const defaultOptions = {
languageCodeOnly: false,
};
const opt = {
...defaultOptions,
...options,
};
const browserLocales =
navigator.languages === undefined? [navigator.language] : navigator.languages;
if (!browserLocales) {
return undefined;
}
return browserLocales.map(locale => {
const trimmedLocale = locale.trim();
return opt.languageCodeOnly ? trimmedLocale.split(/-|_/)[0] : trimmedLocale;
});
}
let userLanguages = [...new Set(getBrowserLocales({languageCodeOnly: true}))];
//console.log(userLanguages);
const languageRedirectNavigation = document.getElementById("locale-switcher-navigation");
userLanguages.forEach( userLanguage => {
if(userLanguage === 'pl') {
//show popup
languageRedirectNavigation.classList.remove("hidden-locale-switcher");
}
})
const closelanguageRedirectNavigation = document.getElementById("ls-close");
closelanguageRedirectNavigation.onclick = () => {
languageRedirectNavigation.classList.add("hidden-locale-switcher");
}