mirror of
https://github.com/RVC-Project/Retrieval-based-Voice-Conversion-WebUI.git
synced 2024-12-29 02:55:05 +08:00
4027928a8e
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
26 lines
744 B
Python
26 lines
744 B
Python
import locale
|
|
import json
|
|
import os
|
|
|
|
|
|
def load_language_list(language):
|
|
with open(f"./i18n/{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))
|
|
if not os.path.exists(f"./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)
|