-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
35 lines (32 loc) · 1.2 KB
/
index.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
// Define a dictionary of translations for each language
const translations = {
'en-gb': {
"HOME": "Home",
"ABOUT": "About",
"CONTACT": "Contact",
"MELIODAS": "Welcome on my personal website !",
"ORALTA": "You can also discover my Oralta project by clicking on the image",
},
'fr-fr': {
"HOME": "Accueil",
"ABOUT": "À propos",
"CONTACT": "Contact",
"MELIODAS": "Bienvenue sur mon site web personnel !",
"ORALTA": "Vous pouvez aussi découvrir mon projet Oralta en cliquant sur l'image",
}
};
// Get the language buttons and the elements with the lang class
const langButtons = document.querySelectorAll('.translate');
const langElements = document.querySelectorAll('.lang');
// Add click event listeners to the language buttons
langButtons.forEach(button => {
button.addEventListener('click', () => {
// Get the selected language from the button id
const lang = button.id;
// Update the text content of the elements with the lang class
langElements.forEach(element => {
const key = element.getAttribute('key');
element.textContent = translations[lang][key];
});
});
});