# HG changeset patch # User Edouard Tisserant # Date 1612886948 -3600 # Node ID 450cd01324ad112df3b3332aa83024121fc271e8 # Parent a1e2eff0bc585f688a03174004218973da558358 SVGHMI: HMI:DropDown:#langs@lang now automatically shows human readable list of languages. tests/svghmi_i18n updated accordingly. diff -r a1e2eff0bc58 -r 450cd01324ad svghmi/i18n.py --- 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 diff -r a1e2eff0bc58 -r 450cd01324ad svghmi/i18n.ysl2 --- 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()" > , diff -r a1e2eff0bc58 -r 450cd01324ad svghmi/widget_dropdown.ysl2 --- 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 } diff -r a1e2eff0bc58 -r 450cd01324ad tests/svghmi_i18n/svghmi_0@svghmi/svghmi.svg --- 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"> + + @@ -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" /> sel_0 + id="tspan421">Language (Country)