Retrieval-based-Voice-Conve.../webui_locale.py
源文雨 71bf6a4156
feat: link zh_TW.json to zh_HK.json & zh_SG.json (#64)
* 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
2023-04-15 13:45:01 +00:00

26 lines
695 B
Python

import locale
import json
import os
def load_language_list(language):
with open(f"./locale/{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 is None:
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)
def __call__(self, key):
return self.language_map[key]