diff options
author | 0neGal <mail@0negal.com> | 2024-06-08 21:18:42 +0200 |
---|---|---|
committer | 0neGal <mail@0negal.com> | 2024-06-08 21:18:42 +0200 |
commit | aa7f589553787328c1c9cd20e6d798e6b4d16d3e (patch) | |
tree | 4d57007b010e31a6add16ef6579b49a81d924743 /src/app/js | |
parent | 0e747947f4e847f4aefa2912bfa25631b7eb1ef9 (diff) | |
download | Viper-aa7f589553787328c1c9cd20e6d798e6b4d16d3e.tar.gz Viper-aa7f589553787328c1c9cd20e6d798e6b4d16d3e.zip |
rename js/set_dom_strings.js to localize.js
Diffstat (limited to 'src/app/js')
-rw-r--r-- | src/app/js/localize.js (renamed from src/app/js/set_dom_strings.js) | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/src/app/js/set_dom_strings.js b/src/app/js/localize.js index e039ebd..6776566 100644 --- a/src/app/js/set_dom_strings.js +++ b/src/app/js/localize.js @@ -1,4 +1,6 @@ -function format_string(string) { +// localizes `string`, removing instances of `%%string%%` with +// `lang("string")` and so forth +function localize_string(string) { let parts = string.split("%%"); // basic checks to make sure `string` has lang strings @@ -29,8 +31,8 @@ function format_string(string) { return parts.join(""); } -// runs `format_string()` on `el`'s attributes, text nodes and children -function replace_in_el(el) { +// runs `localize_string()` on `el`'s attributes, text nodes and children +function localize_el(el) { // we don't want to mess with script tags if (el.tagName == "SCRIPT") {return} @@ -46,22 +48,22 @@ function replace_in_el(el) { // the node is a text node, so we set its `.textContent` by // running `format_string()` on it el.childNodes[i].textContent = - format_string(el.childNodes[i].textContent) + localize_string(el.childNodes[i].textContent) } // run through attributes and run `format_string()` on their values for (let i = 0; i < attributes.length; i++) { let attr = el.getAttribute(attributes[i]); - el.setAttribute(attributes[i], format_string(attr)) + el.setAttribute(attributes[i], localize_string(attr)) } // run `replace_in_el()` on `el`'s children for (let i = 0; i < el.children.length; i++) { - replace_in_el(el.children[i]); + localize_el(el.children[i]); } } -// replaces lang strings on (almost) all the elements inside `<body>` +// localizes lang strings on (almost) all the elements inside `<body>` module.exports = () => { - replace_in_el(document.body); + localize_el(document.body); } |