2023-04-12 10:48:39 +08:00
|
|
|
import json
|
|
|
|
import re
|
|
|
|
|
|
|
|
# Define regular expression patterns
|
2023-04-15 21:27:03 +08:00
|
|
|
pattern = r"""i18n\([\s\n\t]*(["'][^"']+["'])[\s\n\t]*\)"""
|
2023-04-12 10:48:39 +08:00
|
|
|
|
|
|
|
# Initialize the dictionary to store key-value pairs
|
|
|
|
data = {}
|
|
|
|
|
2023-04-15 19:44:24 +08:00
|
|
|
|
2023-04-12 16:53:50 +08:00
|
|
|
def process(fn: str):
|
|
|
|
global data
|
2023-04-15 19:44:24 +08:00
|
|
|
with open(fn, "r", encoding="utf-8") as f:
|
2023-04-12 16:53:50 +08:00
|
|
|
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-15 19:44:24 +08:00
|
|
|
|
2023-04-12 16:53:50 +08:00
|
|
|
print("processing infer-web.py")
|
2023-04-15 19:44:24 +08:00
|
|
|
process("infer-web.py")
|
2023-04-12 16:53:50 +08:00
|
|
|
|
|
|
|
print("processing gui.py")
|
2023-04-15 19:44:24 +08:00
|
|
|
process("gui.py")
|
2023-04-12 10:48:39 +08:00
|
|
|
|
|
|
|
# Save as a JSON file
|
2023-04-16 14:29:01 +08:00
|
|
|
with open("./i18n/zh_CN.json", "w", encoding="utf-8") as f:
|
2023-04-12 10:48:39 +08:00
|
|
|
json.dump(data, f, ensure_ascii=False, indent=4)
|
2023-04-17 20:49:29 +08:00
|
|
|
f.write("\n")
|