Revision 33097569
Added by koszko over 1 year ago
src/hydrilla/util/_util.py | ||
---|---|---|
30 | 30 |
import gettext |
31 | 31 |
|
32 | 32 |
from pathlib import Path |
33 |
from typing import Optional |
|
33 |
from typing import Optional, Union
|
|
34 | 34 |
|
35 | 35 |
from jsonschema import RefResolver, Draft7Validator |
36 | 36 |
|
... | ... | |
130 | 130 |
return Draft7Validator(resolver.resolve(schema_filename)[1], |
131 | 131 |
resolver=resolver) |
132 | 132 |
|
133 |
def translation(domain: str, lang: Optional[str]=None): |
|
133 |
def translation(localedir: Union[Path, str], lang: Optional[str]=None) \ |
|
134 |
-> gettext.GNUTranslations: |
|
134 | 135 |
""" |
135 |
Configure translation and return the object that represents it. |
|
136 |
Configure translations for domain 'messages' and return the object that |
|
137 |
represents them. |
|
136 | 138 |
|
137 | 139 |
If `lang` is set, look for translations for `lang`. Otherwise, try to |
138 | 140 |
determine system's default language and use that. |
... | ... | |
146 | 148 |
except: |
147 | 149 |
lang = locale.getdefaultlocale()[0] or 'C' |
148 | 150 |
|
149 |
return gettext.translation( |
|
150 |
domain, |
|
151 |
localedir=(here.parent / 'locales'), |
|
152 |
languages=[lang, 'en_US'] |
|
153 |
) |
|
151 |
return gettext.translation('messages', localedir=localedir, |
|
152 |
languages=[lang, 'en_US']) |
|
154 | 153 |
|
155 |
_ = translation('hydrilla_builder').gettext |
|
154 |
_ = translation(here.parent / 'builder' / 'locales').gettext |
Also available in: Unified diff
move locales under builder/