DocsFrontend

Translations

Every word of the app in every language it speaks, edited live in the page by translators working together.

Translations live in i18n.json, one entry per phrase with a value per language. Translators edit them in the admin or right on the page, and every open page updates without a reload. To translate an app, list its languages and phrases:

app/i18n.json
{
  "locales": ["en", "fr", "de"],
  "orders": { "en": "orders", "fr": "commandes", "de": "bestellungen" },
  "welcome": { "en": "welcome to {{app}}, {{name}}", "fr": "bienvenue sur {{app}}, {{name}}" }
}

Features include:

  • One file, with English as the fallback and gaps that show instead of going blank
  • Case changes such as |title, so one entry serves “orders” and “Orders”
  • t() that stays current in JSX when the language or a translation changes
  • Editing in place on the page, together, with drafts published in one step
  • Session links for guests without an account

The file

  • Keys are lower case.
  • {{name}} is filled in from the params you pass. {{app}} is always the app’s name.
  • Missing languages fall back to English. A key missing in English too shows as ?[key.locale], so gaps are visible instead of blank.

Use it in the app

app/i18n.ts
import { createI18n } from "@sluurp/client/i18n";
import table from "./i18n.json" with { type: "json" };

export const i18n = createI18n({ table, appName: "My app" });
export const t = i18n.t;
i18n.connect(sluurp);   // live updates
app/header.tsx
<h1>{t("orders|title")}</h1>          // "Orders"
<p>{t("welcome", { name: me.first_name })}</p>
  • |title, |upper and |lower change case, so “orders” and “Orders” don’t need separate entries.
  • In JSX, t(…) stays current with no arrow function to write: i18n.setLocale("fr") or a translator’s edit updates it. Outside JSX, a plain t("x") is read once, so wrap it in computed if it should follow the language.
  • The server merges published edits into i18n.json when serving it, so the import is always current.

Translate

  • In the admin: Translations lists every key with a field per language.
  • In place: turn on translate mode, click any text and edit it where it appears. Clicks go to the editor, so links don’t navigate.
  • Together: a translation session holds drafts only its translators see. Everyone’s cursor shows in their colour, typing appears live, and the session is published in one step.
  • Guests: a session link lets someone without an account edit, but not publish.

Only people with the translator role can translate. The registry components’ own words (Close, Search…, month names) come translated, in lib/words.ts. sluurp i18n lists keys no longer used.

View as Markdown