From 85a78a6e486cab2b8ee506c01d369b7004c5d669 Mon Sep 17 00:00:00 2001 From: Bernd Hahnebach Date: Fri, 18 Dec 2020 07:14:42 +0100 Subject: [PATCH] bimtester: se gettext for message translation --- .../bimtester/features/steps/ifcdata.py | 8 +++--- .../bimtester/features/steps/ifcdata_de.py | 18 +++---------- .../bimtester/features/steps/ifcdata_fr.py | 12 +++------ .../features/steps/ifcdata_methods.py | 9 +++++++ .../bimtester/features/steps/utils.py | 11 +++++--- .../locale/de/LC_MESSAGES/messages.mo | Bin 0 -> 556 bytes .../locale/de/LC_MESSAGES/messages.po | 24 ++++++++++++++++++ .../locale/en/LC_MESSAGES/messages.mo | Bin 0 -> 532 bytes .../locale/en/LC_MESSAGES/messages.po | 24 ++++++++++++++++++ .../locale/fr/LC_MESSAGES/messages.mo | Bin 0 -> 415 bytes .../locale/fr/LC_MESSAGES/messages.po | 24 ++++++++++++++++++ .../bimtester/locale/messages.pot | 23 +++++++++++++++++ src/ifcbimtester/bimtester/run.py | 12 ++++++++- 13 files changed, 135 insertions(+), 30 deletions(-) create mode 100644 src/ifcbimtester/bimtester/features/steps/ifcdata_methods.py create mode 100644 src/ifcbimtester/bimtester/locale/de/LC_MESSAGES/messages.mo create mode 100644 src/ifcbimtester/bimtester/locale/de/LC_MESSAGES/messages.po create mode 100644 src/ifcbimtester/bimtester/locale/en/LC_MESSAGES/messages.mo create mode 100644 src/ifcbimtester/bimtester/locale/en/LC_MESSAGES/messages.po create mode 100644 src/ifcbimtester/bimtester/locale/fr/LC_MESSAGES/messages.mo create mode 100644 src/ifcbimtester/bimtester/locale/fr/LC_MESSAGES/messages.po create mode 100644 src/ifcbimtester/bimtester/locale/messages.pot diff --git a/src/ifcbimtester/bimtester/features/steps/ifcdata.py b/src/ifcbimtester/bimtester/features/steps/ifcdata.py index 5a3b3e6027..3f3a0cdb47 100644 --- a/src/ifcbimtester/bimtester/features/steps/ifcdata.py +++ b/src/ifcbimtester/bimtester/features/steps/ifcdata.py @@ -1,7 +1,9 @@ +import gettext from behave import step -from utils import assert_schema +from ifcdata_methods import assert_schema from utils import IfcFile +from utils import switch_locale @step('The IFC file "{file}" must be provided') @@ -14,8 +16,8 @@ def step_impl(context, file): @step("IFC data must use the {schema} schema") def step_impl(context, schema): - context.schema = IfcFile.get().schema - assert_schema(schema, context.schema) + switch_locale(context.localedir, "en") + assert_schema(context, schema) @step('The IFC file "{file}" is exempt from being provided') diff --git a/src/ifcbimtester/bimtester/features/steps/ifcdata_de.py b/src/ifcbimtester/bimtester/features/steps/ifcdata_de.py index a21d248782..58ede99a1b 100644 --- a/src/ifcbimtester/bimtester/features/steps/ifcdata_de.py +++ b/src/ifcbimtester/bimtester/features/steps/ifcdata_de.py @@ -1,19 +1,9 @@ from behave import step -from utils import assert_schema - - -# https://behave.readthedocs.io/en/latest/api.html#step-macro-calling-steps-from-other-steps -# https://stackoverflow.com/questions/46735425/how-to-only-show-failing-tests-from-behave -# https://community.osarch.org/discussion/comment/4533/#Comment_4533 +from ifcdata_methods import assert_schema +from utils import switch_locale @step("Die IFC Daten müssen das {schema} Schema benutzen") def step_impl(context, schema): - try: - context.execute_steps( - "* IFC data must use the {schema} schema".format(schema=schema) - ) - except Exception: - assert_schema(schema, context.schema) - # TODO translate error - # "Wir haben ein Schema {} erwartet, aber die Daten sind Schema (}" + switch_locale(context.localedir, "de") + assert_schema(context, schema) diff --git a/src/ifcbimtester/bimtester/features/steps/ifcdata_fr.py b/src/ifcbimtester/bimtester/features/steps/ifcdata_fr.py index ed465fe02a..1172cefdbc 100644 --- a/src/ifcbimtester/bimtester/features/steps/ifcdata_fr.py +++ b/src/ifcbimtester/bimtester/features/steps/ifcdata_fr.py @@ -1,13 +1,9 @@ from behave import step -from utils import assert_schema - +from ifcdata_methods import assert_schema +from utils import switch_locale @step("Les données IFC doivent utiliser le schéma {schema}") def step_impl(context, schema): - try: - context.execute_steps( - "* IFC data must use the {schema} schema".format(schema=schema) - ) - except Exception: - assert_schema(schema, context.schema) + switch_locale(context.localedir, "fr") + assert_schema(context, schema) diff --git a/src/ifcbimtester/bimtester/features/steps/ifcdata_methods.py b/src/ifcbimtester/bimtester/features/steps/ifcdata_methods.py new file mode 100644 index 0000000000..c084fc34b8 --- /dev/null +++ b/src/ifcbimtester/bimtester/features/steps/ifcdata_methods.py @@ -0,0 +1,9 @@ +from utils import IfcFile + + +def assert_schema(context, target_schema): + real_schema = IfcFile.get().schema + assert real_schema == target_schema, ( + _("We expected a schema of {} but instead got {}") + .format(target_schema, real_schema) + ) diff --git a/src/ifcbimtester/bimtester/features/steps/utils.py b/src/ifcbimtester/bimtester/features/steps/utils.py index 5ae6c8c180..bbf1052d12 100644 --- a/src/ifcbimtester/bimtester/features/steps/utils.py +++ b/src/ifcbimtester/bimtester/features/steps/utils.py @@ -80,8 +80,11 @@ def assert_pset(element, pset_name, prop_name=None, value=None): ) -def assert_schema(real_schema, target_schema): - assert real_schema == target_schema, ( - "We expected a schema of {} but instead got {}" - .format(target_schema, real_schema) +def switch_locale(locale_dir, locale_id="en"): + from gettext import translation + newlang = translation( + "messages", + localedir=locale_dir, + languages=[locale_id] ) + newlang.install() diff --git a/src/ifcbimtester/bimtester/locale/de/LC_MESSAGES/messages.mo b/src/ifcbimtester/bimtester/locale/de/LC_MESSAGES/messages.mo new file mode 100644 index 0000000000000000000000000000000000000000..f95ef3bb99b1f08629f04234d170cfa1b397428e GIT binary patch literal 556 zcmZ9J&2HN;41m32yZG315A1Ejs?_$O2%Ki#@%38z@SZWxtn+#&ZI0j) z0k3OZ5Gs)17b{##uuHhRhj~MwjVF`}N=s}Ca%X>YtQabBfzE4dQpk(RX?8q=i>#Oq zCud=SwRI%MzSK$_HKi9bn?g1|9F7hS2ZJJ;PQ!d63cS*70x^(;DI`%6i8v8)7oxp1 zj=x876on({Nz9xyzLI2J3T!cDBTK%a@c%)~P_A1G?2kqVmF`$q{s{A`ak3I8)~$UC zrhYm4e$sL7nXKx+FohUrEhR|^Fo0@A8Uej(}No{(tSV`xR`VB2b z_bsk{8=(t1viklRUri+i=>AAYNISqz2TCKfzh}TSbo((n_zQK0pW*-j literal 0 HcmV?d00001 diff --git a/src/ifcbimtester/bimtester/locale/de/LC_MESSAGES/messages.po b/src/ifcbimtester/bimtester/locale/de/LC_MESSAGES/messages.po new file mode 100644 index 0000000000..a1a86662aa --- /dev/null +++ b/src/ifcbimtester/bimtester/locale/de/LC_MESSAGES/messages.po @@ -0,0 +1,24 @@ +# German translations for PROJECT. +# Copyright (C) 2020 ORGANIZATION +# This file is distributed under the same license as the PROJECT project. +# FIRST AUTHOR , 2020. +# +msgid "" +msgstr "" +"Project-Id-Version: PROJECT VERSION\n" +"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" +"POT-Creation-Date: 2020-12-17 15:14+0100\n" +"PO-Revision-Date: 2020-12-18 06:11+0100\n" +"Last-Translator: \n" +"Language: de\n" +"Language-Team: de \n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=utf-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Generated-By: Babel 2.6.0\n" +"X-Generator: Poedit 2.2.1\n" + +#: features/steps/ifcdata_methods.py:7 +msgid "We expected a schema of {} but instead got {}" +msgstr "Wir haben das Schema {} erwartet, aber die Daten nutzen das Schema {}" diff --git a/src/ifcbimtester/bimtester/locale/en/LC_MESSAGES/messages.mo b/src/ifcbimtester/bimtester/locale/en/LC_MESSAGES/messages.mo new file mode 100644 index 0000000000000000000000000000000000000000..a8c96e94499ccde60baae75ba5f691d5c70540cd GIT binary patch literal 532 zcmb7>y-ve05P$=MB_lJ#v4OxP$xu}(Mg0q?sHGvTfYoiTsZnZ2wu4$B#8dEkj64Sy zKp;j={-paqpZ&JC^Xian6Z^you}hp0mBa)iZivN}Q@D+i$zXi#CRiwK z*~nxfW!*9}Y^p+tMxDX1-Rbv}Xfko*F-!1KR1H|4TMQxa0+0Ct^BdsRLq9n7e9v=- z+*mf%T$-F)r9&W(%u1e71, 2020. +# +msgid "" +msgstr "" +"Project-Id-Version: PROJECT VERSION\n" +"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" +"POT-Creation-Date: 2020-12-17 15:14+0100\n" +"PO-Revision-Date: 2020-12-18 06:12+0100\n" +"Last-Translator: \n" +"Language: en\n" +"Language-Team: en \n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=utf-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Generated-By: Babel 2.6.0\n" +"X-Generator: Poedit 2.2.1\n" + +#: features/steps/ifcdata_methods.py:7 +msgid "We expected a schema of {} but instead got {}" +msgstr "We expected a schema of {} but instead got {}" diff --git a/src/ifcbimtester/bimtester/locale/fr/LC_MESSAGES/messages.mo b/src/ifcbimtester/bimtester/locale/fr/LC_MESSAGES/messages.mo new file mode 100644 index 0000000000000000000000000000000000000000..7f24af08f3955df2636f138aaa4c579141e289cd GIT binary patch literal 415 zcmYLF%TB{E5G;a|kDNL9zySmfi4Rq9Y1LOiK?#l0sN(82ZZJyi$aWC@5PpwuVFRcg zX=Lxt+T-!}`Po+wa00vlUII^nx4;e|P=I(3Yd3R1X7sz*I1-m+C5)9?F`VU#=V(^o zRg^E|#S6+sqm3h}tz=22ZDmQJ8IICPoQx;)c^)m7C|i(Re8}zsGUrY(OnvH;fRZ4@ zexC*O#t(cSCEPkv7_My1oi+?ZM^!Da;KbG(3Q`EZ>pJ)$NyfGGw5diYt6Rfs@~F+u zGOU{4(hlhW|80j?3XgDbJwR!kM#n&b=cAccPAKr+H(=$&r@L!vF4X{U-ng;C4O_P* z;c>2e<5n0Fsf{kBsu&K}(xE4zgn@wY6MKfId@X8By*@a+l7Fp>m1$8*2MYB9)cXMo C+H}zX literal 0 HcmV?d00001 diff --git a/src/ifcbimtester/bimtester/locale/fr/LC_MESSAGES/messages.po b/src/ifcbimtester/bimtester/locale/fr/LC_MESSAGES/messages.po new file mode 100644 index 0000000000..0517d51973 --- /dev/null +++ b/src/ifcbimtester/bimtester/locale/fr/LC_MESSAGES/messages.po @@ -0,0 +1,24 @@ +# French translations for PROJECT. +# Copyright (C) 2020 ORGANIZATION +# This file is distributed under the same license as the PROJECT project. +# FIRST AUTHOR , 2020. +# +msgid "" +msgstr "" +"Project-Id-Version: PROJECT VERSION\n" +"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" +"POT-Creation-Date: 2020-12-17 15:14+0100\n" +"PO-Revision-Date: 2020-12-18 06:12+0100\n" +"Last-Translator: \n" +"Language: fr\n" +"Language-Team: fr \n" +"Plural-Forms: nplurals=2; plural=(n > 1);\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=utf-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Generated-By: Babel 2.6.0\n" +"X-Generator: Poedit 2.2.1\n" + +#: features/steps/ifcdata_methods.py:7 +msgid "We expected a schema of {} but instead got {}" +msgstr "" diff --git a/src/ifcbimtester/bimtester/locale/messages.pot b/src/ifcbimtester/bimtester/locale/messages.pot new file mode 100644 index 0000000000..ac5ec26174 --- /dev/null +++ b/src/ifcbimtester/bimtester/locale/messages.pot @@ -0,0 +1,23 @@ +# Translations template for PROJECT. +# Copyright (C) 2020 ORGANIZATION +# This file is distributed under the same license as the PROJECT project. +# FIRST AUTHOR , 2020. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: PROJECT VERSION\n" +"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" +"POT-Creation-Date: 2020-12-17 15:14+0100\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=utf-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Generated-By: Babel 2.6.0\n" + +#: features/steps/ifcdata_methods.py:7 +msgid "We expected a schema of {} but instead got {}" +msgstr "" + diff --git a/src/ifcbimtester/bimtester/run.py b/src/ifcbimtester/bimtester/run.py index 7eade8784b..3e6356557e 100644 --- a/src/ifcbimtester/bimtester/run.py +++ b/src/ifcbimtester/bimtester/run.py @@ -11,6 +11,9 @@ from behave.__main__ import main as behave_main # get bimtester source code module path bimtester_path = os.path.dirname(os.path.realpath(__file__)) # print(bimtester_path) +locale_path = os.path.join(bimtester_path, "locale") + + try: # PyInstaller creates a temp folder and stores path in _MEIPASS base_path = sys._MEIPASS @@ -36,6 +39,10 @@ def run_tests(args): "--outfile", "report/report.json" ]) + behave_args.extend([ + "--define", + "localedir={}".format(locale_path) + ]) behave_main(behave_args) print("# All tests are finished.") return True @@ -262,7 +269,10 @@ def run_intmp_tests(args={}): os.path.join(report_path, "report.json"), # next two lines are one arg "--define", - "ifcbasename={}".format(os.path.splitext(ifc_filename)[0]) + "ifcbasename={}".format(os.path.splitext(ifc_filename)[0]), + # next two lines are one arg + "--define", + "localedir={}".format(locale_path) ]) print(behave_args)