# HG changeset patch # User Edouard Tisserant # Date 1613326520 -3600 # Node ID 2637bb6a6bb09741f9cd4bac19e81b2543b99b7f # Parent 6d4c1e6560acd4c381f48b9022501e776f692a8c SVGHMI: allow i18n of formated strings of HMI:Messages. This was by construction impossible since formating was given as an argument. Now added optional "format" labelled element in HMI:Display, so that it can be translated, when labelled "_format". diff -r 6d4c1e6560ac -r 2637bb6a6bb0 svghmi/svghmi.js --- a/svghmi/svghmi.js Sun Feb 14 05:30:29 2021 +0100 +++ b/svghmi/svghmi.js Sun Feb 14 19:15:20 2021 +0100 @@ -1,9 +1,7 @@ // svghmi.js -var updates = {}; var need_cache_apply = []; - function dispatch_value(index, value) { let widgets = subscribers(index); @@ -204,35 +202,42 @@ } }); -var translated = false; +function svg_text_to_multiline(elt) { + return(Array.prototype.map.call(elt.children, x=>x.textContent).join("\\\\n")); +} + +function multiline_to_svg_text(elt, str) { + str.split('\\\\n').map((line,i) => {elt.children[i].textContent = line;}); +} function switch_langnum(langnum) { if(langnum == current_lang) { return; } - if (!translated) { - translated = true; - for (let translation of translations) { - let [objs] = translation; - translation.push(Array.prototype.map.call(objs[0].children, x=>x.textContent).join("\\\\n")); - } - } - for (let translation of translations) { let [objs, msgs, orig] = translation; let msg = langnum == 0 ? orig : msgs[langnum - 1]; for (let obj of objs) { - msg.split('\\\\n').map((line,i) => {obj.children[i].textContent = line;}); + multiline_to_svg_text(obj, msg); + obj.setAttribute("lang",langnum); } } current_lang = langnum; } + +// backup original texts +for (let translation of translations) { + let [objs] = translation; + translation.push(svg_text_to_multiline(objs[0])); +} + var lang_local_index = hmi_local_index("lang"); subscribers(lang_local_index).add({ indexes: [lang_local_index], new_hmi_value: function(index, value, oldval) { switch_langnum(value); + switch_page(); } }); var current_lang = 0; @@ -397,7 +402,6 @@ jumps_need_update = true; requestHMIAnimation(); - jump_history.push([page_name, page_index]); if(jump_history.length > 42) jump_history.shift(); diff -r 6d4c1e6560ac -r 2637bb6a6bb0 svghmi/widget_display.ysl2 --- a/svghmi/widget_display.ysl2 Sun Feb 14 05:30:29 2021 +0100 +++ b/svghmi/widget_display.ysl2 Sun Feb 14 19:15:20 2021 +0100 @@ -7,15 +7,20 @@ frequency = 5; dispatch(value, oldval, index) { this.fields[index] = value; - this.element.textContent = this.args.length == 1 ? vsprintf(this.args[0],this.fields) : this.fields.join(' '); + this.request_animate(); } } || template "widget[@type='Display']", mode="widget_defs" { param "hmi_element"; - if "$hmi_element[not(self::svg:text)]" - error > Display Widget id="«$hmi_element/@id»" is not a svg::text element + + const "format" optional_labels("format"); + const "has_format","string-length($format)>0"; + value "$format"; + + if "$hmi_element[not(self::svg:text)] and not($has_format)" + error > Display Widget id="«$hmi_element/@id»" must be a svg::text element itself or a group containing a svg:text element labelled "format" const "field_initializer" foreach "path" { choose{ @@ -25,6 +30,28 @@ if "position()!=last()" > , } | fields: [«$field_initializer»], + | animate: function(){ + choose { + when "$has_format" { + | if(this.format_elt.getAttribute("lang")) { + | this.format = svg_text_to_multiline(this.format_elt); + | this.format_elt.removeAttribute("lang"); + | } + | let str = vsprintf(this.format,this.fields); + | multiline_to_svg_text(this.format_elt, str); + } + otherwise { + | let str = this.args.length == 1 ? vsprintf(this.args[0],this.fields) : this.fields.join(' '); + | multiline_to_svg_text(this.element, str); + } + } + | }, + | + if "$has_format" { + | init: function() { + | this.format = svg_text_to_multiline(this.format_elt); + | }, + } } emit "preamble:display" diff -r 6d4c1e6560ac -r 2637bb6a6bb0 svghmi/widgets_common.ysl2 --- a/svghmi/widgets_common.ysl2 Sun Feb 14 05:30:29 2021 +0100 +++ b/svghmi/widgets_common.ysl2 Sun Feb 14 19:15:20 2021 +0100 @@ -65,6 +65,7 @@ emit "preamble:local-variable-indexes" { || + let hmi_locals = {}; var last_remote_index = hmitree_types.length - 1; var next_available_index = hmitree_types.length; @@ -95,6 +96,7 @@ ]); var persistent_indexes = new Map(); var cache = hmitree_types.map(_ignored => undefined); + var updates = {}; function page_local_index(varname, pagename){ let pagevars = hmi_locals[pagename]; @@ -155,11 +157,11 @@ if(!this.unsubscribable) for(let i = 0; i < this.indexes.length; i++) { /* flush updates pending because of inhibition */ - let inhibition = this.inhibit[index]; + let inhibition = this.inhibit[i]; if(inhibition != undefined){ clearTimeout(inhibition); - this.lastapply[index] = undefined; - this.unhinibit(index); + this.lastapply[i] = undefined; + this.unhinibit(i); } let index = this.indexes[i]; if(this.relativeness[i]) diff -r 6d4c1e6560ac -r 2637bb6a6bb0 tests/svghmi_i18n/svghmi_0@svghmi/fr_FR.mo Binary file tests/svghmi_i18n/svghmi_0@svghmi/fr_FR.mo has changed diff -r 6d4c1e6560ac -r 2637bb6a6bb0 tests/svghmi_i18n/svghmi_0@svghmi/fr_FR.po --- a/tests/svghmi_i18n/svghmi_0@svghmi/fr_FR.po Sun Feb 14 05:30:29 2021 +0100 +++ b/tests/svghmi_i18n/svghmi_0@svghmi/fr_FR.po Sun Feb 14 19:15:20 2021 +0100 @@ -5,8 +5,8 @@ msgid "" msgstr "" "Project-Id-Version: \n" -"POT-Creation-Date: 2021-01-22 10:38+CET\n" -"PO-Revision-Date: 2021-01-22 10:39+0100\n" +"POT-Creation-Date: 2021-02-14 18:36+CET\n" +"PO-Revision-Date: 2021-02-14 18:37+0100\n" "Last-Translator: \n" "Language-Team: \n" "Language: fr_FR\n" @@ -14,9 +14,12 @@ "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Generated-By: SVGHMI 1.0\n" -"X-Generator: Poedit 2.3\n" +"X-Generator: Poedit 2.4.2\n" "Plural-Forms: nplurals=2; plural=(n > 1);\n" +msgid "height is %d meters" +msgstr "la hauteur est de %d metres" + msgid "This is an integer value : %d" msgstr "C'est un nombre entier : %d" diff -r 6d4c1e6560ac -r 2637bb6a6bb0 tests/svghmi_i18n/svghmi_0@svghmi/messages.pot --- a/tests/svghmi_i18n/svghmi_0@svghmi/messages.pot Sun Feb 14 05:30:29 2021 +0100 +++ b/tests/svghmi_i18n/svghmi_0@svghmi/messages.pot Sun Feb 14 19:15:20 2021 +0100 @@ -5,7 +5,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" -"POT-Creation-Date: 2021-02-09 16:59+CET\n" +"POT-Creation-Date: 2021-02-14 19:05+CET\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -15,6 +15,10 @@ "Generated-By: SVGHMI 1.0\n" +#:svghmi.svg: format:text424 +msgid "height is %d meters" +msgstr "" + #:svghmi.svg: formatfortext:text5271 msgid "This is an integer value : %d" msgstr "" diff -r 6d4c1e6560ac -r 2637bb6a6bb0 tests/svghmi_i18n/svghmi_0@svghmi/sl_SI.mo Binary file tests/svghmi_i18n/svghmi_0@svghmi/sl_SI.mo has changed diff -r 6d4c1e6560ac -r 2637bb6a6bb0 tests/svghmi_i18n/svghmi_0@svghmi/sl_SI.po --- a/tests/svghmi_i18n/svghmi_0@svghmi/sl_SI.po Sun Feb 14 05:30:29 2021 +0100 +++ b/tests/svghmi_i18n/svghmi_0@svghmi/sl_SI.po Sun Feb 14 19:15:20 2021 +0100 @@ -5,17 +5,21 @@ msgid "" msgstr "" "Project-Id-Version: \n" -"POT-Creation-Date: 2021-01-22 11:13+CET\n" -"PO-Revision-Date: 2021-01-22 11:22+0100\n" +"POT-Creation-Date: 2021-02-14 18:36+CET\n" +"PO-Revision-Date: 2021-02-14 18:38+0100\n" +"Last-Translator: \n" "Language-Team: \n" +"Language: sl_SI\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Generated-By: SVGHMI 1.0\n" -"X-Generator: Poedit 2.3\n" -"Last-Translator: \n" -"Plural-Forms: nplurals=4; plural=(n%100==1 ? 0 : n%100==2 ? 1 : n%100>=3 && n%100<=4 ? 2 : 3);\n" -"Language: sl_SI\n" +"X-Generator: Poedit 2.4.2\n" +"Plural-Forms: nplurals=4; plural=(n%100==1 ? 0 : n%100==2 ? 1 : n%100>=3 && n" +"%100<=4 ? 2 : 3);\n" + +msgid "height is %d meters" +msgstr "To je celo število %d m" msgid "This is an integer value : %d" msgstr "To je celo število %d" diff -r 6d4c1e6560ac -r 2637bb6a6bb0 tests/svghmi_i18n/svghmi_0@svghmi/svghmi.svg --- a/tests/svghmi_i18n/svghmi_0@svghmi/svghmi.svg Sun Feb 14 05:30:29 2021 +0100 +++ b/tests/svghmi_i18n/svghmi_0@svghmi/svghmi.svg Sun Feb 14 19:15:20 2021 +0100 @@ -2415,12 +2415,12 @@ inkscape:pageopacity="0" inkscape:pageshadow="2" inkscape:document-units="px" - inkscape:current-layer="hmi0" + inkscape:current-layer="g436" showgrid="false" units="px" - inkscape:zoom="2" - inkscape:cx="1015.4336" - inkscape:cy="539.83485" + inkscape:zoom="0.70710678" + inkscape:cx="575.80285" + inkscape:cy="308.66839" inkscape:window-width="1939" inkscape:window-height="844" inkscape:window-x="3325" @@ -2613,4 +2613,20 @@ inkscape:transform-center-y="10.92088" inkscape:label="button" /> + + height is %d meters +