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
aab3d4d64a
commit
36d6a81079
18 changed files with 1461 additions and 27 deletions
26
packages/waybetter/i18n-meta.schema.json
Normal file
26
packages/waybetter/i18n-meta.schema.json
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
{
|
||||
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
||||
"$id": "https://waybetter.fyi/schema/i18n-meta.schema.json",
|
||||
"title": "wayBetter locale catalog notes (en.meta.json)",
|
||||
"description": "Notes for translators, one entry per source key: where the text appears and anything that constrains it. A plain string is the description.",
|
||||
"type": "object",
|
||||
"properties": { "$schema": { "type": "string" } },
|
||||
"patternProperties": {
|
||||
"^[a-z][A-Za-z0-9]*([._-][A-Za-z0-9]+)*$": {
|
||||
"oneOf": [
|
||||
{ "type": "string", "minLength": 1 },
|
||||
{
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"description": { "type": "string", "minLength": 1 },
|
||||
"context": { "description": "Where it appears (button, tooltip, menu item, native dialog title).", "type": "string" },
|
||||
"maxLength": { "description": "Hard limit in characters (tight buttons, menu items).", "type": "integer", "minimum": 1 },
|
||||
"allowEmpty": { "description": "A sentence fragment that some languages leave empty because their word order moves it into a neighbouring string.", "type": "boolean" }
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
}
|
||||
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 } } }
|
||||
}
|
||||
|
|
@ -3,10 +3,11 @@
|
|||
"version": "0.2.0",
|
||||
"license": "GPL-3.0-or-later",
|
||||
"type": "module",
|
||||
"description": "wayBetter: the framework for apps that run the apps you already use in a light native (Tauri) window and extend them in place. Page runtime (DOM/request hubs, plugins, plugin UI kit with themed dialogs and toasts, theme API and theme JSON Schema, theme color model, link routing, account reporting, deck columns) and shell models (address bar, panes, decks, profiles, palette, updates). No dependencies.",
|
||||
"description": "wayBetter: the framework for apps that run the apps you already use in a light native (Tauri) window and extend them in place. Page runtime (DOM/request hubs, plugins, plugin UI kit with themed dialogs and toasts, theme API and theme JSON Schema, theme color model, link routing, account reporting, deck columns, i18n: ICU-lite messages, locale fallback, plugin strings, catalog checks and JSON Schemas) and shell models (address bar, panes, decks, profiles, palette, updates). No dependencies.",
|
||||
"keywords": [
|
||||
"waybetter",
|
||||
"tauri",
|
||||
"i18n",
|
||||
"betterdiscord",
|
||||
"plugins",
|
||||
"theming",
|
||||
|
|
@ -24,6 +25,21 @@
|
|||
},
|
||||
"sideEffects": false,
|
||||
"exports": {
|
||||
"./i18n": {
|
||||
"types": "./dist/runtime/i18n.d.ts",
|
||||
"import": "./dist/runtime/i18n.js"
|
||||
},
|
||||
"./i18n/check": {
|
||||
"types": "./dist/runtime/i18nCheck.d.ts",
|
||||
"import": "./dist/runtime/i18nCheck.js"
|
||||
},
|
||||
"./i18n/plugin": {
|
||||
"types": "./dist/runtime/pluginI18n.d.ts",
|
||||
"import": "./dist/runtime/pluginI18n.js"
|
||||
},
|
||||
"./i18n.schema.json": "./i18n.schema.json",
|
||||
"./i18n-meta.schema.json": "./i18n-meta.schema.json",
|
||||
"./locales/*.json": "./locales/*.json",
|
||||
"./runtime/accountReport": {
|
||||
"types": "./dist/runtime/accountReport.d.ts",
|
||||
"import": "./dist/runtime/accountReport.js"
|
||||
|
|
@ -80,6 +96,10 @@
|
|||
"types": "./dist/runtime/*.d.ts",
|
||||
"import": "./dist/runtime/*.js"
|
||||
},
|
||||
"./shell/messages": {
|
||||
"types": "./dist/shell/messages.d.ts",
|
||||
"import": "./dist/shell/messages.js"
|
||||
},
|
||||
"./shell/addressModel": {
|
||||
"types": "./dist/shell/addressModel.d.ts",
|
||||
"import": "./dist/shell/addressModel.js"
|
||||
|
|
@ -126,6 +146,9 @@
|
|||
"files": [
|
||||
"dist",
|
||||
"theme.schema.json",
|
||||
"i18n.schema.json",
|
||||
"i18n-meta.schema.json",
|
||||
"locales",
|
||||
"README.md",
|
||||
"LICENSE"
|
||||
],
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue