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)
34 lines
712 B
JavaScript
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);
|