2022-07-26 22:28:50 +01:00
|
|
|
window.browser = window.browser || window.chrome
|
2020-07-12 11:26:48 +10:00
|
|
|
|
2020-07-30 22:40:36 +10:00
|
|
|
function localisePage() {
|
2023-11-11 18:12:36 +01:00
|
|
|
/**
|
|
|
|
* @param {string} tag
|
|
|
|
*/
|
2022-07-26 22:28:50 +01:00
|
|
|
function getMessage(tag) {
|
|
|
|
return tag.replace(/__MSG_(\w+)__/g, (_match, v1) => {
|
|
|
|
return v1 ? browser.i18n.getMessage(v1) : null
|
|
|
|
})
|
|
|
|
}
|
2020-07-12 11:26:48 +10:00
|
|
|
|
2022-07-26 22:28:50 +01:00
|
|
|
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
|
|
|
|
}
|
2021-01-12 20:29:26 +11:00
|
|
|
|
2022-07-26 22:28:50 +01:00
|
|
|
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
|
|
|
|
}
|
2020-07-12 11:26:48 +10:00
|
|
|
}
|
|
|
|
|
2022-04-02 15:23:43 +00:00
|
|
|
export default {
|
2022-07-26 22:28:50 +01:00
|
|
|
localisePage,
|
2022-04-13 14:51:36 +00:00
|
|
|
}
|