MCPcopy
hub / github.com/kvcache-ai/ktransformers / get_lang

Function get_lang

kt-kernel/python/cli/i18n.py:1260–1303  ·  view source on GitHub ↗

Detect the current language setting. Priority: 1. KT_LANG environment variable 2. Config file general.language setting 3. LANG environment variable (if config is "auto") 4. Default to English Returns: Language code: "zh" for Chinese, "en" for English

()

Source from the content-addressed store, hash-verified

1258
1259
1260def get_lang() -> str:
1261 """
1262 Detect the current language setting.
1263
1264 Priority:
1265 1. KT_LANG environment variable
1266 2. Config file general.language setting
1267 3. LANG environment variable (if config is "auto")
1268 4. Default to English
1269
1270 Returns:
1271 Language code: "zh" for Chinese, "en" for English
1272 """
1273 global _lang_cache
1274
1275 # 1. Check KT_LANG environment variable (highest priority)
1276 kt_lang = os.environ.get("KT_LANG", "").lower()
1277 if kt_lang:
1278 return "zh" if kt_lang.startswith("zh") else "en"
1279
1280 # 2. Return cached value if available (avoids I/O on every call)
1281 if _lang_cache is not None:
1282 return _lang_cache
1283
1284 # 3. Check config file setting (with caching)
1285 # Import here to avoid circular imports
1286 from kt_kernel.cli.config.settings import get_settings
1287
1288 try:
1289 settings = get_settings()
1290 config_lang = settings.get("general.language", "auto")
1291 if config_lang and config_lang != "auto":
1292 lang = "zh" if config_lang.lower().startswith("zh") else "en"
1293 _lang_cache = lang
1294 return lang
1295 except Exception:
1296 # If settings fail to load, continue with system detection
1297 pass
1298
1299 # 4. Check system LANG environment variable
1300 system_lang = os.environ.get("LANG", "").lower()
1301 lang = "zh" if system_lang.startswith("zh") else "en"
1302 _lang_cache = lang
1303 return lang
1304
1305
1306def t(msg_key: str, **kwargs: Any) -> str:

Callers 6

_get_app_helpFunction · 0.90
_get_helpFunction · 0.90
tFunction · 0.85

Calls 2

get_settingsFunction · 0.90
getMethod · 0.45

Tested by

no test coverage detected