Skip to content

Commit

Permalink
a
Browse files Browse the repository at this point in the history
  • Loading branch information
hu8813 committed Apr 22, 2024
1 parent 698fd1d commit 902bd5f
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions srcs/frontend/js/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -425,21 +425,20 @@ window.onpopstate = () => {


function translate(lang) {
let currentLanguage = localStorage.getItem('language');
if (!currentLanguage) {
currentLanguage = lang || 'en';
localStorage.setItem('language', currentLanguage);
let currentLanguagetmp = localStorage.getItem('language');
if (!currentLanguagetmp) {
currentLanguagetmp = lang || 'en';
localStorage.setItem('language', currentLanguagetmp);
currentLanguage = currentLanguagetmp;
}

fetch(`translations/${lang}.json`)
.then(response => response.json())
.then(translations => {
Object.keys(translations).forEach(key => {
const elements = document.getElementsByClassName(key);
if (elements.length > 0) {
Array.from(elements).forEach(element => {
element.innerHTML = translations[key];
});
const element = document.getElementById(key);
if (element) {
element.innerHTML = translations[key];
}
});
})
Expand Down

0 comments on commit 902bd5f

Please sign in to comment.