RCV/extract_locale.py
源文雨 aeec244087
fix: extract locale regex (#63)
* optimize: 精简未用到的配置项并在特征提取初步引入mps

* add cmd argument: --noautoopen

* fix: i18n

* fix

* fix

* add genlocale workflow

* add unitest

* fix

* fix

* fix

* 优化笔记本

* reintroduce Push changes

* disable genlocale on non-main branch

* 将笔记本checkout改为stable

* 优化代码结构

* make lint happy

* make lint happy

* 优化

* 优化

* 优化

* fix path on windows okey pack

* fix

* fix

* revert

* revert

* revert

* fix: extract locale regex
2023-04-15 13:27:03 +00:00

31 lines
709 B
Python

import json
import re
# Define regular expression patterns
pattern = r"""i18n\([\s\n\t]*(["'][^"']+["'])[\s\n\t]*\)"""
# Initialize the dictionary to store key-value pairs
data = {}
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
print("processing infer-web.py")
process("infer-web.py")
print("processing gui.py")
process("gui.py")
# 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)