add localization(添加本地化) (#35)

* add i18n

* Add gui.py as target

* update

* Update extract_locale.py
This commit is contained in:
唐澤 克幸
2023-04-12 11:48:39 +09:00
committed by GitHub
parent 8143197b3f
commit 72d37119de
10 changed files with 419 additions and 199 deletions

28
extract_locale.py Normal file
View File

@@ -0,0 +1,28 @@
import json
import re
# Define regular expression patterns
pattern = r'i18n\([^)]*\)'
# Initialize the dictionary to store key-value pairs
data = {}
# Extract labels from infer-webui.py
with open('infer-web.py', 'r', encoding='utf-8') as f:
contents = f.read()
matches = re.findall(pattern, contents)
for match in matches:
key = match.strip('()"')
data[key] = key
# Extract labels from gui.py
with open('gui.py', 'r', encoding='utf-8') as f:
contents = f.read()
matches = re.findall(pattern, contents)
for match in matches:
key = match.strip('()"')
data[key] = key
# Save as a JSON file
with open('./locale/zh_CN.json', 'w', encoding='utf-8') as f:
json.dump(data, f, ensure_ascii=False, indent=4)