-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtranslations.js
37 lines (34 loc) · 1.27 KB
/
translations.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
// translations.js
(function() {
window.applyTranslations = function() {
document.querySelectorAll('[data-translate]').forEach(element => {
const key = element.getAttribute('data-translate');
if (window.translations[key]) {
if (element.tagName === 'INPUT' && element.placeholder) {
element.placeholder = window.translations[key];
} else {
element.innerText = window.translations[key];
}
}
});
};
window.loadLanguage = function(lang, callback) {
fetch(`languages/${lang}.json`)
.then(response => response.json())
.then(data => {
window.translations = data;
applyTranslations();
if (callback) callback();
})
.catch(error => console.error('Error loading translations:', error));
};
function initializeTranslations() {
chrome.storage.local.get(['language'], function(result) {
const userLang = result.language || navigator.language.split('-')[0] || 'en';
loadLanguage(userLang);
});
}
document.addEventListener('DOMContentLoaded', function() {
initializeTranslations();
});
})();