feat(scripts): apply translations

This commit is contained in:
wanhose 2021-11-08 17:10:35 +01:00
parent 2e589f2adc
commit 5bb09feebd

View File

@ -94,8 +94,10 @@ const handleRate = (event) => {
*/
const handleContentLoaded = () => {
dispatch({ type: "GET_TAB" }, null, ({ hostname, id }) => {
dispatch({ type: "GET_TAB" }, null, ({ hostname }) => {
dispatch({ hostname, type: "GET_CACHE" }, null, ({ enabled }) => {
translate();
const host = document.getElementById("host");
const like = document.getElementById("like");
const power = document.getElementById("power");
@ -108,12 +110,27 @@ const handleContentLoaded = () => {
reload.addEventListener("click", handleReload);
store.setAttribute("href", isChromium ? chromeUrl : firefoxUrl);
unlike.addEventListener("click", handleRate);
if (location) host.innerText = hostname.replace("www.", "");
if (location) host.innerText = hostname.replace("www.", " ");
if (!enabled) power.removeAttribute("checked");
});
});
};
/**
* @description Applies translations to tags with i18n data attribute
*/
const translate = () => {
const nodes = document.querySelectorAll("[data-i18n]");
for (let i = nodes.length; i--; ) {
const node = nodes[i];
const { i18n } = node.dataset;
node.innerHTML = chrome.i18n.getMessage(i18n);
}
};
/**
* @description Listen to document ready
* @listens document#ready