Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Get badge locale from navigator.language
Loading branch information
Showing
1 changed file
with
21 additions
and
2 deletions .
+21
−2
proxy/init-badge.js
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -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 ( ) ;
Toggle all file notes
Toggle all file annotations