String packs: rich-text entries, language conditions and word rewriting; theme doctor report; translate-mode words

- Rich sentences (a link or button inside text) can be replaced by data: the inventory gives a rich entry `slots`, a pack value places the site's own elements with {e0}, {e1}, ... (each once, the last may be left out; no markup, plural or other parameters). The engine returns a pieces + element order template; the page inventory carries `rich` slot counts.
- Packs may carry `when: { languages }` (applies only while the site shows one of them; `en` matches `en-GB`) and `rewrite: { words }` (whole-word rewording of the site's own text, messages keep their parameters' values; no sentences of the site in the pack). The hook tells the engine the site's language; a rewording pack makes the delivery carry the whole inventory.
- Apps can ship built-in packs (BuiltInPacks) delivered before installed ones; syncStringPacks hands the tabs a delivery at start only when it changed.
- Translate mode words are a function the app supplies (asked at each draw) and gain a `plural` word; host validates `when` and `rewrite` envelopes.
- Theme doctor: every finding says where (token path or CSS rule), what and how to fix, as catalog keys wb.doctor.*; the Theme Builder shows the full report; the import hint is translated. Doctor words are in the 17 supported catalogs.
- waybetter strings check describes conditions and rewrites.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
CRTkafa 2026-10-01 14:19:36 +07:00
parent 1539cb68e1
commit 6b37744226
33 changed files with 1353 additions and 85 deletions

View file

@ -16,10 +16,10 @@ import { ThemeDots } from '../frame/PaneTheme.tsx';
import { shell, type WebParams } from '../frame/state.ts';
import { assign } from '../frame/themeScopes.ts';
import { tabProfile } from '../profileModel.ts';
import { Button, ColorField, Row, Section, Segmented, Select, Slider, Toggle, useSettingsQuery, type Option } from './controls.tsx';
import { Badge, Button, ColorField, Row, Section, Segmented, Select, Slider, Toggle, useSettingsQuery, type Option } from './controls.tsx';
import { IconPackImport, IconPackReview } from './IconPackInstall.tsx';
import type { IconPack } from '../../../runtime/src/themeIcons.ts';
import { themeDoctor } from '../../../runtime/src/themeDoctor.ts';
import { themeDoctor, type DoctorAdvice } from '../../../runtime/src/themeDoctor.ts';
import { bytesLabel, defaultWeights, loadCatalog, weightsLabel } from './fonts/catalog.ts';
import { FontRoles } from './fonts/FontRoles.tsx';
import { CustomCssEditor } from './Plugins.tsx';
@ -283,6 +283,8 @@ export function Appearance({ notify }: { notify: Notify }) {
<ThemeCssEditor key={choice.preset} css={effective.css} onApply={text => { void override({ css: { text } }); notify(t('wb.appearance.cssApplied', { name: base.name })); }}/>
</Section>
<DoctorReport theme={effective}/>
<Section title={t('wb.appearance.scopes')} id="theme-scopes" hint={searching ? undefined : t('wb.appearance.scopesHint')}>
<Row label={t('wb.appearance.chrome')} hint={t('wb.appearance.chromeHint')}
keywords="chrome window tabs titlebar panel colors own style">
@ -299,6 +301,24 @@ export function Appearance({ notify }: { notify: Notify }) {
}
/** Theme choices for a scope row: follow (the level above) plus every theme with its swatch. */
/** The theme doctor's full report on the theme as it is now: every finding, where it is, what it found, how to fix it. Advice only. */
function DoctorReport({ theme }: { theme: ThemeSpec }) {
const t = useT();
const advice = themeDoctor(theme);
const words = (item: DoctorAdvice, part: 'found' | 'fix') => t(`wb.doctor.${item.key}.${part}`, item.params);
return <Section title={t('wb.doctor.title')} id="theme-doctor" hint={t('wb.doctor.hint')} action={<Badge tone={advice.length ? undefined : 'ok'}>{t('wb.doctor.count', { count: advice.length })}</Badge>}>
{advice.length === 0
? <p className="btp-hint">{t('wb.doctor.empty')}</p>
: <ul className="bt-doctor" aria-label={t('wb.doctor.title')}>
{advice.map((item, index) => <li key={`${item.id}:${item.where}:${index}`} className={`bt-doctor-item is-${item.kind}`}>
<span className="bt-doctor-head"><Badge>{t(`wb.doctor.kind.${item.kind}`)}</Badge><strong>{words(item, 'found')}</strong></span>
<small className="bt-doctor-line">{t('wb.doctor.where')}: <code>{item.where}</code></small>
<small className="bt-doctor-line">{t('wb.doctor.fix')}: {words(item, 'fix')}</small>
</li>)}
</ul>}
</Section>;
}
function scopeOptions(follow: string): Array<Option<string>> {
// Called during render of components that use useT(), so the labels follow the language.
return [{ value: '', label: follow }, ...panelThemes().store.allThemes().map(theme => ({ value: theme.id, label: theme.name, icon: <ThemeDots theme={theme}/> }))];
@ -408,7 +428,7 @@ function ImportPanel({ onImport, onCancel }: { onImport(theme: ThemeSpec, warnin
if ('error' in parsed) { setError(parsed.error); return; }
// The theme doctor: advice only (never a block); contrast is already in the warnings.
const hints = themeDoctor(parsed.theme).filter(advice => advice.kind !== 'contrast');
onImport(parsed.theme, hints.length ? [...parsed.warnings, t('wb.appearance.doctorHints', { count: hints.length, hint: hints[0]!.text })] : parsed.warnings);
onImport(parsed.theme, hints.length ? [...parsed.warnings, t('wb.appearance.doctorHints', { count: hints.length, hint: t(`wb.doctor.${hints[0]!.key}.found`, hints[0]!.params) })] : parsed.warnings);
};
return <div className="bt-import">
<div className="bt-import-drop" onDragOver={event => event.preventDefault()}