summaryrefslogtreecommitdiff
path: root/src/hydrilla/util/_util.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/hydrilla/util/_util.py')
-rw-r--r--src/hydrilla/util/_util.py17
1 files changed, 8 insertions, 9 deletions
diff --git a/src/hydrilla/util/_util.py b/src/hydrilla/util/_util.py
index f9fed5d..364945c 100644
--- a/src/hydrilla/util/_util.py
+++ b/src/hydrilla/util/_util.py
@@ -30,7 +30,7 @@ import locale
import gettext
from pathlib import Path
-from typing import Optional
+from typing import Optional, Union
from jsonschema import RefResolver, Draft7Validator
@@ -130,9 +130,11 @@ def validator_for(schema_filename: str) -> Draft7Validator:
return Draft7Validator(resolver.resolve(schema_filename)[1],
resolver=resolver)
-def translation(domain: str, lang: Optional[str]=None):
+def translation(localedir: Union[Path, str], lang: Optional[str]=None) \
+ -> gettext.GNUTranslations:
"""
- Configure translation and return the object that represents it.
+ Configure translations for domain 'messages' and return the object that
+ represents them.
If `lang` is set, look for translations for `lang`. Otherwise, try to
determine system's default language and use that.
@@ -146,10 +148,7 @@ def translation(domain: str, lang: Optional[str]=None):
except:
lang = locale.getdefaultlocale()[0] or 'C'
- return gettext.translation(
- domain,
- localedir=(here.parent / 'locales'),
- languages=[lang, 'en_US']
- )
+ return gettext.translation('messages', localedir=localedir,
+ languages=[lang, 'en_US'])
-_ = translation('hydrilla_builder').gettext
+_ = translation(here.parent / 'builder' / 'locales').gettext