Phase 19: the copy stops being hardcoded Mandarin

Every `中文 · English` string moves out of ~29 components into
web/src/i18n: one Pack type, a verbatim zh pack, and two ways to read
it — usePack() for components, pack() for the modules that build a line
when something happens rather than when something renders.

Anything with a value in it is a function on the pack rather than a
template at the call site, English pluralisation included: word order
isn't universal, and a pack author has to be able to move the number.
The roster constants (tones, rewrite styles, export formats, companions)
keep only value + emoji, so a label can't drift from its key.

On the server, internal/llm/lang.go replaces "Simplified Chinese" in the
three prompts that actually name her language. pt-PT is spelled
"European Portuguese (pt-PT, never Brazilian Portuguese)" in the prompt
itself, and each Lang carries her word for "why" so the tutor prompt
still recognises the question when she asks it her way.

pair_lang reaches the model through the row-scoped query each handler
already ran — the one that proves she owns the document — rather than a
second lookup that could disagree with it.

Also records Phase 18's deploy: migration 0011 rehearsed against a copy
of the live VPS database, then applied for real.
This commit is contained in:
prosolis
2026-07-27 08:37:05 -07:00
parent 30d5e691c9
commit 336cae93e0
45 changed files with 1331 additions and 371 deletions
+17 -15
View File
@@ -1,28 +1,29 @@
import { useEffect, useRef, useState } from 'react'
import { usePack } from '../../i18n'
// ToneSelect lets the writer set the document's target tone, which steers the
// grammar-checkpoint LLM toward the right register (an academic essay vs a casual
// journal). A small custom dropdown (not a native <select>) so it can carry the
// bilingual zh·en labels and emoji that match Petal's chrome — the writer uses
// Mandarin and English. The `value` strings mirror the backend's tone keys.
// bilingual labels and emoji that match Petal's chrome — the writer reads her
// own language and English. The `value` strings mirror the backend's tone keys;
// the labels themselves live in the langpack, keyed by the same value.
export interface ToneOption {
value: string
emoji: string
zh: string
en: string
}
// Keep these `value`s in sync with llm.toneGuidance on the server. 'general'
// means no steering (Petal's default friendly ESL advice).
export const TONES: ToneOption[] = [
{ value: 'general', emoji: '🌸', zh: '通用', en: 'General' },
{ value: 'academic', emoji: '🎓', zh: '学术', en: 'Academic' },
{ value: 'professional', emoji: '💼', zh: '专业', en: 'Professional' },
{ value: 'casual', emoji: '☕', zh: '轻松', en: 'Casual' },
{ value: 'humorous', emoji: '😄', zh: '幽默', en: 'Humorous' },
{ value: 'creative', emoji: '🎨', zh: '创意', en: 'Creative' },
{ value: 'persuasive', emoji: '📣', zh: '说服', en: 'Persuasive' },
{ value: 'general', emoji: '🌸' },
{ value: 'academic', emoji: '🎓' },
{ value: 'professional', emoji: '💼' },
{ value: 'casual', emoji: '☕' },
{ value: 'humorous', emoji: '😄' },
{ value: 'creative', emoji: '🎨' },
{ value: 'persuasive', emoji: '📣' },
]
interface Props {
@@ -31,6 +32,7 @@ interface Props {
}
export function ToneSelect({ value, onChange }: Props) {
const pk = usePack()
const [open, setOpen] = useState(false)
const ref = useRef<HTMLDivElement>(null)
const current = TONES.find((t) => t.value === value) ?? TONES[0]
@@ -63,8 +65,8 @@ export function ToneSelect({ value, onChange }: Props) {
title="Set the tone — Petal tailors its advice to match"
>
<span aria-hidden>{current.emoji}</span>
<span>{current.zh}</span>
<span style={{ color: 'var(--color-muted)' }}>· {current.en}</span>
<span>{pk.tones[current.value].native}</span>
<span style={{ color: 'var(--color-muted)' }}>· {pk.tones[current.value].en}</span>
<span aria-hidden style={{ color: 'var(--color-muted)' }}>
</span>
@@ -105,9 +107,9 @@ export function ToneSelect({ value, onChange }: Props) {
}
>
<span aria-hidden>{t.emoji}</span>
<span>{t.zh}</span>
<span>{pk.tones[t.value].native}</span>
<span className="font-normal" style={{ color: 'var(--color-muted)' }}>
{t.en}
{pk.tones[t.value].en}
</span>
</button>
)