Skip to content
Permalink
Browse files
Get badge locale from navigator.language
  • Loading branch information
arlolra committed Aug 15, 2019
1 parent 4e5a50f commit 7bab95d1458859c94513b2e238858eb4f5e1cd69
Showing with 21 additions and 2 deletions.
  1. +21 −2 proxy/init-badge.js
@@ -82,6 +82,26 @@ function setSnowflakeCookie(val, 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;

(function() {
@@ -171,8 +191,7 @@ var debug, snowflake, config, broker, ui, log, dbg, init, update, silenceNotific
};

window.onload = function() {
const lang = 'en_US';
fetch(`./_locales/${lang}/messages.json`)
fetch(`./_locales/${getLang()}/messages.json`)
.then((res) => {
if (!res.ok) { return; }
return res.json();

0 comments on commit 7bab95d

Please sign in to comment.