The code cited its plan instead of saying why: `E28 review J4`, `(R6 S3b)`, `S1 justified…`,
`deep-review round 5`. That plan lives in the private ops repo, so for every reader of this one the
citation was noise, and a sentence whose subject was the plan step ("round 2 showed…") hid its
lesson behind an id. Each one is gone and the "why" kept: a bare citation is deleted, a sentence
carrying a lesson is reworded around it ("a later attempt showed…").
Measured (`scripts/audit_metrics.py`, product code): 652 lines in 270 files carried an epic code by
the definition the next commit holds (507 / 241 by the old, two-digit-only one) -> 0. Across all
code, tests, scripts and configs: ~1100 epic-code lines plus ~320 sprint/round ids.
Behaviour unchanged, checked mechanically: every changed .py file has the same AST once docstrings
are blanked; css/sh/toml/yml/json files are identical once comments are stripped; the only
non-comment changes in TS/JS are test titles, one description string in a contract table, and five
ESLint messages, whose text is all the gates snapshot diff holds. Not touched: Markdown (docs and
the changelog keep their history), Alembic migrations, TV episode notation (`S2 · E5`), DESIGN.md
ids (`C1`, `B4`, `S3h`), tracker ids (`SEC-16`, `DX-17`).
One stale claim fixed on the way: test_hls_reaper's docstring said the player checkpoints "every
10 s whether or not it is playing", which plex/stream.py calls wrong; it now says what the code does.
44 lines
2.1 KiB
TypeScript
44 lines
2.1 KiB
TypeScript
import i18n from "./index";
|
|
|
|
// The translation KEY a piece of on-screen text is, or null (for click capture).
|
|
//
|
|
// A click is logged by what the control IS, and its visible label is the most telling part — but a
|
|
// label can be the user's own content (a video title, a tag, a channel name), which the log must not
|
|
// carry. Text that is exactly one of the app's own translated strings is app copy, not user content,
|
|
// so it can be logged — as its ENGLISH wording, whatever the UI language: the same click reads the
|
|
// same in every log, and nothing a user typed comes out of it (a user's tag that happens to equal a
|
|
// string of ours is logged as our string, which says nothing about the user). Not as a key: one
|
|
// wording is often several keys ("Diagnostics" is a settings tab AND a config group), so a key would
|
|
// name a control the user may never have touched. Interpolated strings (`{{n}} items`) never match.
|
|
let index: Map<string, string> | null = null;
|
|
|
|
const normalize = (text: string) => text.replace(/\s+/g, " ").trim();
|
|
|
|
/** Every app string (any language) → its English wording. */
|
|
function build(): Map<string, string> {
|
|
const map = new Map<string, string>();
|
|
const resources = i18n.options.resources ?? {};
|
|
const english = (path: string[]): string | null => {
|
|
let node: unknown = resources.en?.translation;
|
|
for (const key of path) node = (node as Record<string, unknown> | undefined)?.[key];
|
|
return typeof node === "string" ? normalize(node) : null;
|
|
};
|
|
const walk = (node: unknown, path: string[]) => {
|
|
if (typeof node === "string") {
|
|
const text = normalize(node);
|
|
const en = english(path);
|
|
if (en && text.length >= 2 && !text.includes("{{") && !map.has(text)) map.set(text, en);
|
|
} else if (node && typeof node === "object") {
|
|
for (const [k, v] of Object.entries(node)) walk(v, [...path, k]);
|
|
}
|
|
};
|
|
for (const lang of Object.keys(resources)) walk(resources[lang]?.translation, []);
|
|
return map;
|
|
}
|
|
|
|
export function appCopyOf(text: string | null | undefined): string | null {
|
|
if (!text) return null;
|
|
index ??= build();
|
|
return index.get(normalize(text)) ?? null;
|
|
}
|