Files
splinter/tools/check_i18n.py
T
lotherkandClaude Sonnet 5.5 2e7a88c462 usable: opencode-go session header, embedded catalogs, locale fixes, calmer UI, --doctor
- openai transport sends x-opencode-session (opencode-go refused every request
  without it) and a splinter user agent
- the message catalogues are compiled in: an installed binary no longer shows
  raw keys (ui.ready ...); LANG=de_DE now selects German (lang was emptied by an
  overlapping snprintf), pt_BR is matched
- sidebar rewritten (agent, provider/model, usage, goal/plan, last turn);
  idle widgets say nothing; status line shows only what matters
- tool calls shown readable instead of JSON with \u escapes
- providers without their key variable are skipped by pools and refused by -m
  with a clear message; --doctor checks every provider

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-12 03:22:49 +00:00

112 lines
4.1 KiB
Python
Executable File

#!/usr/bin/env python3
"""Every key used in the code must exist in every catalogue.
A UI that is half translated is worse than one that is not translated at all:
the operator cannot tell a missing string from a deliberate one. This walks the
sources for sp_t()/sp_td() keys and compares them with share/locale/*.msg.
"""
import pathlib
import re
import sys
ROOT = pathlib.Path(__file__).resolve().parent.parent
KEY = re.compile(r'sp_td?\(\s*"([^"]+)"')
def used_keys():
keys = set()
for path in list(ROOT.glob("src/*.c")) + list(ROOT.glob("plugins/*/*.c")):
keys.update(KEY.findall(path.read_text(encoding="utf-8", errors="replace")))
return keys
def catalogue(path):
out = {}
for line in path.read_text(encoding="utf-8").splitlines():
line = line.strip()
if not line or line.startswith("#") or "=" not in line:
continue
k, v = line.split("=", 1)
out[k.strip()] = v.strip()
return out
# Anything drawn on the screen must come from a catalogue. These are the calls
# that put text into a curses window; a literal there is a string the operator
# can never translate.
DRAW = re.compile(r'\b(mvwaddstr|mvwaddnstr|mvwprintw|waddstr|wprintw|winsstr)\s*\(')
LITERAL_ARG = re.compile(r',\s*"([^"\\]*(?:\\.[^"\\]*)*)"')
def hardcoded():
bad = []
for path in list(ROOT.glob("src/*.c")):
for no, line in enumerate(path.read_text(encoding="utf-8",
errors="replace").splitlines(), 1):
if not DRAW.search(line) or "sp_t" in line:
continue
m = LITERAL_ARG.search(line)
if m is not None:
bad.append(f"{path.name}:{no}: {m.group(1)!r}")
return bad
# Roles are keys too: add_entry() takes an identifier, the label comes from the
# catalogue. An unknown identifier would ship as untranslated text.
ROLE_CALL = re.compile(r'add_entry\(\s*&?[A-Za-z_>.-]*\s*,\s*"([a-z_]+)"')
ALLOWED_ROLES = {"you", "agent", "thinking", "tool", "error", "shell",
"splinter", "diff"}
def unknown_roles():
bad = []
for path in ROOT.glob("src/*.c"):
for no, line in enumerate(path.read_text(encoding="utf-8",
errors="replace").splitlines(), 1):
for role in ROLE_CALL.findall(line):
if role not in ALLOWED_ROLES:
bad.append(f"{path.name}:{no}: role {role!r} has no label")
return bad
def main():
used = used_keys()
# role.<x> is built by role_label(), never written literally
used.add("role.you"); used.add("role.agent"); used.add("role.thinking")
used.add("role.tool"); used.add("role.error"); used.add("role.shell")
used.add("role.splinter"); used.add("role.diff")
bad = 0
cats = sorted(ROOT.glob("share/locale/*.msg"))
if not cats:
print("check_i18n: no catalogues in share/locale", file=sys.stderr)
return 1
for path in cats:
cat = catalogue(path)
missing = sorted(k for k in used if k not in cat)
if missing:
bad = 1
print(f"{path.name}: missing {len(missing)} key(s): "
+ ", ".join(missing), file=sys.stderr)
# the English catalogue is the reference: everything in it must be used
en = catalogue(ROOT / "share/locale/en.msg")
# keys built at run time from a name: interview.q.<x>, widget.<plugin>
dynamic = ("interview.q.", "interview.h.", "widget.")
unused = sorted(k for k in en if k not in used and not k.startswith(dynamic))
if unused:
print("en.msg: keys nothing uses: " + ", ".join(unused), file=sys.stderr)
roles = unknown_roles()
if roles:
bad = 1
print("unknown role identifiers:", file=sys.stderr)
for item in roles:
print(" " + item, file=sys.stderr)
lit = hardcoded()
if lit:
bad = 1
print("hardcoded text on screen (use sp_t/sp_td):", file=sys.stderr)
for item in lit:
print(" " + item, file=sys.stderr)
if bad == 0:
print(f"check_i18n: ok ({len(used)} keys in {len(cats)} catalogues)")
return bad
if __name__ == "__main__":
sys.exit(main())