USe the system locale if the parameter default_language is not set while instanciating Ki18n

This commit is contained in:
2026-11-22 09:46:04 +01:00
parent 0e8875e878
commit f7825e6789
8 changed files with 420 additions and 37 deletions
+4
View File
@@ -5,6 +5,8 @@ The suite uses [pytest](https://docs.pytest.org/) with
operated through Textual's `Pilot` (clicks and key presses in the headless test
driver `App.run_test`).
`Ki18n.get_locale()` is replaced by a stub returning `None` for every test (autouse fixture in `conftest.py`), so the results do not depend on the machine's locale; `test_locale.py` restores the real implementation, other tests use the `system_locale` fixture.
Every test runs in temporary directories (installed and user resources;
`XDG_DATA_HOME` and `LOCALAPPDATA` are redirected), so real user data is never
read. The `Ki18n` singleton is reset before and after every test.
@@ -33,6 +35,7 @@ Configuration lives in `pyproject.toml` (`[tool.pytest.ini_options]`):
| `test_set_language.py` | `set_language()`, error cases, listeners |
| `test_translate.py` | `t()`: fallback order, formatting |
| `test_plural.py` | `p()`: categories, `#count`/`{count}`, fallbacks |
| `test_default_language.py` | Default language from the system locale (regional fallback, `DEFAULT_LANGUAGE` fallback, explicit language unaffected) |
| `test_help.py` | `get_help()`: regions, user files, English fallback |
| `test_locale.py` | `Ki18n.get_locale()`: POSIX environment, macOS `defaults`, Windows API (all simulated on any host) |
| `test_lazy_handle.py` | Module handle `i18n`, alias names |
@@ -46,6 +49,7 @@ Configuration lives in `pyproject.toml` (`[tool.pytest.ini_options]`):
`env.make()` / `env.remake()`, directories `app_dir`, `user_dir`, `data_home`.
- `installed` - `env` with the example languages `en` and `de` installed, no manager yet.
- `manager` - `installed` plus a constructed `Ki18n` instance.
- `system_locale` - callable that makes `Ki18n.get_locale()` report a locale, e.g. `system_locale("de_AT")`, or `None`.
- `log_warnings` - callable returning the library's WARNING messages so far.
## Known deviations between documentation and code