Extract 515 strings by codemod, and the two bugs only a screenshot caught
Wrapping ~1,000 strings by hand is a thousand chances to mistype the copy
itself, and a parser does not get bored. scripts/i18n-extract.mjs does the
mechanical part -- JSX text and the attributes a person actually reads -- and
refuses the rest rather than guessing. 78% now: 515 wrapped, 143 left.
What it refuses matters as much as what it does. Text split around an
interpolation arrives as separate fragments, and wrapping each on its own
produces "Move " and " messages", which no translator can do anything with;
those are listed for a person to rebuild as sentences. So is anything
containing a double quote, which would end the literal.
Three things it had to be taught, each found by running it:
- <code>, <kbd> and <pre> are not prose. The first run wrapped `label:name`
inside <code> -- a search operator, where translating it breaks the thing it
documents. Subtrees marked translate="no" are skipped for the same reason.
- `t` is a natural name for a callback parameter and several files already use
it, so an import called `t` is shadowed inside those callbacks -- silently,
wherever the local happens to be callable. The name is checked per file now
and aliased to `translate` where it is taken.
- JSX decodes HTML entities and a JS string literal does not, so
`Language & region` moved into t("...") and rendered the entity on screen.
That last one is the one worth remembering. Typecheck passed, 443 tests
passed, and the page said "Language & region" in plain sight. It took
looking at a screenshot, and then a sweep of ten views to find the second
occurrence in a sentence I had written by hand earlier the same day. Nothing
in the toolchain was ever going to catch it: it is valid TypeScript rendering
valid text that happens to be wrong.
The codemod decodes entities now, and checks for a quote after decoding rather
than before.
This commit is contained in:
@@ -6,6 +6,7 @@ import { useContacts } from "@/store/contacts";
|
||||
import { useSettings } from "@/store/settings";
|
||||
import { contactDisplayName, contactEmails } from "@/lib/contacts";
|
||||
import type { ContactCard, EmailAddress } from "@/jmap/types";
|
||||
import { t } from "@/lib/i18n";
|
||||
|
||||
export type Field = "to" | "cc" | "bcc";
|
||||
|
||||
@@ -109,13 +110,13 @@ export function RecipientPicker({ onPick, onClose }: { onPick: (field: Field, ad
|
||||
<Dialog
|
||||
open
|
||||
onClose={onClose}
|
||||
title="Choose recipients"
|
||||
title={t("Choose recipients")}
|
||||
size="lg"
|
||||
footer={
|
||||
<>
|
||||
<button className="btn" onClick={onClose}>Cancel</button>
|
||||
<button className="btn" disabled={!chosen.length} onClick={() => send("bcc")}>Bcc</button>
|
||||
<button className="btn" disabled={!chosen.length} onClick={() => send("cc")}>Cc</button>
|
||||
<button className="btn" onClick={onClose}>{t("Cancel")}</button>
|
||||
<button className="btn" disabled={!chosen.length} onClick={() => send("bcc")}>{t("Bcc")}</button>
|
||||
<button className="btn" disabled={!chosen.length} onClick={() => send("cc")}>{t("Cc")}</button>
|
||||
<button className="btn btn-primary" disabled={!chosen.length} onClick={() => send("to")}>
|
||||
{chosen.length > 1 ? `To — ${chosen.length} people` : "To"}
|
||||
</button>
|
||||
@@ -129,14 +130,14 @@ export function RecipientPicker({ onPick, onClose }: { onPick: (field: Field, ad
|
||||
<input
|
||||
className="grow"
|
||||
style={{ background: "none", border: 0, outline: "none", color: "inherit", font: "inherit" }}
|
||||
placeholder="Search names and addresses"
|
||||
placeholder={t("Search names and addresses")}
|
||||
value={q}
|
||||
onChange={(e) => setQ(e.target.value)}
|
||||
autoFocus
|
||||
/>
|
||||
</label>
|
||||
<select className="select" value={bookKey} onChange={(e) => setBookKey(e.target.value)} aria-label="Address book">
|
||||
<option value="all">All address books</option>
|
||||
<select className="select" value={bookKey} onChange={(e) => setBookKey(e.target.value)} aria-label={t("Address book")}>
|
||||
<option value="all">{t("All address books")}</option>
|
||||
{ownBooks.map((b) => <option key={b.id} value={b.id}>{b.name}</option>)}
|
||||
{subscribed.map((b) => (
|
||||
<option key={`${b.accountId}:${b.book.id}`} value={`${b.accountId}:${b.book.id}`}>
|
||||
@@ -149,7 +150,7 @@ export function RecipientPicker({ onPick, onClose }: { onPick: (field: Field, ad
|
||||
{chosen.length > 0 && (
|
||||
<div className="row wrap gap-4" style={{ marginBottom: 10 }}>
|
||||
{chosen.map((r) => (
|
||||
<button key={r.key} className="chip" onClick={() => toggle(r)} title="Remove">
|
||||
<button key={r.key} className="chip" onClick={() => toggle(r)} title={t("Remove")}>
|
||||
{r.name ?? r.email} <X size={12} />
|
||||
</button>
|
||||
))}
|
||||
@@ -158,7 +159,7 @@ export function RecipientPicker({ onPick, onClose }: { onPick: (field: Field, ad
|
||||
|
||||
<div style={{ maxHeight: "48vh", overflowY: "auto" }}>
|
||||
{contacts.loading && !rows.length ? (
|
||||
<Spinner label="Loading contacts…" />
|
||||
<Spinner label={t("Loading contacts…")} />
|
||||
) : !rows.length ? (
|
||||
<p className="hint">{q ? "Nobody matches that." : "No contacts in this address book."}</p>
|
||||
) : (
|
||||
|
||||
Reference in New Issue
Block a user