|
import os |
|
import json |
|
import re |
|
|
|
|
|
pattern = r'i18n\((\"{3}.*?\"{3}|\".*?\")\)' |
|
|
|
|
|
with open('ChuanhuChatbot.py', 'r', encoding='utf-8') as f: |
|
contents = f.read() |
|
|
|
|
|
for filename in os.listdir("modules"): |
|
if filename.endswith(".py"): |
|
with open(os.path.join("modules", filename), "r", encoding="utf-8") as f: |
|
contents += f.read() |
|
|
|
|
|
matches = re.findall(pattern, contents, re.DOTALL) |
|
|
|
|
|
data = {match.strip('()"'): '' for match in matches} |
|
|
|
|
|
with open('labels.json', 'w', encoding='utf-8') as f: |
|
json.dump(data, f, ensure_ascii=False, indent=4) |