From 71bf6a4156319ef98cfee944a0ebd305310a8dae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=BA=90=E6=96=87=E9=9B=A8?= <41315874+fumiama@users.noreply.github.com> Date: Sat, 15 Apr 2023 21:45:01 +0800 Subject: [PATCH] feat: link zh_TW.json to zh_HK.json & zh_SG.json (#64) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * optimize: 精简未用到的配置项并在特征提取初步引入mps * add cmd argument: --noautoopen * fix: i18n * fix * fix * add genlocale workflow * add unitest * fix * fix * fix * 优化笔记本 * reintroduce Push changes * disable genlocale on non-main branch * 将笔记本checkout改为stable * 优化代码结构 * make lint happy * make lint happy * 优化 * 优化 * 优化 * fix path on windows okey pack * fix * fix * revert * revert * revert * fix: extract locale regex * feat: link zh_TW.json to zh_HK.json & zh_SG.json * fix #50: set default language to en_US --- locale/locale_diff.py | 2 ++ locale/zh_HK.json | 1 + locale/zh_SG.json | 1 + webui_locale.py | 3 +++ 4 files changed, 7 insertions(+) create mode 120000 locale/zh_HK.json create mode 120000 locale/zh_SG.json diff --git a/locale/locale_diff.py b/locale/locale_diff.py index fba8025..b2f6af8 100644 --- a/locale/locale_diff.py +++ b/locale/locale_diff.py @@ -5,6 +5,8 @@ from collections import OrderedDict standard_file = "zh_CN.json" # Define the list of supported languages +# zh_HK.json and zh_SG.json is not included in the list +# because they are symbolinks to zh_TW.json languages = ["zh_TW.json", "ja_JP.json", "en_US.json"] # Load the standard file diff --git a/locale/zh_HK.json b/locale/zh_HK.json new file mode 120000 index 0000000..2e019ea --- /dev/null +++ b/locale/zh_HK.json @@ -0,0 +1 @@ +zh_TW.json \ No newline at end of file diff --git a/locale/zh_SG.json b/locale/zh_SG.json new file mode 120000 index 0000000..2e019ea --- /dev/null +++ b/locale/zh_SG.json @@ -0,0 +1 @@ +zh_TW.json \ No newline at end of file diff --git a/webui_locale.py b/webui_locale.py index 5ec47e2..bb9e585 100644 --- a/webui_locale.py +++ b/webui_locale.py @@ -1,5 +1,6 @@ import locale import json +import os def load_language_list(language): @@ -14,6 +15,8 @@ class I18nAuto: language = "auto" if language == "auto": language = locale.getdefaultlocale()[0] + if not os.path.exists(f"./locale/{language}.json"): + language = "en_US" self.language = language print("Use Language:", language) self.language_map = load_language_list(language)