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
--- 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" {
--- 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;});
+ }
+ }
+}