i18n: dependency-free message runtime, catalog checks, plugin strings, native strings
- 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.
This commit is contained in:
parent
c404dd3dd0
commit
2b8161fedc
18 changed files with 1461 additions and 27 deletions
42
packages/waybetter/i18n.schema.json
Normal file
42
packages/waybetter/i18n.schema.json
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
{
|
||||
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
||||
"$id": "https://waybetter.fyi/schema/i18n.schema.json",
|
||||
"title": "wayBetter locale catalog",
|
||||
"description": "One language of a wayBetter app, plugin or the framework itself: locales/<bcp47>.json. English (en.json) is the source; every other file translates some or all of its keys. Messages are plain text in an ICU MessageFormat subset ({name}, {n, plural, ...}, {x, select, ...}, {n, number}, {d, date}); never HTML.",
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"required": ["locale", "name", "englishName", "status", "messages"],
|
||||
"properties": {
|
||||
"$schema": { "type": "string" },
|
||||
"locale": {
|
||||
"description": "Canonical BCP 47 tag of this file: tr, pt, zh-Hans, zh-Hant, en-GB, ar-x-fm.",
|
||||
"type": "string",
|
||||
"pattern": "^[a-z]{2,3}(-[A-Z][a-z]{3})?(-([A-Z]{2}|[0-9]{3}))?(-x-[a-z0-9]{1,8})?$"
|
||||
},
|
||||
"name": { "description": "The language's own name (Türkçe, 日本語).", "type": "string", "minLength": 1, "maxLength": 60 },
|
||||
"englishName": { "description": "The language's English name (Turkish, Japanese).", "type": "string", "minLength": 1, "maxLength": 60 },
|
||||
"dir": { "description": "Writing direction; must match the language.", "enum": ["ltr", "rtl"] },
|
||||
"status": {
|
||||
"description": "source: the English source. machine: machine-drafted, needs a human review (the app shows a Help translate link). reviewed: checked by the people in reviewers.",
|
||||
"enum": ["source", "machine", "reviewed"]
|
||||
},
|
||||
"reviewers": {
|
||||
"description": "Names or handles of the people who reviewed this translation.",
|
||||
"type": "array",
|
||||
"items": { "type": "string", "minLength": 1, "maxLength": 80 },
|
||||
"uniqueItems": true
|
||||
},
|
||||
"fallback": {
|
||||
"description": "A locale this one inherits from before English (ar-x-fm falls back to ar, en-GB to en).",
|
||||
"type": "string"
|
||||
},
|
||||
"messages": {
|
||||
"description": "Flat map of dotted keys to messages. Keys must exist in en.json; placeholders must match English.",
|
||||
"type": "object",
|
||||
"propertyNames": { "pattern": "^[a-z][A-Za-z0-9]*([._-][A-Za-z0-9]+)*$", "maxLength": 96 },
|
||||
"additionalProperties": { "type": "string", "maxLength": 2000, "not": { "pattern": "<\\s*/?\\s*[A-Za-z!?]" } }
|
||||
}
|
||||
},
|
||||
"if": { "properties": { "status": { "const": "reviewed" } } },
|
||||
"then": { "required": ["reviewers"], "properties": { "reviewers": { "minItems": 1 } } }
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue