[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [snowflake/master] Get badge locale from navigator.language
commit 1e33ae830f739a7d61e03ea1626f5e71ba175cbc
Author: Arlo Breault <arlolra@xxxxxxxxx>
Date: Thu Aug 15 17:32:21 2019 -0400
Get badge locale from navigator.language
---
proxy/init-badge.js | 23 +++++++++++++++++++++--
1 file changed, 21 insertions(+), 2 deletions(-)
diff --git a/proxy/init-badge.js b/proxy/init-badge.js
index b906f62..1acc923 100644
--- a/proxy/init-badge.js
+++ b/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();
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits