Translations & i18n
How to handle translations, interpolation, pluralization, and formatting in the frontend.
The translation system is built on i18next and exposed through alan-i18n. All user-facing strings must go through translation functions - never hardcode text in components.
import { t, tString, Trans } from "alan-i18n";
Quick reference
| I want to... | Use this |
|---|---|
| Display plain text | tString("ns:key") - returns string. Most cases: labels, placeholders, titles. Disables HTML escaping. |
Display text with <strong>, links, etc. | t("ns:key") - returns ReactNode. Uses global tag map (shared/common/i18n/tagToComponentMap.ts): <strong>, <em>, <a>, <highlight>, <ul>, <li>, <br>, <sup> |
| Bind tags to specific components or handlers | <Trans> - returns ReactNode. Re-exported as-is from react-i18next. For custom handlers, styles, or props. |
| Show an API error | tError({ key }) - returns string. Looks up error:<key>, falls back to a generic message. |
| Return a JSON array | tList("ns:key") - returns Array. Rare. |
| Pluralize based on count | Add _one/_other keys (ar also: _zero/_two/_few/_many), pass { count } |
| Handle French elision | {{val, elide_de_d}} in JSON |
| Handle gender agreement | {{val, mf_masc_fem}} in JSON |
| Format a date | {{- date, d mmmm yyyy}} in JSON, pass Date object |
| Format a number or percentage | Pre-format with formatNumberWithLocale / formatPercentage from alan-i18n, interpolate as string |
| Format currency | Pass new Currency(amount) as interpolation value |
| Format a duration or relative time | Use date-fns formatDuration / formatDistance with a date-fns/locale |
Playground
Try editing the JSON, key, and options to see how tString resolves translations.
Interpolation
Use double curly braces to inject values into translations.
{
"greeting": "Hello {{firstName}}, welcome to {{company}}!"
}
tString("app:greeting", { firstName: "Alice", company: "Alan" });
By default, tString disables HTML escaping. For t() (rich text), values are escaped to prevent XSS. To disable escaping for trusted values (URLs, formatted dates), prefix with -:
{
"link": "<a href=\"{{- url}}\">Click here</a>"
}
Only use {{- with trusted values (URLs from config, formatted dates). Never use it with user input.
Custom formatters
Use these when a raw interpolated value would produce incorrect grammar: gender agreement, article elision, pluralization, casing. Applied inline in the JSON with {{variable, formatter}} syntax. All formatters use underscore as a delimiter: formatterName_arg1_arg2. Arguments cannot contain underscores.
elide_: French article elision before vowels (de → d', que → qu'):
{ "account": "Sur le compte {{accountHolder, elide_de_d}}" }
tString("app:account", { accountHolder: "Alan" }); // → "Sur le compte d'Alan"
tString("app:account", { accountHolder: "Marie" }); // → "Sur le compte de Marie"
mf_: Gender agreement for French. The interpolated value must be a Gender string: "M", "F", or "X". Only "F" triggers the feminine form; everything else uses masculine as default.
{ "status": "Vous êtes {{gender, mf_inscrit_inscrite}} depuis le {{- date, d mmmm yyyy}}" }
// gender is "M", "F", "X", or undefined - typically from user.guessGender
tString("app:status", { gender: user.guessGender, date: user.since });
The mf function is also available as a direct import from string-utils for use outside translations:
import { mf } from "string-utils";
const label = mf(user.guessGender, "assuré", "assurée");
boolean_: Selects between two words based on a boolean:
{ "coverage": "You {{future, boolean_will be_are}} insured" }
capitalize: Capitalizes the first letter of the interpolated value.
genitive: Applies English genitive case ("Alice" → "Alice's", "James" → "James'").
Unicode
For non-standard whitespace characters like a non-breaking space, prefer a Unicode escape sequence in the JSON. This makes the intent clear and ensures special characters are visible in editors. For visible characters use the literal character.
Example: French typography requires a non-breaking space (U+00A0) before ?, !, ;, :, %, and inside « » guillemets. Use \u00A0 as this character would otherwise appear as a normal space.
{ "confirm": "Êtes-vous sûr\u00A0?" }
Pluralization
Use native CLDR plural keys — a _one and _other key (more for some languages) — and pass count:
{
"notification_one": "You have {{count}} new message",
"notification_other": "You have {{count}} new messages"
}
tString("app:notification", { count: 1 }); // → "You have 1 new message"
tString("app:notification", { count: 5 }); // → "You have 5 new messages"
The app uses compatibilityJSON: "v4"
:::info Which suffixes per locale?
Only the CLDR categories the locale actually uses (new Intl.PluralRules(locale).resolvedOptions().pluralCategories):
en,nl:_one,_otherfr,es:_one,_other,_many(rare)ar:_zero,_one,_two,_few,_many,_other
_one and _other are always required (the fallback);
count === 0 selects _zero in any locale if present (i18next special-case).
Adding a form a locale never selects (e.g. _few in en) is dead code — the check-plurals pre-commit hook flags it.
:::
Never use the legacy _plural/_singular suffix, manual singular/plural keys, or the pluralize_ formatter. They predate the v4 migration and are forbidden by the check-plurals pre-commit hook. Always native _one/_other (etc.) driven by count.
// Bad: untranslatable, ignores language rules
{
count === 1 ? "1 item" : `${count} items`;
}
// Good: use i18next
tString("app:item", { count });
Hardcoding count === 1 breaks for languages that treat 0 as singular (French, Spanish, Dutch) and cannot scale to languages with more plural forms (like Arabic). Always delegate to i18next.
Rich text
Simple tags with t()
Use t() when the translation string contains HTML-like tags that map to the global tag map:
// en.json: "disclaimer": "See our <strong>privacy policy</strong>."
<Text>{t("app:disclaimer")}</Text>
Custom components with <Trans>
Use <Trans> when tags need custom component instances with specific handlers, styles, or props:
{
"weather": "Today is a <greenText>{{dayType}}</greenText> day. Click <weatherModal>here</weatherModal> for the forecast."
}
<Trans
i18nKey="app:weather"
components={{
greenText: <Text color="green" />,
weatherModal: <A onPress={() => navigation.navigate("WeatherModal")} />,
}}
values={{ dayType: getDayType() }}
/>
The components keys must match the tag names in the JSON string. If you don't have variables, skip values. <Trans> also works for simple translations without custom components - <Trans i18nKey="key" /> and {t("key")} are equivalent.
Dates, numbers, and currency
Dates
Use {{- date, format}} with dateformat patterns. The - prefix is needed because formatted dates should not be HTML-escaped.
{
"updated": "Updated on {{- date, d mmmm yyyy}}"
}
tString("app:updated", { date: new Date("2025-03-01") });
// FR → "Updated on 1er mars 2025" (special French ordinal for day 1)
Always pass Date instances directly, never .toISOString() strings. toISOString() converts to UTC, which silently shifts the date by +-1 day depending on the user's timezone.
Numbers
No inline JSON formatter for plain numbers. Pre-format with formatNumberWithLocale or formatPercentage from alan-i18n, then interpolate as a string.
import { formatNumberWithLocale, formatPercentage } from "alan-i18n";
tString("app:score", { score: formatNumberWithLocale(3.14, 2) }); // fr → "3,14"
tString("app:happyShare", { share: formatPercentage(0.42) }); // fr → "42 %"
formatPercentage expects a value between 0 and 1. For money inputs, use CurrencyInput, which follows the locale's separators.
Currency
Use the Currency class from alan-i18n. It's auto-detected inside translations via instanceof Currency - no inline formatter needed.
import { Currency } from "alan-i18n";
tString("app:payment", { amount: new Currency(4200) });
// → "you have to pay 4 200 €"
For direct use outside translations, call formatAmountWithCurrency(value, decimalDigits, options) or formatCentsAmountWithCurrency(valueInCents, decimalDigits, options).
Time and durations
Prefer date-fns - notably formatDistance ("about 1 hour ago") and formatDuration ("2 hours 30 minutes"). Pass the matching locale from date-fns/locale for localized output.
Namespaces
Translations are organized by namespace. Each module/feature exports a namespace constant and registers translations per locale:
export const MEMBER_PROFILE = "member-profile";
// In app i18n.ts
resources: {
fr: { [MEMBER_PROFILE]: memberProfileFrTranslations },
en: { [MEMBER_PROFILE]: memberProfileEnTranslations },
}
Use the namespace as a prefix: tString("member-profile:settings.title").
Common namespaces: app (per country app), common (shared strings), error (for tError), plus feature/module names like walk, selfServe, support.
Most translations are loaded statically at i18n.init(). Modules can register dynamically with i18n.addResourceBundle() / removeResourceBundle() (reference-counted).
Key naming
Keys should describe the content and be written in English, so the whole team can reason about them regardless of the locale the string is translated into. Migrating existing French keys to English is not a priority; follow this convention for new keys.
{ "settings.notifications.title": "Notifications" }
{ "parametres.notifications.titre": "Notifications" }
File structure
Translation files use nested JSON. Access nested keys with dot notation.
{
"settings": {
"title": "Settings",
"notifications": {
"enable": "Enable notifications"
}
},
"employee_one": "{{count}} employee",
"employee_other": "{{count}} employees"
}
tString("app:settings.notifications.enable");
Verification and tooling
Debug mode
Use "Enable i18n key debug mode" in the DevTools menu on web and mobile to render raw translation keys instead of translated strings.
i18next/no-literal-string
ESLint rule that catches hardcoded strings in JSX. Configured via eslint-plugin-alan at error or warning level (alan.configs.i18nError / alan.configs.i18nWarn).
yarn check:translations
Runs i18n-extract (built on i18next-parser) across all workspaces in CI. Detects missing keys, unused keys, and inconsistencies between code and JSON files. Each app has its own i18n-extract.config.ts. Dynamic keys not found by the static scan can be added to ignoreKeys in the config.
alan i18n check-quebecois-terms
Checks fr-CA.json files for FR-FR terms that should use Quebecois equivalents. Blocking, both in CI and as a pre-commit hook. Legitimate FR-FR terms (brand names, FR-only keys) go in apps/cli/src/data/quebecois-glossary-exceptions.jsonc.
@alaneu/i18n-transform-hardcoded-strings
Babel codemod that extracts hardcoded strings into tString() / t() / <Trans> calls and generates JSON files. See shared/i18n-transform-hardcoded-strings/INSTRUCTIONS.md.
Claude Code skills
Claude Code skills are non-deterministic. Always double-check their output before merging. When in doubt, send a message in #translation_requests and ping the relevant @{language}translation_reviewers group.
/extract-i18n-strings
Extract hardcoded strings from TS/TSX into tString() / t() / <Trans> calls and JSON. Auto-chains into /translate for non-source locales.
/extract-i18n-strings frontend/packages/foo/src/screens/BarScreen.tsx
/translate
Translate raw strings or JSON blocks into any of fr, fr-CA, en, es, nl, ar. Aware of i18next interpolation and custom formatters. Keys, variables, and formatter syntax are preserved, and rewritten where the target locale needs a different formatter.
/translate "La couverture {{firstName, elide_de_d}} commence aujourd'hui" to en
The example above returns:
{{ firstName, genitive }} coverage starts today
Each language has its own subagent with locale-aware formatter rules. The French elide_de_d is rewritten to the English genitive automatically.