1
0
mirror of synced 2024-11-15 03:07:40 +01:00
Retrieval-based-Voice-Conve.../extract_locale.py
唐澤 克幸 6fb458a754
optimize: 优化代码结构 (#66)
* update

* 纠正了多余的内容

* update

* Change the location of the comments (or revert) to improve readability.

* revert

* Update extract_locale.py

* Update i18n.py

* fix HK & SG

---------

Co-authored-by: 源文雨 <41315874+fumiama@users.noreply.github.com>
2023-04-16 06:29:01 +00:00

31 lines
707 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("./i18n/zh_CN.json", "w", encoding="utf-8") as f:
json.dump(data, f, ensure_ascii=False, indent=4)