1
0
mirror of synced 2024-12-02 19:17:18 +01:00
Retrieval-based-Voice-Conve.../i18n/i18n.py

29 lines
828 B
Python
Raw Normal View History

2023-08-19 12:10:31 +02:00
import json
2023-08-28 09:08:31 +02:00
import locale
2023-08-19 12:10:31 +02:00
import os
def load_language_list(language):
with open(f"./i18n/locale/{language}.json", "r", encoding="utf-8") as f:
language_list = json.load(f)
return language_list
class I18nAuto:
def __init__(self, language=None):
if language in ["Auto", None]:
language = locale.getdefaultlocale()[
0
] # getlocale can't identify the system's language ((None, None))
2023-08-28 14:58:36 +02:00
if not os.path.exists(f"./i18n/locale/{language}.json"):
2023-08-19 12:10:31 +02:00
language = "en_US"
self.language = language
# print("Use Language:", language)
self.language_map = load_language_list(language)
def __call__(self, key):
return self.language_map.get(key, key)
def print(self):
print("Use Language:", self.language)