From 51486fdabe3f5c60198930d8d42488edb328d609 Mon Sep 17 00:00:00 2001 From: Andy Fuchs Date: Tue, 31 Jan 2023 13:13:05 +0100 Subject: [PATCH] adding localization script --- .../template/property-inspector/inspector.js | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/com.elgato.template.sdPlugin/actions/template/property-inspector/inspector.js b/src/com.elgato.template.sdPlugin/actions/template/property-inspector/inspector.js index 9dea582..15d6130 100644 --- a/src/com.elgato.template.sdPlugin/actions/template/property-inspector/inspector.js +++ b/src/com.elgato.template.sdPlugin/actions/template/property-inspector/inspector.js @@ -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(); +});