From c18f0f6f366b4f1e100f486eae2565861731095a Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Thu, 13 Nov 2025 14:33:34 +1100 Subject: [PATCH] Make locales dynamically detected from the locales dir rather than hardcoded --- CHANGELOG.md | 5 +++++ bouquin/strings.py | 13 +++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1ee3899..cde5185 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +# 0.2.1.9 + + * Fix a few small matters identified with tests + * Make locales dynamically detected from the locales dir rather than hardcoded + # 0.2.1.8 * Translate all strings, add French, add locale choice in settings diff --git a/bouquin/strings.py b/bouquin/strings.py index 6a321b8..322739c 100644 --- a/bouquin/strings.py +++ b/bouquin/strings.py @@ -1,19 +1,24 @@ from importlib.resources import files import json -_AVAILABLE = ("en", "fr") +# Get list of locales +root = files("bouquin") / "locales" +_AVAILABLE = tuple( + entry.stem + for entry in root.iterdir() + if entry.is_file() and entry.suffix == ".json" +) + _DEFAULT = "en" strings = {} translations = {} - def load_strings(current_locale: str) -> None: global strings, translations translations = {} - # read json resources from bouquin/locales/*.json - root = files("bouquin") / "locales" + # read in the locales json for loc in _AVAILABLE: data = (root / f"{loc}.json").read_text(encoding="utf-8") translations[loc] = json.loads(data)