mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-19 14:41:25 +00:00
bimtester: se gettext for message translation
This commit is contained in:
committed by
Dion Moult
parent
3ae20637d7
commit
85a78a6e48
@@ -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')
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
)
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user