diff --git a/Makefile b/Makefile index df94dce..0a61e4d 100644 --- a/Makefile +++ b/Makefile @@ -134,7 +134,8 @@ tests/test_plugin: tests/test_plugin.c $(LIB) $(PLUGIN) $(CC) $(CFLAGS) -o $@ tests/test_plugin.c -L. -lsplinter $(TEST_RPATH) $(LIBS) check: $(LIB) $(BIN) $(PLUGIN) $(TESTS) - @set -e; for t in $(TESTS); do echo "== $$t"; ./$$t; done; \ + @set -e; python3 tools/check_i18n.py; \ + for t in $(TESTS); do echo "== $$t"; ./$$t; done; \ echo "all tests passed" install: all diff --git a/share/locale/de.msg b/share/locale/de.msg index 9fbc371..4c71979 100644 --- a/share/locale/de.msg +++ b/share/locale/de.msg @@ -54,3 +54,6 @@ cli.no_output = cli: '%s' lieferte keine Ausgabe cli.timeout = cli: '%s' lief nach %s s in das Zeitlimit cli.failed = cli: '%s' scheiterte (exit %d): %.400s focus.widget_none = kein Ziel (/goal ) +ui.prompt_mark = > +sidebar.ms = %ld ms +ui.empty = - diff --git a/share/locale/en.msg b/share/locale/en.msg index 2345eae..17b8772 100644 --- a/share/locale/en.msg +++ b/share/locale/en.msg @@ -53,3 +53,6 @@ cli.no_output = cli: '%s' produced no output cli.timeout = cli: '%s' timed out after %s s cli.failed = cli: '%s' failed (exit %d): %.400s focus.widget_none = no goal (/goal ) +ui.prompt_mark = > +sidebar.ms = %ld ms +ui.empty = - diff --git a/src/ui.c b/src/ui.c index da2df1e..0ff00c6 100644 --- a/src/ui.c +++ b/src/ui.c @@ -580,7 +580,8 @@ draw_sidebar(struct ui_state *s, const char *id, const char *dir, werase(ui_side); sidebar_heading(&y, cols, sp_t("sidebar.session")); - mvwaddnstr(ui_side, y++, 0, id != NULL ? id : "-", cols - 1); + mvwaddnstr(ui_side, y++, 0, id != NULL ? id : sp_t("ui.empty"), + cols - 1); if (dir != NULL) mvwaddnstr(ui_side, y++, 0, dir, cols - 1); y++; @@ -597,7 +598,7 @@ draw_sidebar(struct ui_state *s, const char *id, const char *dir, y++; sidebar_heading(&y, cols, sp_t("sidebar.last_turn")); - mvwprintw(ui_side, y++, 0, "%ld ms", s->last_ms); + mvwprintw(ui_side, y++, 0, sp_t("sidebar.ms"), s->last_ms); mvwprintw(ui_side, y++, 0, sp_t("sidebar.steps"), s->last_steps); mvwprintw(ui_side, y++, 0, sp_t("sidebar.tool_calls"), s->last_calls); y++; @@ -809,7 +810,7 @@ sp_ui_run(struct sp_agent *ag, const char *endpoint, const char *theme_name, ag->sess != NULL ? ag->sess->dir : NULL, host); draw_status(&s); werase(ui_input); - mvwaddstr(ui_input, 0, 0, "> "); + mvwaddstr(ui_input, 0, 0, sp_t("ui.prompt_mark")); wnoutrefresh(ui_input); doupdate(); @@ -848,7 +849,7 @@ sp_ui_run(struct sp_agent *ag, const char *endpoint, const char *theme_name, if (ch == 3) { len = 0; werase(ui_input); - mvwaddstr(ui_input, 0, 0, "> "); + mvwaddstr(ui_input, 0, 0, sp_t("ui.prompt_mark")); wrefresh(ui_input); continue; } @@ -874,7 +875,7 @@ sp_ui_run(struct sp_agent *ag, const char *endpoint, const char *theme_name, } input[len] = '\0'; werase(ui_input); - mvwaddstr(ui_input, 0, 0, "> "); + mvwaddstr(ui_input, 0, 0, sp_t("ui.prompt_mark")); ui_add_text(ui_input, input, getmaxx(ui_input) - 3); wrefresh(ui_input); @@ -901,7 +902,7 @@ sp_ui_run(struct sp_agent *ag, const char *endpoint, const char *theme_name, input[len++] = (char)ch; input[len] = '\0'; werase(ui_input); - mvwaddstr(ui_input, 0, 0, "> "); + mvwaddstr(ui_input, 0, 0, sp_t("ui.prompt_mark")); ui_add_text(ui_input, input, getmaxx(ui_input) - 3); wrefresh(ui_input); } diff --git a/tests/test_ascii b/tests/test_ascii index 0886ff0..3e2c255 100755 Binary files a/tests/test_ascii and b/tests/test_ascii differ diff --git a/tools/check_i18n.py b/tools/check_i18n.py index 4c09d8a..1960910 100755 --- a/tools/check_i18n.py +++ b/tools/check_i18n.py @@ -28,6 +28,43 @@ def catalogue(path): 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"} + + +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. is built by role_label(), never written literally @@ -51,6 +88,18 @@ def main(): unused = sorted(k for k in en if k not in used) 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