35 lines
1.3 KiB
Python
35 lines
1.3 KiB
Python
"""Show only the non-trivial changes: undo the mechanical t() wrapping on the new text, then diff against the old."""
|
|
import difflib, re, sys
|
|
from pathlib import Path
|
|
|
|
BASE = Path(sys.argv[1])
|
|
WEB = Path('C:/wechat_rpa/admin-web/apps/web-antd')
|
|
only = sys.argv[2:]
|
|
|
|
|
|
def neutral(text):
|
|
text = text.replace('\r\n', '\n')
|
|
lit = r"'((?:[^'\\\n]|\\.)*)'"
|
|
text = re.sub(r"\{\{\s*t\(" + lit + r"\)\s*\}\}", r"\1", text)
|
|
text = re.sub(r":([\w-]+)=\"t\(" + lit + r"\)\"", r'\1="\2"', text)
|
|
text = re.sub(r"\bt\(" + lit + r"\)", r"'\1'", text)
|
|
text = text.replace("import { t } from '#/locales/t';\n", '')
|
|
return text
|
|
|
|
|
|
for old_path in sorted(BASE.rglob('*')):
|
|
if not old_path.is_file() or old_path.name == 'REMOVED.txt':
|
|
continue
|
|
rel = old_path.relative_to(BASE).as_posix()
|
|
if only and not any(o in rel for o in only):
|
|
continue
|
|
old = old_path.read_text(encoding='utf-8').replace('\r\n', '\n')
|
|
new = neutral((WEB / rel).read_text(encoding='utf-8'))
|
|
diff = [l for l in difflib.unified_diff(old.split('\n'), new.split('\n'), lineterm='', n=0)
|
|
if not l.startswith(('---', '+++'))]
|
|
changed = [l for l in diff if l.startswith(('+', '-'))]
|
|
if changed:
|
|
print(f'===== {rel} ({len(changed)} lines)')
|
|
for l in diff:
|
|
print(l[:220])
|