Skip to content
This repository was archived by the owner on Nov 24, 2024. It is now read-only.

Commit 85a78a6

Browse files
berndhahnebachMoult
authored andcommitted
bimtester: se gettext for message translation
1 parent 3ae2063 commit 85a78a6

13 files changed

Lines changed: 135 additions & 30 deletions

File tree

src/ifcbimtester/bimtester/features/steps/ifcdata.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
import gettext
12
from behave import step
23

3-
from utils import assert_schema
4+
from ifcdata_methods import assert_schema
45
from utils import IfcFile
6+
from utils import switch_locale
57

68

79
@step('The IFC file "{file}" must be provided')
@@ -14,8 +16,8 @@ def step_impl(context, file):
1416

1517
@step("IFC data must use the {schema} schema")
1618
def step_impl(context, schema):
17-
context.schema = IfcFile.get().schema
18-
assert_schema(schema, context.schema)
19+
switch_locale(context.localedir, "en")
20+
assert_schema(context, schema)
1921

2022

2123
@step('The IFC file "{file}" is exempt from being provided')
Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,9 @@
11
from behave import step
22

3-
from utils import assert_schema
4-
5-
6-
# https://behave.readthedocs.io/en/latest/api.html#step-macro-calling-steps-from-other-steps
7-
# https://stackoverflow.com/questions/46735425/how-to-only-show-failing-tests-from-behave
8-
# https://community.osarch.org/discussion/comment/4533/#Comment_4533
3+
from ifcdata_methods import assert_schema
4+
from utils import switch_locale
95

106
@step("Die IFC Daten müssen das {schema} Schema benutzen")
117
def step_impl(context, schema):
12-
try:
13-
context.execute_steps(
14-
"* IFC data must use the {schema} schema".format(schema=schema)
15-
)
16-
except Exception:
17-
assert_schema(schema, context.schema)
18-
# TODO translate error
19-
# "Wir haben ein Schema {} erwartet, aber die Daten sind Schema (}"
8+
switch_locale(context.localedir, "de")
9+
assert_schema(context, schema)
Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
from behave import step
22

3-
from utils import assert_schema
4-
3+
from ifcdata_methods import assert_schema
4+
from utils import switch_locale
55

66
@step("Les données IFC doivent utiliser le schéma {schema}")
77
def step_impl(context, schema):
8-
try:
9-
context.execute_steps(
10-
"* IFC data must use the {schema} schema".format(schema=schema)
11-
)
12-
except Exception:
13-
assert_schema(schema, context.schema)
8+
switch_locale(context.localedir, "fr")
9+
assert_schema(context, schema)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from utils import IfcFile
2+
3+
4+
def assert_schema(context, target_schema):
5+
real_schema = IfcFile.get().schema
6+
assert real_schema == target_schema, (
7+
_("We expected a schema of {} but instead got {}")
8+
.format(target_schema, real_schema)
9+
)

src/ifcbimtester/bimtester/features/steps/utils.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,11 @@ def assert_pset(element, pset_name, prop_name=None, value=None):
8080
)
8181

8282

83-
def assert_schema(real_schema, target_schema):
84-
assert real_schema == target_schema, (
85-
"We expected a schema of {} but instead got {}"
86-
.format(target_schema, real_schema)
83+
def switch_locale(locale_dir, locale_id="en"):
84+
from gettext import translation
85+
newlang = translation(
86+
"messages",
87+
localedir=locale_dir,
88+
languages=[locale_id]
8789
)
90+
newlang.install()
556 Bytes
Binary file not shown.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# German translations for PROJECT.
2+
# Copyright (C) 2020 ORGANIZATION
3+
# This file is distributed under the same license as the PROJECT project.
4+
# FIRST AUTHOR <EMAIL@ADDRESS>, 2020.
5+
#
6+
msgid ""
7+
msgstr ""
8+
"Project-Id-Version: PROJECT VERSION\n"
9+
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
10+
"POT-Creation-Date: 2020-12-17 15:14+0100\n"
11+
"PO-Revision-Date: 2020-12-18 06:11+0100\n"
12+
"Last-Translator: \n"
13+
"Language: de\n"
14+
"Language-Team: de <LL@li.org>\n"
15+
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
16+
"MIME-Version: 1.0\n"
17+
"Content-Type: text/plain; charset=utf-8\n"
18+
"Content-Transfer-Encoding: 8bit\n"
19+
"Generated-By: Babel 2.6.0\n"
20+
"X-Generator: Poedit 2.2.1\n"
21+
22+
#: features/steps/ifcdata_methods.py:7
23+
msgid "We expected a schema of {} but instead got {}"
24+
msgstr "Wir haben das Schema {} erwartet, aber die Daten nutzen das Schema {}"
532 Bytes
Binary file not shown.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# German translations for PROJECT.
2+
# Copyright (C) 2020 ORGANIZATION
3+
# This file is distributed under the same license as the PROJECT project.
4+
# FIRST AUTHOR <EMAIL@ADDRESS>, 2020.
5+
#
6+
msgid ""
7+
msgstr ""
8+
"Project-Id-Version: PROJECT VERSION\n"
9+
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
10+
"POT-Creation-Date: 2020-12-17 15:14+0100\n"
11+
"PO-Revision-Date: 2020-12-18 06:12+0100\n"
12+
"Last-Translator: \n"
13+
"Language: en\n"
14+
"Language-Team: en <LL@li.org>\n"
15+
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
16+
"MIME-Version: 1.0\n"
17+
"Content-Type: text/plain; charset=utf-8\n"
18+
"Content-Transfer-Encoding: 8bit\n"
19+
"Generated-By: Babel 2.6.0\n"
20+
"X-Generator: Poedit 2.2.1\n"
21+
22+
#: features/steps/ifcdata_methods.py:7
23+
msgid "We expected a schema of {} but instead got {}"
24+
msgstr "We expected a schema of {} but instead got {}"
415 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)