-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
39 lines (35 loc) · 917 Bytes
/
script.js
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
31
32
33
34
35
36
37
38
39
var btn = document.querySelector("button"),
currentLanguage = document.querySelector("[data-current]"),
target = document.querySelectorAll("[data-target]"),
source = [
{
eng : "Hello World!", //English
es : "Hola Mundo!" //Spanish
},
{
eng : "Switch Language", //English
es : "Cambiar De Idioma" //Spanish
},
]
const lang = localStorage.getItem("lang")
if (lang == "eng" || lang == null){
for(i = 0; i < source.length; i++){
target[i].textContent = source[i].eng
}
currentLanguage.textContent = "English"
}
else if (lang == "es"){
for(i = 0; i < source.length; i++){
target[i].textContent = source[i].es
}
currentLanguage.textContent = "Spanish"
}
btn.addEventListener("click", () => {
if (lang == "es"){
localStorage.setItem("lang","eng")
}
else if (lang == "eng" || lang == null){
localStorage.setItem("lang","es")
}
window.location = ""
})