2023-04-12 10:48:39 +08:00
|
|
|
import json
|
|
|
|
import re
|
|
|
|
|
|
|
|
# Define regular expression patterns
|
2023-04-12 16:53:50 +08:00
|
|
|
pattern = r"""i18n\((["'][^"']+["'])\)"""
|
2023-04-12 10:48:39 +08:00
|
|
|
|
|
|
|
# Initialize the dictionary to store key-value pairs
|
|
|
|
data = {}
|
|
|
|
|
2023-04-12 16:53:50 +08:00
|
|
|
def process(fn: str):
|
|
|
|
global data
|
|
|
|
with open(fn, 'r', encoding='utf-8') as f:
|
|
|
|
contents = f.read()
|
|
|
|
matches = re.findall(pattern, contents)
|
|
|
|
for key in matches:
|
|
|
|
key = eval(key)
|
|
|
|
print("extract:", key)
|
|
|
|
data[key] = key
|
2023-04-12 10:48:39 +08:00
|
|
|
|
2023-04-12 16:53:50 +08:00
|
|
|
print("processing infer-web.py")
|
|
|
|
process('infer-web.py')
|
|
|
|
|
|
|
|
print("processing gui.py")
|
|
|
|
process('gui.py')
|
2023-04-12 10:48:39 +08:00
|
|
|
|
|
|
|
# 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)
|