WLED/wled00/data/translator.mjs
Christian Schwinne 59025e317e
New settings es6 (merge from pbolduc fork) (#3231)
* Initial new settings page test commit

* quick poc to add chibi style helper and start to change files to es6

* add ready and loaded functions

* added missing pageloaded variable to track if loaded already called.

* More POC to dynamically add content, minimal DOM lib based on chibi

* Add simple translation for any element that has class=l10n

* simply self executing function

---------

Co-authored-by: Phil Bolduc <philbolduc@gmail.com>
2023-06-05 16:33:51 +02:00

28 lines
539 B
JavaScript

import $ from './dom.mjs'
var w = window;
function getText(elm) {
return elm.textContent; // or innerText ?
}
function setText(elm, value) {
if (value) {
elm.textContent = value; // or innerText ?
}
}
// perform simple translation
function translateElement(elm) {
const text = getText(elm);
setText(elm, w.translations[text]);
}
export default function translate(selector) {
if (w.translations) {
$(selector).each(translateElement)
} else {
console.info("no translations");
}
}