mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-28 19:27:10 +00:00
bimtester: do not break bimtester if translation files are missing, fixes #1910
This commit is contained in:
@@ -8,8 +8,21 @@ def _(message):
|
|||||||
return message
|
return message
|
||||||
|
|
||||||
|
|
||||||
def switch_locale(locale_dir, locale_id="en"):
|
def switch_locale(locale_dir, locale_id):
|
||||||
global translation
|
global translation
|
||||||
newlang = gettext.translation("messages", localedir=locale_dir, languages=[locale_id])
|
domain = "messages"
|
||||||
newlang.install()
|
# https://docs.python.org/3/library/gettext.html
|
||||||
translation = newlang.gettext
|
mo_file = gettext.find(domain, localedir=locale_dir, languages=[locale_id])
|
||||||
|
if mo_file is not None:
|
||||||
|
print(
|
||||||
|
"Locale will be switched to language '{}'. Translation file found {}"
|
||||||
|
.format(locale_id, mo_file)
|
||||||
|
)
|
||||||
|
newlang = gettext.translation(domain, localedir=locale_dir, languages=[locale_id])
|
||||||
|
newlang.install()
|
||||||
|
translation = newlang.gettext
|
||||||
|
else:
|
||||||
|
print(
|
||||||
|
"Locale can not be switched to '{}'. Translation file (*.mo) not found in {}"
|
||||||
|
.format(locale_id, locale_dir)
|
||||||
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user