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