Translations in a plugin
Translations in a plugin
Section intitulée « Translations in a plugin »The shell ships English and French. A plugin declares its own texts; they are registered while the plugin is active and removed when it is disabled.
export default { id: "clock", name: "Clock", messages: { en: { name: "Clock", "command.announce": "Clock: Announce the time" }, fr: { name: "Horloge", "command.announce": "Horloge : Annoncer l'heure" }, }, setup(ctx) { ctx.registerCommand({ id: "clock.announce", title: ctx.i18n.key("command.announce"), // full key, resolved by the shell event: "clock/announce", });
ctx.emit("shell/status.set", { text: ctx.i18n.t("status.now", { time: "12:00" }) }); },};Rules:
- Keys are automatically prefixed with the plugin id, so
command.announcebecomesclock.command.announce.ctx.i18n.key(k)returns that full key. ctx.i18n.t(key, params)interpolates{name}placeholders. Missing keys fall back to English, then to the key itself — so plain strings still work.- Command titles, panel titles and status texts are translated by the shell at render time: pass a key, not a finished string.
- In React components, use
useT()from@/kernelwith the full key so the UI re-renders when the language changes. ctx.i18n.formatDate/ctx.i18n.formatNumberformat with the active locale.- The
namekey is used as the plugin label in the command palette. - The language lives in the core store slice, so it persists on the web and in
the desktop app. Change it with
emit("i18n/locale.set", { locale: "fr" }).
Documentation sous licence CC BY 4.0 · © les contributeurs de SCFlow ·Retour à supplychainflow.org