Move i18n to tools/i18n (#1298)

* move i18n/locale to tools/i18n/locale

* del i18n/locale

* change i18nAuto dir

* Update i18n json
This commit is contained in:
蓝梦实
2024-07-13 11:46:13 +08:00
committed by GitHub
parent ea83174fe0
commit c4272cd1c0
26 changed files with 1894 additions and 4398 deletions

View File

@@ -2,20 +2,19 @@ import json
import locale
import os
I18N_JSON_DIR : os.PathLike = os.path.join(os.path.dirname(os.path.relpath(__file__)), 'locale')
def load_language_list(language):
with open(f"./i18n/locale/{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
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"./i18n/locale/{language}.json"):
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)
@@ -25,3 +24,7 @@ class I18nAuto:
def __repr__(self):
return "Use Language: " + self.language
if __name__ == "__main__":
i18n = I18nAuto(language='en_US')
print(i18n)