MCPcopy Index your code
hub / github.com/Externalizable/bongo.cat / preferredLang

Function preferredLang

js/core.js:343–362  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

341
342var supportedLanguages = {"ca": true, "en": true};
343function preferredLang() {
344 const urlParams = new URLSearchParams(window.location.search);
345 var urlLang = urlParams.get("lang");
346 if(urlLang !== null && supportedLanguages[urlLang]) {
347 return urlLang;
348 }
349
350 var langs = window.navigator.languages;
351 for(var i=0; i<langs.length; i++) {
352 /* 2 is the length of ISO 639-1 language codes
353 * which are the start of BCP-47 codes
354 */
355 var code = langs[i].substring(0, 2);
356 var l = supportedLanguages[code];
357 if(l) {
358 return code;
359 }
360 }
361 return "en";
362};
363
364
365function internationalize() {

Callers 1

internationalizeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected