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 = () => { const handleContentLoaded = () => {
dispatch({ type: "GET_TAB" }, null, ({ hostname, id }) => { dispatch({ type: "GET_TAB" }, null, ({ hostname }) => {
dispatch({ hostname, type: "GET_CACHE" }, null, ({ enabled }) => { dispatch({ hostname, type: "GET_CACHE" }, null, ({ enabled }) => {
translate();
const host = document.getElementById("host"); const host = document.getElementById("host");
const like = document.getElementById("like"); const like = document.getElementById("like");
const power = document.getElementById("power"); const power = document.getElementById("power");
@ -114,6 +116,21 @@ const handleContentLoaded = () => {
}); });
}; };
/**
* @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 * @description Listen to document ready
* @listens document#ready * @listens document#ready