blob: a4bbca920102d608a3d65144a7a2a656a9470710 (
plain) (
blame)
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
|
window.browser = window.browser || window.chrome;
function localisePage() {
function getMessage(tag) {
return tag.replace(/__MSG_(\w+)__/g, (_match, v1) => {
return v1 ? browser.i18n.getMessage(v1) : null;
});
}
const elements = document.querySelectorAll("[data-localise]");
for (let i in elements)
if (elements.hasOwnProperty(i)) {
const obj = elements[i];
const tag = obj.getAttribute("data-localise").toString();
const msg = getMessage(tag);
if (msg && msg !== tag) obj.textContent = msg;
}
const placeholders = document.querySelectorAll("[data-localise-placeholder]");
for (let i in placeholders)
if (placeholders.hasOwnProperty(i)) {
const obj = placeholders[i];
const tag = obj.getAttribute("data-localise-placeholder").toString();
const msg = getMessage(tag);
if (msg && msg !== tag) obj.placeholder = msg;
}
}
export default {
localisePage
}
|