MCPcopy Index your code
hub / github.com/dataease/SQLBot / load_translation

Function load_translation

backend/apps/swagger/i18n.py:20–40  ·  view source on GitHub ↗

Load translations for the specified language from a JSON file

(lang: str)

Source from the content-addressed store, hash-verified

18
19
20def load_translation(lang: str) -> Dict[str, str]:
21 """Load translations for the specified language from a JSON file"""
22 if lang in _translations_cache:
23 return _translations_cache[lang]
24
25 file_path = LOCALES_DIR / f"{lang}.json"
26 if not file_path.exists():
27 if lang == DEFAULT_LANG:
28 raise FileNotFoundError(f"Default language file not found: {file_path}")
29 # If the non-default language is missing, fall back to the default language
30 return load_translation(DEFAULT_LANG)
31
32 try:
33 with open(file_path, "r", encoding="utf-8") as f:
34 data = json.load(f)
35 if not isinstance(data, dict):
36 raise ValueError(f"Translation file {file_path} must be a JSON object")
37 _translations_cache[lang] = data
38 return data
39 except json.JSONDecodeError as e:
40 raise ValueError(f"Invalid JSON in {file_path}: {e}")
41
42
43# group tags

Callers 1

get_translationFunction · 0.85

Calls 3

openFunction · 0.85
existsMethod · 0.45
loadMethod · 0.45

Tested by

no test coverage detected