Skip to content

feat(i18n): translatable metadata and layered catalogues (0.4.0) - #5

Merged
Stdg001 merged 6 commits into
developfrom
feature/apps-sites-i18n
Nov 23, 2026
Merged

Stdg001 merged 6 commits into
developfrom
feature/apps-sites-i18n

Conversation

@Stdg001

@Stdg001 Stdg001 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Qué

La capa i18n deja de estar cerrada en compilación y cubre los metadatos.

  • Capas de catálogo: I18n::with_catalog fusiona 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.
  • Convención de metadatos (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. MetaTranslate devuelve el texto declarado cuando no hay entrada: nunca se imprime una clave.
  • Catálogos internos {en,es}.meta.toml: 130 DocTypes con descripción, 1.074 campos, workspaces, carpetas, grupos y temas (2.397 claves por idioma, paridad verificada).
  • Proyección localizada: RequestLocale negocia por petición (cuenta → Accept-Language → default) y /api/doctype/meta, /api/modules, /api/desk-layout, /api/ui-extensions y /api/themes devuelven las etiquetas ya traducidas. DynMeta gana label; los identificadores (name, fieldname, rutas, permisos) no se tocan.
  • Sitios: install-app copia locales/ al ámbito del sitio y el arranque lo fusiona.

Versión

0.4.0 en ambos Cargo.toml, ferris.wit, WIT_VERSION y FerrisDocs/project.json (cambio de contrato en 0.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 -- --check limpio; clippy sin avisos en líneas añadidas.
  • E2E con un sitio real: /api/doctype/meta/User en es devuelve label: Usuario y campos traducidos, /api/modules → Usuarios y /api/themes → Claro, con los identificadores intactos.

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.
@Stdg001
Stdg001 merged commit b6730a3 into develop Nov 23, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant