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

29 lines
822 B
Python
Raw Normal View History

import locale
import json
import os
def load_language_list(language):
2023-07-24 08:19:53 +02:00
with open(f"./lib/i18n/{language}.json", "r", encoding="utf-8") as f:
language_list = json.load(f)
return language_list
class I18nAuto:
def __init__(self, language=None):
2023-04-25 04:51:20 +02:00
if language in ["Auto", None]:
language = locale.getdefaultlocale()[
0
] # getlocale can't identify the system's language ((None, None))
2023-07-24 08:19:53 +02:00
if not os.path.exists(f"./lib/i18n/{language}.json"):
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)
2023-05-21 05:10:07 +02:00
def print(self):
print("Use Language:", self.language)