# HG changeset patch # User Edouard Tisserant # Date 1612470238 -3600 # Node ID f45e413a0f40048de0c41041188cd84518f61ad9 # Parent 1fb0c07bd97b0799e013b4735588c88ef26f0209 SVGHMI: generate JS translation literals so that it is possible to also translate uses of texts, and added JS code that apply translations to tspans diff -r 1fb0c07bd97b -r f45e413a0f40 svghmi/i18n.ysl2 --- a/svghmi/i18n.ysl2 Thu Feb 04 21:20:01 2021 +0100 +++ b/svghmi/i18n.ysl2 Thu Feb 04 21:23:58 2021 +0100 @@ -22,14 +22,21 @@ const "translations", "ns:GetTranslations($translatable_strings)"; > var langs = [ foreach "$translations/langs/lang" { - value "."; + > "«.»" if "position()!=last()" > , } | ]; | var translations = [ foreach "$translatable_texts" { const "n","position()"; - > ["«@id»",[ + const "current_id","@id"; + const "text_unlinked_uses","$result_svg_ns//svg:text[@original = $current_id]/@id"; + > [[ + foreach "@id | $text_unlinked_uses" { + > id("«.»") + if "position()!=last()" > , + } + > ],[ foreach "$translations/messages/msgid[$n]/msg" { > " foreach "line" { diff -r 1fb0c07bd97b -r f45e413a0f40 svghmi/svghmi.js --- a/svghmi/svghmi.js Thu Feb 04 21:20:01 2021 +0100 +++ b/svghmi/svghmi.js Thu Feb 04 21:23:58 2021 +0100 @@ -465,3 +465,18 @@ current_modal = undefined; }; +function switch_lang(lang) { + langnum = langs.indexOf(lang); + if(langnum == -1) { + console.log("Unknown language: "+lang+", return to original"); + location.reload(true); + } + + for (let translation of translations) { + let [objs, msgs] = translation; + let msg = msgs[langnum]; + for (let obj of objs) { + msg.split('\\\\n').map((line,i) => {obj.children[i].textContent = line;}); + } + } +}