-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlocalization.py
More file actions
29 lines (23 loc) · 957 Bytes
/
localization.py
File metadata and controls
29 lines (23 loc) · 957 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# Copyright NGGT.LightKeeper. All Rights Reserved.
import json
from pathlib import Path
BASE_DIR = Path(__file__).resolve().parent
_LOCALES = {}
for file in (BASE_DIR / "locales").glob("*.json"):
lang = file.stem
with open(file, "r", encoding="utf-8") as f:
_LOCALES[lang] = json.load(f)
def translate(lang: str, key: str) -> str:
"""Return translated string for given key and language."""
return str(_LOCALES.get(lang, _LOCALES["en"]).get(key, key))
def get_scramble_chars(lang: str) -> dict:
"""Return character sets used for scramble animations."""
default = _LOCALES.get("en", {})
locale = _LOCALES.get(lang, default)
return {
"upper": locale.get("scramble_upper", default.get("scramble_upper", "")),
"lower": locale.get("scramble_lower", default.get("scramble_lower", "")),
"special": locale.get(
"scramble_special", default.get("scramble_special", "")
),
}