Added handling of system locale

This commit is contained in:
2026-11-21 11:50:47 +01:00
parent 12b471f641
commit 16d17ac6df
7 changed files with 798 additions and 29 deletions
+29 -10
View File
@@ -10,20 +10,38 @@ import ki18n
ki18n_module = importlib.import_module("ki18n.ki18n")
# The README shows ``from ki18n import Ki18n, i18n``. The package's
# ``__init__.py`` is currently empty, so these cases are expected to fail until
# the package re-exports the names (the demo scripts take the detour
# ``from ki18n.ki18n import ...``). Remove the xfail marker once it does.
# @pytest.mark.xfail(strict=True, raises=ImportError,
# reason="ki18n/__init__.py does not re-export the public names")
@pytest.mark.parametrize(
("name", "target"),
[("Ki18n", "Ki18n"), ("i18n", "i18n"), ("I18n", "Ki18n")],
[
("Ki18n", "Ki18n"),
("i18n", "i18n"),
("I18n", "Ki18n"),
("SystemLocale", "SystemLocale"),
],
)
def test_package_exports_documented_names(name, target):
namespace: dict = {}
exec(f"from ki18n import {name}", namespace)
assert namespace[name] is getattr(ki18n_module, target)
assert getattr(ki18n, name) is getattr(ki18n_module, target)
def test_readme_import_statement_works():
from ki18n import Ki18n, i18n
assert Ki18n is ki18n_module.Ki18n
assert i18n is ki18n_module.i18n
def test_all_lists_the_public_names():
assert set(ki18n.__all__) == {"Ki18n", "i18n", "I18n", "SystemLocale"}
def test_package_attribute_ki18n_is_still_the_submodule():
# Re-exporting names must not shadow ``ki18n.ki18n`` (the module).
assert ki18n.ki18n is ki18n_module
def test_importing_the_package_does_not_import_textual_dialogs():
assert not hasattr(ki18n, "HelpScreen")
assert not hasattr(ki18n, "LanguageSelectScreen")
def test_py_typed_marker_is_shipped():
@@ -36,6 +54,7 @@ def test_py_typed_marker_is_shipped():
"get_language",
"get_default_language",
"get_available_languages",
"get_locale",
"set_language",
"t",
"p",