SVGHMI: HMI:DropDown:#langs@lang now automatically shows human readable list of languages. tests/svghmi_i18n updated accordingly. svghmi
authorEdouard Tisserant <edouard.tisserant@gmail.com>
Tue, 09 Feb 2021 17:09:08 +0100
branchsvghmi
changeset 3133 450cd01324ad
parent 3132 a1e2eff0bc58
child 3134 af558c9a5141
SVGHMI: HMI:DropDown:#langs@lang now automatically shows human readable list of languages. tests/svghmi_i18n updated accordingly.
svghmi/i18n.py
svghmi/i18n.ysl2
svghmi/widget_dropdown.ysl2
tests/svghmi_i18n/svghmi_0@svghmi/svghmi.svg
--- a/svghmi/i18n.py	Tue Feb 09 08:11:22 2021 +0100
+++ b/svghmi/i18n.py	Tue Feb 09 17:09:08 2021 +0100
@@ -15,6 +15,11 @@
 import ast
 import wx
 
+# to have it for python 2, had to install 
+# https://pypi.org/project/pycountry/18.12.8/
+# python2 -m pip install pycountry==18.12.8 --user
+import pycountry
+
 def open_pofile(pofile):
     """ Opens PO file with POEdit """
     
@@ -92,7 +97,18 @@
         translated_messages.append((msgid,translated_message))
     langs = []
     for lang,translation in translations:
-        langs.append(lang)
+        try:
+            l,c = lang.split("_")
+            language_name = pycountry.languages.get(alpha_2 = l).name
+            country_name = pycountry.countries.get(alpha_2 = c).name
+            langs.append("{} ({})".format(language_name, country_name))
+        except:
+            try:
+                language_name = pycountry.languages.get(alpha_2 = lang).name
+                langs.append(language_name)
+            except:
+                langs.append(lang)
+
         broken = False
         for msgid, msg in translation.iteritems():
             broken = True
