optimize UI and user experience
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import locale
|
||||
import os
|
||||
import platform
|
||||
import threading
|
||||
@@ -174,3 +175,25 @@ def split_string_by_punctuations(s):
|
||||
def md5(text):
|
||||
import hashlib
|
||||
return hashlib.md5(text.encode('utf-8')).hexdigest()
|
||||
|
||||
|
||||
def get_system_locale():
|
||||
try:
|
||||
loc = locale.getdefaultlocale()
|
||||
# zh_CN, zh_TW return zh
|
||||
# en_US, en_GB return en
|
||||
language_code = loc[0].split("_")[0]
|
||||
return language_code
|
||||
except Exception as e:
|
||||
return "en"
|
||||
|
||||
|
||||
def load_locales(i18n_dir):
|
||||
_locales = {}
|
||||
for root, dirs, files in os.walk(i18n_dir):
|
||||
for file in files:
|
||||
if file.endswith(".json"):
|
||||
lang = file.split(".")[0]
|
||||
with open(os.path.join(root, file), "r", encoding="utf-8") as f:
|
||||
_locales[lang] = json.loads(f.read())
|
||||
return _locales
|
||||
|
||||
Reference in New Issue
Block a user