Read preferences also from browser and VC settings
This commit is contained in:
parent
84547aecfb
commit
ff22f25937
12
bilingual.js
12
bilingual.js
@ -167,12 +167,22 @@ function getClassNameForLanguage(language) {
|
||||
|
||||
/**
|
||||
* Read the user's language preference—if any—from LocalStorage and update elements accordingly.
|
||||
* In case there is no LocalStorage entry, but the user selected English as its default VC or browser
|
||||
* language, the `currentLanguage` is set to English.
|
||||
*/
|
||||
function readUserPreferences() {
|
||||
if (localStorage.getItem(STORAGE_LANGUAGE_PREFERENCE_KEY) != null) {
|
||||
const localStorageEntry = localStorage.getItem(STORAGE_LANGUAGE_PREFERENCE_KEY);
|
||||
const documentLanguage = document.querySelector('html').getAttribute('lang');
|
||||
|
||||
if (localStorageEntry != null) {
|
||||
currentLanguage = localStorage.getItem(STORAGE_LANGUAGE_PREFERENCE_KEY);
|
||||
updateMultiLanguageElements();
|
||||
document.body.classList.add(`wiai-language-${currentLanguage}`);
|
||||
} else if (documentLanguage === 'en' || documentLanguage === 'en_us'
|
||||
|| navigator.language === 'en' || navigator.language.includes('en-')) {
|
||||
currentLanguage = 'english';
|
||||
updateMultiLanguageElements();
|
||||
document.body.classList.add(`wiai-language-${currentLanguage}`);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user