--- a/svghmi/i18n.ysl2	Tue Feb 09 08:11:22 2021 +0100
+++ b/svghmi/i18n.ysl2	Tue Feb 09 17:09:08 2021 +0100
@@ -20,7 +20,7 @@
 
 emit "preamble:i18n" {
     const "translations", "ns:GetTranslations($translatable_strings)";
-    > var langs = [
+    > var langs = [ "default",
     foreach "$translations/langs/lang" {
         > "«.»"
         if "position()!=last()" > ,
--- a/svghmi/widget_dropdown.ysl2	Tue Feb 09 08:11:22 2021 +0100
+++ b/svghmi/widget_dropdown.ysl2	Tue Feb 09 17:09:08 2021 +0100
@@ -337,11 +337,17 @@
     param "hmi_element";
     labels("text box button highlight");
     // It is assumed that list content conforms to Array interface.
-||
-    content: [
-    /* TODO : Support HMI:List */
-    ``foreach "arg" | "«@value»",
-    ],
-
-||
+    >   content:
+    choose{
+        // special case when used for language selection
+        when "count(arg) = 1 and arg[1]/@value = '#langs'" {
+            > langs
+        }
+        otherwise {
+            > [\n
+            foreach "arg" | "«@value»",
+            >   ]
+        }
+    }
+    > ,\n
 }
--- a/tests/svghmi_i18n/svghmi_0@svghmi/svghmi.svg	Tue Feb 09 08:11:22 2021 +0100
+++ b/tests/svghmi_i18n/svghmi_0@svghmi/svghmi.svg	Tue Feb 09 17:09:08 2021 +0100
@@ -2418,19 +2418,25 @@
      inkscape:current-layer="hmi0"
      showgrid="false"
      units="px"
-     inkscape:zoom="0.5"
-     inkscape:cx="826.76877"
-     inkscape:cy="73.93813"
-     inkscape:window-width="1431"
+     inkscape:zoom="2"
+     inkscape:cx="1015.4336"
+     inkscape:cy="539.83485"
+     inkscape:window-width="1939"
      inkscape:window-height="844"
-     inkscape:window-x="3841"
-     inkscape:window-y="36"
+     inkscape:window-x="3325"
+     inkscape:window-y="554"
      inkscape:window-maximized="0"
      showguides="true"
      inkscape:guide-bbox="true"
      inkscape:snap-global="true"
      inkscape:snap-bbox="true"
-     inkscape:bbox-nodes="true" />
+     inkscape:bbox-nodes="true">
+    <sodipodi:guide
+       position="1265,637"
+       orientation="1,0"
+       id="guide424"
+       inkscape:locked="false" />
+  </sodipodi:namedview>
   <rect
      style="color:#000000;fill:#ffffff"
      id="page0"
@@ -2554,16 +2560,16 @@
   </g>
   <g
      id="g14237"
-     inkscape:label="HMI:DropDown:orig:fr_FR:sl_SI@lang"
-     transform="matrix(0.81491208,0,0,0.81491208,32.392121,-516.64521)"
+     inkscape:label="HMI:DropDown:#langs@lang"
+     transform="matrix(0.81491208,0,0,0.81491208,92.392121,-676.64521)"
      style="stroke-width:0.35083869">
     <rect
        style="color:#000000;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;vector-effect:none;fill:#53676c;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:1.75419343;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate"
        id="rect14212"
-       width="391.99988"
-       height="130.9433"
+       width="574.92957"
+       height="84.312515"
        x="864.00842"
-       y="923.98993"
+       y="946.07819"
        rx="2.4558709"
        ry="2.4558709"
        inkscape:label="box" />
@@ -2571,31 +2577,31 @@
        inkscape:label="highlight"
        ry="2.4558709"
        rx="2.4558709"
-       y="943.10553"
+       y="968.2616"
        x="864.00842"
-       height="92.71212"
-       width="391.99988"
+       height="39.945667"
+       width="574.92957"
        id="rect5497"
        style="color:#000000;clip-rule:nonzero;display:inline;overflow:visible;visibility:visible;opacity:1;isolation:auto;mix-blend-mode:normal;color-interpolation:sRGB;color-interpolation-filters:linearRGB;solid-color:#000000;solid-opacity:1;vector-effect:none;fill:#0000ff;fill-opacity:1;fill-rule:nonzero;stroke:none;stroke-width:1.75419331;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;color-rendering:auto;image-rendering:auto;shape-rendering:auto;text-rendering:auto;enable-background:accumulate" />
     <text
        id="text14183"
-       y="1011.9975"
-       x="881.44226"
-       style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:80px;line-height:125%;font-family:sans-serif;-inkscape-font-specification:'sans-serif, Normal';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-feature-settings:normal;text-align:start;letter-spacing:0px;word-spacing:0px;writing-mode:lr-tb;text-anchor:start;fill:#d42aff;fill-opacity:1;stroke:none;stroke-width:0.35083869px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
+       y="998.13739"
+       x="890.70056"
+       style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:35.95956421px;line-height:125%;font-family:sans-serif;-inkscape-font-specification:'sans-serif, Normal';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-feature-settings:normal;text-align:start;letter-spacing:0px;word-spacing:0px;writing-mode:lr-tb;text-anchor:start;fill:#d42aff;fill-opacity:1;stroke:none;stroke-width:0.35083869px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
        xml:space="preserve"
        inkscape:label="text"><tspan
          style="text-align:start;text-anchor:start;fill:#d42aff;stroke-width:0.35083869px"
-         y="1011.9975"
-         x="881.44226"
+         y="998.13739"
+         x="890.70056"
          sodipodi:role="line"
-         id="tspan421">sel_0</tspan></text>
+         id="tspan421">Language (Country)</tspan></text>
     <path
        sodipodi:type="star"
        style="opacity:1;vector-effect:none;fill:#a7a5a6;fill-opacity:1;stroke:none;stroke-width:0.12376806;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
        id="path424"
        sodipodi:sides="3"
-       sodipodi:cx="1200.5"
-       sodipodi:cy="975"
+       sodipodi:cx="1387.0236"
+       sodipodi:cy="977.31356"
        sodipodi:r1="43.683521"
        sodipodi:r2="21.841761"
        sodipodi:arg1="1.5707963"
@@ -2603,7 +2609,7 @@
        inkscape:flatsided="false"
        inkscape:rounded="0"
        inkscape:randomized="0"
-       d="m 1200.5,1018.6835 -18.9155,-32.76262 -18.9155,-32.76264 37.831,0 37.831,0 -18.9155,32.76264 z"
+       d="m 1387.0236,1020.9971 -18.9156,-32.76268 -18.9155,-32.76264 37.8311,0 37.831,0 -18.9155,32.76264 z"
        inkscape:transform-center-y="10.92088"
        inkscape:label="button" />
   </g>