Skip to content

Commit

Permalink
fix: js error
Browse files Browse the repository at this point in the history
  • Loading branch information
igobranco committed Dec 16, 2024
1 parent 3bd2b55 commit 8261626
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions maintenance-site/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,25 +41,28 @@

const intlElements = ['maintenance-title', 'maintenance-shortmessage', 'maintenance-esttime', 'maintenance-message', 'maintenance-technicalinfo'];

function getNavigatorLanguage() {
return navigator.language.split('-')[0] == 'pt' ? 'pt' : 'en';
function transformToSupportedLanguage(lang) {
const primaryLang = lang.split('-')[0];
const supportedLangs = Object.keys(intlTranslations);
return supportedLangs.includes(primaryLang) ? primaryLang : supportedLangs[0];
}

function getCookieValue() {
let cookieLang = decodeURIComponent(document.cookie).split(';').find(cookie => cookie.includes('nau-language-preference'));
const cookieLang = decodeURIComponent(document.cookie).split(';').find(cookie => cookie.includes('nau-language-preference'));
return cookieLang ? cookieLang.split('=')[1] : null;
}

function setLanguage(lang) {
currentLanguage = lang;
const newLang = transformToSupportedLanguage(lang);
currentLanguage = newLang;

document.documentElement.setAttribute('lang', lang);
document.title = `NAU: ${intlTranslations[lang]['title']}`;
document.getElementById('changeLang').ariaLabel = intlTranslations[lang]['langchangemessage'];
document.documentElement.setAttribute('lang', newLang);
document.title = `NAU: ${intlTranslations[newLang]['title']}`;
document.getElementById('changeLang').ariaLabel = intlTranslations[newLang]['langchangemessage'];

intlElements.forEach(function (element) {
let el = document.getElementById(element);
el.innerHTML = intlTranslations[lang][element.split('-')[1]];
el.innerHTML = intlTranslations[newLang][element.split('-')[1]];
});

}
Expand All @@ -74,7 +77,7 @@
}

document.addEventListener("DOMContentLoaded", function () {
setLanguage(getCookieValue() || getNavigatorLanguage());
setLanguage(getCookieValue() || navigator.language);

displayOpDetails();

Expand Down

0 comments on commit 8261626

Please sign in to comment.