diff --git a/GPT_SoVITS/inference_webui.py b/GPT_SoVITS/inference_webui.py index f903b73..39d14dd 100644 --- a/GPT_SoVITS/inference_webui.py +++ b/GPT_SoVITS/inference_webui.py @@ -895,6 +895,7 @@ with gr.Blocks(title="GPT-SoVITS WebUI") as app: # button4.click(cut4, [text_inp], [text_opt]) # button5.click(cut5, [text_inp], [text_opt]) # gr.Markdown(html_center(i18n("后续将支持转音素、手工修改音素、语音合成分步执行。"))) + i18n.translate_blocks(app) if __name__ == '__main__': app.queue().launch(#concurrency_count=511, max_size=1022 diff --git a/GPT_SoVITS/inference_webui_fast.py b/GPT_SoVITS/inference_webui_fast.py index dcc2bcf..3f566ca 100644 --- a/GPT_SoVITS/inference_webui_fast.py +++ b/GPT_SoVITS/inference_webui_fast.py @@ -326,6 +326,8 @@ with gr.Blocks(title="GPT-SoVITS WebUI") as app: cut_text.click(to_cut, [text_inp, _how_to_cut], [text_opt]) gr.Markdown(value=i18n("后续将支持转音素、手工修改音素、语音合成分步执行。")) + i18n.translate_blocks(app) + if __name__ == '__main__': app.queue().launch(#concurrency_count=511, max_size=1022 server_name="0.0.0.0", diff --git a/requirements.txt b/requirements.txt index 6ad9fd0..d032152 100644 --- a/requirements.txt +++ b/requirements.txt @@ -35,6 +35,7 @@ ko_pron opencc; sys_platform != 'linux' opencc==1.1.1; sys_platform == 'linux' python_mecab_ko; sys_platform != 'win32' +gradio-i18n fastapi<0.112.2 x_transformers torchmetrics<=1.5 diff --git a/tools/i18n/i18n.py b/tools/i18n/i18n.py index e256941..b8c19a9 100644 --- a/tools/i18n/i18n.py +++ b/tools/i18n/i18n.py @@ -2,35 +2,60 @@ import json import locale import os -I18N_JSON_DIR : os.PathLike = os.path.join(os.path.dirname(os.path.relpath(__file__)), 'locale') +import gradio_i18n + +I18N_JSON_DIR: os.PathLike = os.path.join( + os.path.dirname(os.path.relpath(__file__)), "locale" +) + def load_language_list(language): - with open(os.path.join(I18N_JSON_DIR, f"{language}.json"), "r", encoding="utf-8") as f: + with open( + os.path.join(I18N_JSON_DIR, f"{language}.json"), "r", encoding="utf-8" + ) as f: language_list = json.load(f) return language_list + def scan_language_list(): language_list = [] for name in os.listdir(I18N_JSON_DIR): - if name.endswith(".json"):language_list.append(name.split('.')[0]) + if name.endswith(".json"): + language_list.append(name.split(".")[0]) 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(os.path.join(I18N_JSON_DIR, f"{language}.json")): - language = "en_US" - self.language = language - self.language_map = load_language_list(language) + if language in ["Auto", None] or not os.path.exists( + os.path.join(I18N_JSON_DIR, f"{language}.json") + ): + self.language = "Auto" + else: + self.language = language + self.language_map = load_language_list(language) def __call__(self, key): - return self.language_map.get(key, key) + if self.language == "Auto": + return gradio_i18n.gettext(key) + else: + return self.language_map.get(key, key) def __repr__(self): return "Use Language: " + self.language + def translate_blocks(self, block): + translation = {} + for lang in scan_language_list(): + short_lang = lang.partition("_")[0] + if short_lang == "zh" and "CN" not in lang: + continue + + translation[short_lang] = load_language_list(lang) + + gradio_i18n.translate_blocks(block, translation) + + if __name__ == "__main__": - i18n = I18nAuto(language='en_US') - print(i18n) \ No newline at end of file + i18n = I18nAuto(language="en_US") + print(i18n) diff --git a/tools/uvr5/webui.py b/tools/uvr5/webui.py index dc6dd02..702617a 100644 --- a/tools/uvr5/webui.py +++ b/tools/uvr5/webui.py @@ -32,12 +32,12 @@ is_share=eval(sys.argv[4]) def html_left(text, label='p'): return f"""