Repository navigation
feat(i18n): translatable metadata and layered catalogues (0.4.0) - #5
Merged
Merged
Conversation
A site now keeps real copies of its apps instead of symlinks into the bench, so replacing `apps/<app>/<app>.wasm` cannot silently change an installed instance. `install-app` copies the component, `app_versions` records the catalogue version captured at copy time (only a forced install rewrites it) and legacy symlinked instances are materialized on boot/migrate. The copy still refuses symlinks that would escape the project tree. `site_config.json` also gains `default_locale` and `supported_locales`: the policy `GET /api/i18n` advertises and the Desk negotiates against. Both are normalized (trimmed, de-duplicated, never empty) so a hand-edited site config cannot turn the locale into a path or an empty set.
The Desk is translated end to end. The catalogues are compiled into the binary, not read from disk at boot: `en` is the base and every other locale overrides it, so a missing key degrades to English instead of to a blank label or a raw key. Keys live in per-area fragments (`en.toml`, `.views`, `.desk`, `.components`, `.ui` and the Spanish equivalents) because one flat table had grown past the size where a reviewer can see a duplicate. `Locale` parses the subset of BCP 47 the catalogues can actually serve, and `negotiate` walks `Accept-Language` q-values without turning a header into a filesystem path or a lookup key. `ferris-web-shared::i18n::DeskI18n` is the snapshot that crosses the SSR boundary and `Translate`/`t_with` are the formatted lookups. `ferris-web-ui` gets a `Copy` handle over a `StoredValue` so a component can call `t` from a nested closure without cloning the catalogue; the 30 components that had Spanish strings inline now read keys. `en` and `es` carry the same 1,031 keys; the coverage test in the framework fails when a literal shown to the user has no entry.
`User.language` was seeded with `"en"`, which made every account ignore its
browser. It now starts as `None`, meaning "follow `Accept-Language`"; an
explicit tag is a per-account choice and outranks the header. `StoredUser`
round-trips the field and `UserStore::set_language` is the only writer, with
`None` clearing the preference.
`WebUser.language` carries it to the Desk (serde-defaulted so an older client
or server still deserializes), and `PUT /api/auth/language` persists the
caller's tag. The handler validates it with `Locale::parse`, rejects an unknown
tag with `400` and answers `{ "language": "es" }`; the framework mounts the
route behind the CSRF gate, like logout, because it mutates the account.
The catalogue set is no longer closed at compile time: `I18n::with_catalog`
merges a layer for a locale (an app or a site) over the embedded one and
advertises the tag, so a deployment can serve a language the binary does not
embed. Lookups, the effective JSON payload and negotiation all fall back to
the base language (`es-MX` → `es`) before the caller's own fallback.
`i18n::keys` is the one place the metadata convention lives: DocTypes
(`doctype.<X>.label`), fields, workspaces, folders, sidebar items and themes.
`MetaTranslate` resolves a key and returns the declared text when the
catalogue has no entry, so a partially translated catalogue degrades to the
previous behaviour instead of printing keys. Identifiers are never translated.
The shipped catalogues gain `{en,es}.meta.toml` with the host's own DocTypes,
fields, workspaces and themes: 2,397 keys per language, parity enforced by the
existing catalogue test. The version moves to 0.4.0 with the contract.
`locales/<tag>.toml` travels with the package, next to `plugin.toml`. The global install copies it into `apps/<app>/locales` (and removes stale files on a re-install without catalogues), and `site install-app` copies it into the instance's own directory, where the boot scan merges it. A site therefore translates itself from what it installed, not from whatever the catalogue holds later.
`/api/doctype/meta`, `/api/modules`, `/api/desk-layout`, `/api/ui-extensions` and `/api/themes` now resolve DocType, field, workspace, dashboard, widget and theme labels through the catalogue. `RequestLocale` negotiates once per request with the shell's precedence (account language, then `Accept-Language`, then the instance default), and the labels are resolved in the projection, so the Desk, the CSV export and the SSR bridge all inherit the same text. `DynMeta.label` carries the DocType's resolved name; `localize_dyn_meta` only touches display strings — `name`, `fieldname`, options and view flags stay byte-identical. A label without a catalogue entry keeps the declared text.
This was referenced Nov 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Qué
La capa i18n deja de estar cerrada en compilación y cubre los metadatos.
I18n::with_catalogfusiona un catálogo externo (app o sitio) sobre el embebido y anuncia su idioma. La búsqueda, el JSON efectivo y la negociación caen al idioma base (es-MX→es) antes del fallback del llamante.i18n::keys):doctype.<X>.label/.description,field.<X>.<campo>.label/.placeholder/.description,workspace.<X>.label,workspace.folder.<X>.label,workspace.<ws>.item.<texto>.label,theme.<id>.label.MetaTranslatedevuelve el texto declarado cuando no hay entrada: nunca se imprime una clave.{en,es}.meta.toml: 130 DocTypes con descripción, 1.074 campos, workspaces, carpetas, grupos y temas (2.397 claves por idioma, paridad verificada).RequestLocalenegocia por petición (cuenta →Accept-Language→ default) y/api/doctype/meta,/api/modules,/api/desk-layout,/api/ui-extensionsy/api/themesdevuelven las etiquetas ya traducidas.DynMetaganalabel; los identificadores (name,fieldname, rutas, permisos) no se tocan.install-appcopialocales/al ámbito del sitio y el arranque lo fusiona.Versión
0.4.0en ambosCargo.toml,ferris.wit,WIT_VERSIONyFerrisDocs/project.json(cambio de contrato en0.x).Verificación
cargo test -p ferris-core -p ferris-schema -p ferris-api -p ferris-auth -p ferris-web-shared -p ferris-web-ui -j 2 -- --test-threads=1→ 0 fallos.cargo fmt --all -- --checklimpio; clippy sin avisos en líneas añadidas./api/doctype/meta/Userenesdevuelvelabel: Usuarioy campos traducidos,/api/modules→Usuariosy/api/themes→Claro, con los identificadores intactos.