- runtime/i18n.ts: ICU-lite messages (placeholders as text, Intl.PluralRules plurals with exact
forms, selectordinal, select, number/date/time), fallback chains (pt-BR -> pt -> en, ar-x-fm ->
ar), X and legacy code aliases, RTL by locale, lazy catalogs, live onChange. Apostrophes are
literal except right before { } # or another apostrophe.
- runtime/i18nCheck.ts: rules for contributed catalogs (shape, keys, syntax, placeholder parity,
select options, markup/control characters, lengths). An argument English only uses to choose a
plural form may be dropped; missing plural forms are warnings; meta "allowEmpty" fragments.
- runtime/pluginI18n.ts: api.i18n bound per plugin (register/t/locale/dir/onChange/number/date/
relative/list); the UI kit's own words follow the app's language. pageLang.ts reports the
site's <html lang>. shell/messages.ts: shell-model words.
- waybetter-host i18n.rs: NativeStrings (validated plain text, caps, one-pass {name} fill, page
payload by prefix), system_locales via sys-locale; TabState.lang.
- JSON Schemas for catalogs and translator notes; npm exports waybetter/i18n, /i18n/check,
/i18n/plugin.
29 lines
1.6 KiB
TypeScript
29 lines
1.6 KiB
TypeScript
// The shell models' own words (account labels, the update chip) in English, with `{name}`
|
|
// placeholders. They live in the framework catalogs (`waybetter/locales/<bcp47>.json`, `wb.*`), so
|
|
// every wayBetter app shows them in its language: pass a `text(key)` translator to the models; it
|
|
// returns the translated message (placeholders not yet filled) or undefined for English.
|
|
|
|
export const SHELL_MESSAGES = {
|
|
'wb.account.notSignedIn': 'Not signed in yet',
|
|
'wb.account.signedOut': '{handle} · signed out',
|
|
'wb.account.newName': 'New account',
|
|
'wb.update.readyLabel': 'Update ready · restart',
|
|
'wb.update.readyTitle': 'Restart to update to {product} {version}. Tabs are restored.',
|
|
'wb.update.installingLabel': 'Updating…',
|
|
'wb.update.installingTitle': 'Installing {product} {version}',
|
|
'wb.update.problemLabel': 'Update problem',
|
|
'wb.update.problemTitle': 'The last update did not start correctly. Download the current version.',
|
|
} as const;
|
|
export type ShellKey = keyof typeof SHELL_MESSAGES;
|
|
/** A translator for the shell models: the message for `key` (unformatted) or undefined for English. */
|
|
export type ShellText = (key: ShellKey) => string | undefined;
|
|
|
|
/** The message for `key` with `{name}` placeholders filled in (values inserted as text). */
|
|
export function shellText(key: ShellKey, params: Record<string, string> = {}, text?: ShellText): string {
|
|
let message: string = SHELL_MESSAGES[key];
|
|
try {
|
|
const translated = text?.(key);
|
|
if (typeof translated === 'string' && translated) message = translated;
|
|
} catch { /* English */ }
|
|
return message.replace(/\{(\w+)\}/g, (whole, name: string) => (name in params ? params[name]! : whole));
|
|
}
|