mirror of
https://github.com/RVC-Project/Retrieval-based-Voice-Conversion-WebUI.git
synced 2024-12-29 19:15:04 +08:00
replace i18n
This commit is contained in:
parent
b83939ba04
commit
b562b12cb9
2
i18n.py
2
i18n.py
@ -4,7 +4,7 @@ import os
|
||||
|
||||
|
||||
def load_language_list(language):
|
||||
with open(f"./lib/i18n/{language}.json", "r", encoding="utf-8") as f:
|
||||
with open(f"./i18n/locale/{language}.json", "r", encoding="utf-8") as f:
|
||||
language_list = json.load(f)
|
||||
return language_list
|
||||
|
||||
|
28
i18n/i18n.py
Normal file
28
i18n/i18n.py
Normal file
@ -0,0 +1,28 @@
|
||||
import locale
|
||||
import json
|
||||
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))
|
||||
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)
|
||||
|
||||
def print(self):
|
||||
print("Use Language:", self.language)
|
@ -6,7 +6,7 @@ from collections import OrderedDict
|
||||
standard_file = "zh_CN.json"
|
||||
|
||||
# Find all JSON files in the directory
|
||||
dir_path = "./"
|
||||
dir_path = "i18n/locale"
|
||||
languages = [
|
||||
f for f in os.listdir(dir_path) if f.endswith(".json") and f != standard_file
|
||||
]
|
Loading…
Reference in New Issue
Block a user