Files
muwire/webui/src/main/js/translate.js
zzz 2d3e843d64 Plugin headers and CSP (Gitlab issue #44)
Prep for stricter script-src:
Add headers, remove js onload, move init call to the js
Add nonces to all scripts, can't use yet due to innerHTML (see Gitlab issue #45)
2020-05-11 07:50:36 -04:00

34 lines
712 B
JavaScript

// map is standard json mapping, generated in the .jsp
// and then passed to initTranslate()
// map = '{ "Host" : "xxx", "Search" : "yyy" }'
var translations = new Map();
function initTranslate(map) {
var obj = JSON.parse(map);
Object.keys(obj).forEach(k => { translations.set(k, obj[k]) });
}
function _t(s) {
var rv = translations.get(s);
if (rv == null) {
rv = s;
}
return rv;
}
// s must contain {0}
// p will replace {0}
function _t(s, p) {
var rv = translations.get(s);
if (rv == null) {
rv = s;
}
rv = rv.replace("{0}", p);
return rv;
}
document.addEventListener("DOMContentLoaded", function() {
initTranslate(jsTranslations);
}, true);