You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
129 lines
5.3 KiB
129 lines
5.3 KiB
# -*- coding: utf-8 -*-
|
|
import re
|
|
import os
|
|
from collections import defaultdict
|
|
|
|
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
|
|
proc_calls = re.compile(r'(?:getProcedureData|execProduceData)\("([^"]+)"')
|
|
java_throw_rt = re.compile(r'throw new RuntimeException\("([^"]+)"')
|
|
java_throw_cr = re.compile(r'throw new CustomerRuntimeException\(\d+,\s*"([^"]+)"')
|
|
java_put_msg = re.compile(r'put\("(?:errorMsg|resultMsg|message|msg)"\s*,\s*"([^"]+)"')
|
|
|
|
menus = []
|
|
labels_print = []
|
|
frontend = defaultdict(set)
|
|
backend_msgs = defaultdict(set)
|
|
proc_list = set()
|
|
proc_handlers = set()
|
|
|
|
# master.ftl
|
|
master_path = os.path.join(ROOT, 'src/main/resources/templates/master.ftl')
|
|
with open(master_path, encoding='utf-8') as f:
|
|
content = f.read()
|
|
for m in re.finditer(r'<a[^>]*>([^<]+)</a>', content):
|
|
text = m.group(1).strip()
|
|
if text:
|
|
menus.append(text)
|
|
for m in re.finditer(r'label="([^"]+)"', content):
|
|
frontend['表单标签'].add(f'master.ftl: {m.group(1)}')
|
|
for m in re.finditer(r"dialog\('setTitle',\s*'([^']+)'", content):
|
|
frontend['弹窗标题'].add(m.group(1))
|
|
for m in re.finditer(r"layer\.alert\('([^']+)'", content):
|
|
frontend['layer提示'].add(m.group(1))
|
|
for m in re.finditer(r"messager\.alert\('[^']*','([^']+)'", content):
|
|
frontend['messager提示'].add(m.group(1))
|
|
for m in re.finditer(r"messager\.confirm\('[^']*','([^']+)'", content):
|
|
frontend['确认框'].add(m.group(1))
|
|
|
|
# Java
|
|
for dirpath, _, files in os.walk(os.path.join(ROOT, 'src/main/java')):
|
|
for fn in files:
|
|
if not fn.endswith('.java'):
|
|
continue
|
|
path = os.path.join(dirpath, fn)
|
|
rel = os.path.relpath(path, ROOT).replace('\\', '/')
|
|
with open(path, encoding='utf-8', errors='ignore') as f:
|
|
text = f.read()
|
|
for m in proc_calls.finditer(text):
|
|
proc_list.add(m.group(1))
|
|
if 'result_msg' in text or 'result_code' in text:
|
|
proc_handlers.add(rel)
|
|
for m in java_throw_rt.finditer(text):
|
|
backend_msgs[m.group(1)].add(rel)
|
|
for m in java_throw_cr.finditer(text):
|
|
backend_msgs[m.group(1)].add(rel)
|
|
for m in java_put_msg.finditer(text):
|
|
backend_msgs[m.group(1)].add(rel)
|
|
|
|
# Templates
|
|
for dirpath, _, files in os.walk(os.path.join(ROOT, 'src/main/resources/templates')):
|
|
for fn in files:
|
|
if not fn.endswith('.ftl'):
|
|
continue
|
|
path = os.path.join(dirpath, fn)
|
|
rel = os.path.relpath(path, ROOT).replace('\\', '/')
|
|
with open(path, encoding='utf-8', errors='ignore') as f:
|
|
text = f.read()
|
|
|
|
if '/print/' in rel.replace('\\', '/'):
|
|
for m in re.finditer(r'ADD_PRINT_TEXT\([^,]+,[^,]+,[^,]+,[^,]+,"([^"]+)"', text):
|
|
s = m.group(1)
|
|
if '${' not in s and not s.startswith('+'):
|
|
labels_print.append((rel, s))
|
|
for m in re.finditer(r'"([\u4e00-\u9fff]+)"', text):
|
|
labels_print.append((rel, m.group(1)))
|
|
|
|
for m in re.finditer(r'field:[^>]+>([^<]+)</th>', text):
|
|
col = m.group(1).strip()
|
|
if col:
|
|
frontend['表格列名'].add(f'{rel}: {col}')
|
|
for m in re.finditer(r'label="([^"]*)"', text):
|
|
if re.search(r'[\u4e00-\u9fff]', m.group(1)):
|
|
frontend['表单标签'].add(f'{rel}: {m.group(1)}')
|
|
for m in re.finditer(r"title:\s*'([^']+)'", text):
|
|
if re.search(r'[\u4e00-\u9fff]', m.group(1)) or m.group(1) in ('提示', 'Error', 'Confirm', 'Info'):
|
|
frontend['弹窗标题'].add(f'{rel}: {m.group(1)}')
|
|
for m in re.finditer(r"layer\.(?:alert|msg)\('([^']+)'", text):
|
|
frontend['layer提示'].add(f'{rel}: {m.group(1)}')
|
|
for m in re.finditer(r"messager\.(?:alert|confirm)\('[^']*',\s*'([^']+)'", text):
|
|
frontend['messager提示'].add(f'{rel}: {m.group(1)}')
|
|
for m in re.finditer(r'<h[1-4][^>]*>([^<]+)</h[1-4]>', text):
|
|
t = m.group(1).strip()
|
|
if re.search(r'[\u4e00-\u9fff]', t):
|
|
frontend['页面标题'].add(f'{rel}: {t}')
|
|
for m in re.finditer(r'<button[^>]*>([^<]+)</button>', text):
|
|
t = m.group(1).strip()
|
|
if re.search(r'[\u4e00-\u9fff]', t):
|
|
frontend['按钮'].add(f'{rel}: {t}')
|
|
|
|
# Output summary
|
|
out = []
|
|
out.append(f'Menus: {len(menus)}')
|
|
out.append(f'Procedures: {len(proc_list)}')
|
|
out.append(f'Backend messages: {len(backend_msgs)}')
|
|
out.append(f'Print labels: {len(labels_print)}')
|
|
for k, v in sorted(frontend.items()):
|
|
out.append(f'Frontend {k}: {len(v)}')
|
|
|
|
print('\n'.join(out))
|
|
print('\n=== PROCEDURES ===')
|
|
for p in sorted(proc_list):
|
|
print(p)
|
|
print('\n=== PROC HANDLERS ===')
|
|
for p in sorted(proc_handlers):
|
|
print(p)
|
|
|
|
# Write JSON for doc generation
|
|
import json
|
|
data = {
|
|
'menus': menus,
|
|
'procedures': sorted(proc_list),
|
|
'procedure_handlers': sorted(proc_handlers),
|
|
'backend_messages': {k: sorted(v) for k, v in sorted(backend_msgs.items())},
|
|
'frontend': {k: sorted(v) for k, v in sorted(frontend.items())},
|
|
'print_labels': labels_print,
|
|
}
|
|
with open(os.path.join(ROOT, 'scripts', 'i18n_extract.json'), 'w', encoding='utf-8') as f:
|
|
json.dump(data, f, ensure_ascii=False, indent=2)
|
|
print('\nWrote scripts/i18n_extract.json')
|