Make locales dynamically detected from the locales dir rather than hardcoded
All checks were successful
CI / test (push) Successful in 2m21s
All checks were successful
CI / test (push) Successful in 2m21s
This commit is contained in:
parent
a4e9af4444
commit
c18f0f6f36
2 changed files with 14 additions and 4 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue