diff --git a/i18n.py b/i18n.py index 67c99d4..4e3536b 100644 --- a/i18n.py +++ b/i18n.py @@ -1,31 +1,43 @@ -import locale import json -import os - def load_language_list(language): try: with open(f"./i18n/{language}.json", "r", encoding="utf-8") as f: return json.load(f) except FileNotFoundError: - print(f"Failed to load language file for {language}. Check if the correct .json file exists.") - return {} + raise FileNotFoundError( + f"Failed to load language file for {language}. Check if the correct .json file exists." + ) class I18nAuto: + """ + A class used for internationalization using JSON language files. + + Examples + -------- + >>> i18n = I18nAuto('en_US') + >>> i18n.print() + Using Language: en_US + """ def __init__(self, language=None): - language = language or locale.getdefaultlocale()[0] + from locale import getdefaultlocale + language = language or getdefaultlocale()[0] if not self._language_exists(language): language = "en_US" + self.language_map = load_language_list(language) self.language = language @staticmethod def _language_exists(language): - return os.path.exists(f"./i18n/{language}.json") + from os.path import exists + return exists(f"./i18n/{language}.json") def __call__(self, key): + """Returns the translation of the given key if it exists, else returns the key itself.""" return self.language_map.get(key, key) def print(self): - print(f"Using Language: {self.language}") \ No newline at end of file + """Prints the language currently in use.""" + print(f"Using Language: {self.language}") \ No newline at end of file diff --git a/infer-web.py b/infer-web.py index a4c88ab..a9246bb 100644 --- a/infer-web.py +++ b/infer-web.py @@ -1570,7 +1570,7 @@ with gr.Blocks(theme=gr.themes.Soft(), title='Mangio-RVC-Web 💻') as app: exp_dir1 = gr.Textbox(label=i18n("输入实验名"), value="mi-test") sr2 = gr.Radio( label=i18n("目标采样率"), - choices=["40k", "48k"], + choices=["40k", "48k", "32k"], value="40k", interactive=True, ) @@ -1582,7 +1582,7 @@ with gr.Blocks(theme=gr.themes.Soft(), title='Mangio-RVC-Web 💻') as app: version19 = gr.Radio( label=i18n("版本"), choices=["v1", "v2"], - value="v1", + value="v2", interactive=True, visible=True, )