adding localization script
This commit is contained in:
parent
3411f3f9a2
commit
51486fdabe
1 changed files with 27 additions and 0 deletions
|
|
@ -31,3 +31,30 @@ window.sendToInspector = (data) => {
|
|||
document.querySelector('#open-external').addEventListener('click', () => {
|
||||
window.open('../../../external.html');
|
||||
});
|
||||
|
||||
const localize = (s) => {
|
||||
if(typeof s === 'undefined') return '';
|
||||
let str = String(s);
|
||||
try {
|
||||
str = $localizedStrings[str] || str;
|
||||
} catch(b) {}
|
||||
return str;
|
||||
};
|
||||
|
||||
const localizeUI = () => {
|
||||
const el = document.querySelector('.sdpi-wrapper');
|
||||
Array.from(el.querySelectorAll('.sdpi-item-label')).forEach(e => {
|
||||
const s = e.innerText.trim();
|
||||
e.innerHTML = e.innerHTML.replace(s, localize(s));
|
||||
});
|
||||
Array.from(el.querySelectorAll('*:not(script)')).forEach(e => {
|
||||
if(e.childNodes && e.childNodes.length > 0 && e.childNodes[0].nodeValue && typeof e.childNodes[0].nodeValue === 'string') {
|
||||
const s = e.childNodes[0].nodeValue.trim();
|
||||
e.childNodes[0].nodeValue = e.childNodes[0].nodeValue.replace(s, localize(s));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
$PI.on('localizationLoaded', (jsn) => {
|
||||
localizeUI();
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue