From 403ca6427271a246fab2531f988d99ec299b9038 Mon Sep 17 00:00:00 2001 From: Wojtek Kosior Date: Sat, 12 Feb 2022 13:08:53 +0100 Subject: expose the entire translation object instead of just its gettext method --- src/hydrilla/builder/build.py | 2 +- src/hydrilla/locales/en_US/LC_MESSAGES/hydrilla_builder.po | 9 +++++---- src/hydrilla/util/__init__.py | 2 +- src/hydrilla/util/_util.py | 10 ++++------ 4 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/hydrilla/builder/build.py b/src/hydrilla/builder/build.py index 8d25b19..ae4be47 100644 --- a/src/hydrilla/builder/build.py +++ b/src/hydrilla/builder/build.py @@ -36,7 +36,7 @@ import click from .. import util -_ = util.get_gettext('hydrilla_builder') +_ = util.translation('hydrilla_builder').gettext index_validator = util.validator_for('package_source-1.schema.json') diff --git a/src/hydrilla/locales/en_US/LC_MESSAGES/hydrilla_builder.po b/src/hydrilla/locales/en_US/LC_MESSAGES/hydrilla_builder.po index 2d351d6..f42b775 100644 --- a/src/hydrilla/locales/en_US/LC_MESSAGES/hydrilla_builder.po +++ b/src/hydrilla/locales/en_US/LC_MESSAGES/hydrilla_builder.po @@ -7,8 +7,8 @@ msgid "" msgstr "" "Project-Id-Version: hydrilla.builder 0.1.dev16+g4e46d7f.d20220211\n" "Report-Msgid-Bugs-To: koszko@koszko.org\n" -"POT-Creation-Date: 2022-02-12 10:49+0100\n" -"PO-Revision-Date: 2022-02-12\n" +"POT-Creation-Date: 2022-02-12 13:07+0100\n" +"PO-Revision-Date: 2022-02-12 00:00+0000\n" "Last-Translator: Wojtek Kosior \n" "Language: en_US\n" "Language-Team: en_US \n" @@ -59,9 +59,10 @@ msgstr "Destination directory to write built package files to." #: src/hydrilla/builder/build.py:394 msgid "build_package_from_srcdir_to_dstdir" msgstr "" -"Build Hydrilla package from `scrdir` and write the resulting files " -"under `dstdir`." +"Build Hydrilla package from `scrdir` and write the resulting files under " +"`dstdir`." #: src/hydrilla/util/_util.py:76 msgid "bad_comment" msgstr "bad comment" + diff --git a/src/hydrilla/util/__init__.py b/src/hydrilla/util/__init__.py index 3a13831..fadb81c 100644 --- a/src/hydrilla/util/__init__.py +++ b/src/hydrilla/util/__init__.py @@ -5,4 +5,4 @@ # Available under the terms of Creative Commons Zero v1.0 Universal. from ._util import strip_json_comments, normalize_version, parse_version, \ - version_string, validator_for, get_gettext + version_string, validator_for, translation diff --git a/src/hydrilla/util/_util.py b/src/hydrilla/util/_util.py index c7e9f47..f9fed5d 100644 --- a/src/hydrilla/util/_util.py +++ b/src/hydrilla/util/_util.py @@ -130,9 +130,9 @@ def validator_for(schema_filename: str) -> Draft7Validator: return Draft7Validator(resolver.resolve(schema_filename)[1], resolver=resolver) -def get_gettext(domain: str, lang: Optional[str]=None): +def translation(domain: str, lang: Optional[str]=None): """ - Configure translation and return its gettext() function. + Configure translation and return the object that represents it. If `lang` is set, look for translations for `lang`. Otherwise, try to determine system's default language and use that. @@ -146,12 +146,10 @@ def get_gettext(domain: str, lang: Optional[str]=None): except: lang = locale.getdefaultlocale()[0] or 'C' - translation = gettext.translation( + return gettext.translation( domain, localedir=(here.parent / 'locales'), languages=[lang, 'en_US'] ) - return translation.gettext - -_ = get_gettext('hydrilla_builder') +_ = translation('hydrilla_builder').gettext -- cgit v1.2.3