Finish extraction: 100%, and a coverage number worth believing

The 143 the codemod refused turned out to be two different things, and only
one of them needed a person.

A third were phrases sitting next to an icon -- `<Plus /> New rule`. The
refusal rule was "has siblings", which is broader than the danger: what breaks
a translation is a sibling that renders *text*, splitting a sentence into
fragments no one can reorder. An element beside a phrase does not. Narrowing
the rule to text-producing siblings let the codemod take 73 more.

The rest were real sentences with values in the middle, rebuilt by hand as
named placeholders -- "Your active script “{name}” was written by hand",
"Waiting on the server — goes out {when}." Named rather than positional
because a translator moves the parts around; counted things go through
plural() so Russian and Ukrainian get their three forms rather than English's
two.

Sentences with an element inside them needed something new. `Open <code>mailto:
</code> links in ihasmail` has two obvious treatments and both are wrong:
splitting it into two t() calls hands over fragments that cannot be reordered,
and dropping the <code> keeps the sentence whole but loses the monospace that
said "this is a literal". tNode() keeps the sentence whole and makes the
element a named hole in it, so a translator sees one sentence and can put the
hole where their language wants it. The German test asserts exactly that: the
same call renders the code first when the catalogue says so.

The coverage number was also lying, and it is worth saying how. It counted
text inside <code> and inside translate="no" as untranslated work, and
placeholders like "123456" and "+1 555 0100" -- a one-time code and a phone
format. None of those will ever be translated, so the report sat at 21 with 6
real items left. A number with an unreachable floor is something to argue with
rather than act on, so the tool now applies the same rules the codemod does.

596 wrapped, nothing remaining. Verified in the browser across 15 views, which
is where the last bulk pass hid a bug the tests could not see: no entities, no
unfilled placeholders, no raw t( in rendered text, and the toggle switches that
looked like emptied labels are text-free by design.
This commit is contained in:
2026-08-31 10:41:24 -07:00
parent 46c1dc28e3
commit 3f4b33cb51
40 changed files with 228 additions and 123 deletions
+37 -1
View File
@@ -1,4 +1,4 @@
import { useSyncExternalStore } from "react";
import { createElement, Fragment, useSyncExternalStore, type ReactNode } from "react";
import { DEFAULT_UI_LANGUAGE, resolveUiLanguage } from "@/lib/languages";
/**
@@ -83,6 +83,42 @@ export function plural(n: number, forms: PluralForms, vars?: Vars): string {
return interpolate(entry[category] ?? entry.other, { n, ...vars });
}
/**
* A translated sentence with elements inside it.
*
* Some sentences have a `<code>` or a `<kbd>` in the middle of them, and the
* two obvious approaches are both wrong. Splitting the sentence into two `t()`
* calls hands a translator "This browser cannot register apps for" and "links,
* in particular…", which are not sentences and cannot be reordered into a
* language that puts the verb somewhere else. Dropping the element and
* interpolating plain text keeps the sentence whole but loses the monospace
* that told the reader it was a literal.
*
* So the sentence stays whole and the elements are placeholders in it:
*
* tNode("Open {scheme} links in ihasmail.", { scheme: <code>mailto:</code> })
*
* A translator sees one sentence with a named hole and can put the hole
* wherever their language wants it.
*/
export function tNode(source: string, parts: Record<string, ReactNode>, vars?: Vars): ReactNode {
const translated = interpolate(current.strings[source] ?? source, vars);
const out: ReactNode[] = [];
let last = 0;
const re = /\{(\w+)\}/g;
let m: RegExpExecArray | null;
while ((m = re.exec(translated))) {
if (!Object.prototype.hasOwnProperty.call(parts, m[1]!)) continue;
if (m.index > last) out.push(translated.slice(last, m.index));
// Keyed, because this is an array and React asks; the index is stable for
// a given rendering of a given sentence.
out.push(createElement(Fragment, { key: `${m[1]}-${m.index}` }, parts[m[1]!]));
last = m.index + m[0].length;
}
if (last < translated.length) out.push(translated.slice(last));
return out;
}
/** The language in force, for anything that needs the tag itself. */
export function currentLanguage(): string {
return currentTag;