mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-13 20:11:19 -04:00
Get badge locale from navigator.language
This commit is contained in:
parent
9c20ab3984
commit
1e33ae830f
1 changed files with 21 additions and 2 deletions
|
@ -82,6 +82,26 @@ function setSnowflakeCookie(val, expires) {
|
||||||
document.cookie = `${COOKIE_NAME}=${val}; path=/; expires=${expires};`;
|
document.cookie = `${COOKIE_NAME}=${val}; path=/; expires=${expires};`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const defaultLang = 'en_US';
|
||||||
|
const availableLangs = new Set([
|
||||||
|
'en_US',
|
||||||
|
]);
|
||||||
|
|
||||||
|
// Resolve as in,
|
||||||
|
// https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Internationalization#Localized_string_selection
|
||||||
|
function getLang() {
|
||||||
|
let lang = navigator.language || defaultLang;
|
||||||
|
lang = lang.replace(/-/g, '_');
|
||||||
|
if (availableLangs.has(lang)) {
|
||||||
|
return lang;
|
||||||
|
}
|
||||||
|
lang = lang.split('_')[0];
|
||||||
|
if (availableLangs.has(lang)) {
|
||||||
|
return lang;
|
||||||
|
}
|
||||||
|
return defaultLang;
|
||||||
|
}
|
||||||
|
|
||||||
var debug, snowflake, config, broker, ui, log, dbg, init, update, silenceNotifications, query;
|
var debug, snowflake, config, broker, ui, log, dbg, init, update, silenceNotifications, query;
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
|
@ -171,8 +191,7 @@ var debug, snowflake, config, broker, ui, log, dbg, init, update, silenceNotific
|
||||||
};
|
};
|
||||||
|
|
||||||
window.onload = function() {
|
window.onload = function() {
|
||||||
const lang = 'en_US';
|
fetch(`./_locales/${getLang()}/messages.json`)
|
||||||
fetch(`./_locales/${lang}/messages.json`)
|
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
if (!res.ok) { return; }
|
if (!res.ok) { return; }
|
||||||
return res.json();
|
return res.json();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue