Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

支持动态语言更新界面 #1559

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions GPT_SoVITS/inference_webui.py
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,7 @@ def html_left(text, label='p'):
# 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
Expand Down
2 changes: 2 additions & 0 deletions GPT_SoVITS/inference_webui_fast.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,8 @@ def to_cut(text_inp, how_to_cut):
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",
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@ 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
51 changes: 38 additions & 13 deletions tools/i18n/i18n.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,60 @@
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)
i18n = I18nAuto(language="en_US")
print(i18n)
6 changes: 4 additions & 2 deletions tools/uvr5/webui.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@

def html_left(text, label='p'):
return f"""<div style="text-align: left; margin: 0; padding: 0;">
<{label} style="margin: 0; padding: 0;">{text}</{label}>
<{label} style="margin: 0; padding: 0;">""" + text + f"""</{label}>
</div>"""

def html_center(text, label='p'):
return f"""<div style="text-align: center; margin: 100; padding: 50;">
<{label} style="margin: 0; padding: 0;">{text}</{label}>
<{label} style="margin: 0; padding: 0;">""" + text + f"""</{label}>
</div>"""

def uvr(model_name, inp_root, save_root_vocal, paths, save_root_ins, agg, format0):
Expand Down Expand Up @@ -199,6 +199,8 @@ def uvr(model_name, inp_root, save_root_vocal, paths, save_root_ins, agg, format
[vc_output4],
api_name="uvr_convert",
)

i18n.translate_blocks(app)
app.queue().launch(#concurrency_count=511, max_size=1022
server_name="0.0.0.0",
inbrowser=True,
Expand Down
1 change: 1 addition & 0 deletions webui.py
Original file line number Diff line number Diff line change
Expand Up @@ -1045,6 +1045,7 @@ def change_precision_choices(key): #根据选择的模型修改可选的语言
close_tts.click(change_tts_inference, [bert_pretrained_dir,cnhubert_base_dir,gpu_number_1C,GPT_dropdown,SoVITS_dropdown, batched_infer_enabled], [tts_info,open_tts,close_tts])
version_checkbox.change(switch_version,[version_checkbox],[pretrained_s2G,pretrained_s2D,pretrained_s1,GPT_dropdown,SoVITS_dropdown])
with gr.TabItem(i18n("2-GPT-SoVITS-变声")):gr.Markdown(value=i18n("施工中,请静候佳音"))
i18n.translate_blocks(app)
app.queue().launch(#concurrency_count=511, max_size=1022
server_name="0.0.0.0",
inbrowser=True,
Expand Down