1
0
mirror of synced 2024-11-15 03:07:40 +01:00
Retrieval-based-Voice-Conve.../extract_locale.py
唐澤 克幸 72d37119de
add localization(添加本地化) (#35)
* add i18n

* Add gui.py as target

* update

* Update extract_locale.py
2023-04-12 10:48:39 +08:00

29 lines
763 B
Python

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)