mirror of
https://github.com/RVC-Boss/GPT-SoVITS.git
synced 2025-10-07 23:48:48 +08:00
32 lines
1.0 KiB
Python
32 lines
1.0 KiB
Python
import json
|
|
import locale
|
|
import os
|
|
|
|
# Get the directory where the script file is located
|
|
script_dir = os.path.dirname(os.path.abspath(__file__))
|
|
# Change the current working directory to the directory where the script is located
|
|
os.chdir(os.path.join(script_dir,'../../'))
|
|
|
|
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))
|
|
if not os.path.exists(f"./i18n/locale/{language}.json"):
|
|
language = "en_US"
|
|
self.language = language
|
|
self.language_map = load_language_list(language)
|
|
|
|
def __call__(self, key):
|
|
return self.language_map.get(key, key)
|
|
|
|
def __repr__(self):
|
|
return "Use Language: " + self.language
|