-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
30 lines (25 loc) · 962 Bytes
/
Copy pathscript.js
File metadata and controls
30 lines (25 loc) · 962 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
document.addEventListener('DOMContentLoaded', () => {
const langSwitcher = document.getElementById('lang-switcher');
const setLanguage = (lang) => {
document.documentElement.lang = lang;
document.title = translations[lang].title;
document.querySelectorAll('[data-lang-key]').forEach(element => {
const key = element.getAttribute('data-lang-key');
if (translations[lang][key]) {
element.innerHTML = translations[lang][key];
}
});
if (lang === 'en') {
langSwitcher.textContent = '中文';
} else {
langSwitcher.textContent = 'English';
}
};
langSwitcher.addEventListener('click', () => {
const currentLang = document.documentElement.lang;
const newLang = currentLang === 'en' ? 'zh' : 'en';
setLanguage(newLang);
});
// Set initial language to English
setLanguage('en');
});