SPB Git

Repository Public

extract_keys.py 1.5 KB 29 lines python

1#!/usr/bin/env python32"""Lists the localization keys used by the FeatureAudit sources (one JSON string per line).34Keys are the first string literal of every L("…") call, plus the literals returned by the5`titleKey` / `messageKey` properties and the icon-set words (looked up dynamically)."""6import json, pathlib, re, sys78root = pathlib.Path(__file__).resolve().parent.parent / "Sources" / "FeatureAudit"9call = re.compile(r'\bL\(\s*"((?:[^"\\]|\\.)*)"')10literal = re.compile(r'"((?:[^"\\]|\\.)*)"')11keys = set()12for path in sorted(root.rglob("*.swift")):13    text = path.read_text()14    for m in call.finditer(text):15        keys.add(m.group(1))16    # dynamic keys: `case …: "Key"` arms inside titleKey / messageKey / iconSetTitle17    for block in re.finditer(r'(?:titleKey|messageKey): String \{\n\s*switch self \{(.*?)\n\s*\}\n|let key: String = switch rest \{(.*?)\n        \}', text, re.S):18        body = block.group(1) or block.group(2)19        for line in body.splitlines():20            if ":" not in line or "case" not in line: continue21            arm = line.split(":", 1)[1]22            for m in literal.finditer(arm):23                keys.add(m.group(1))24    # pane and action titles registered through the local helpers in AuditFeature.swift25    for m in re.finditer(r'\b(?:pane|action)\([^,]+,\s*"((?:[^"\\]|\\.)*)"', text):26        keys.add(m.group(1))27for k in sorted(keys):28    print(json.dumps(bytes(k, "utf-8").decode("unicode_escape").encode("latin-1").decode("utf-8") if "\\" in k else k, ensure_ascii=False))29
Files main
Menu

Theme