Skip to content

One string catalog for every platform, and codes instead of prose

Context and problem

Eduardo wants his Spanish family to play Homefelt in Spanish (#138). Until now every string was English and written separately on each platform: the web game had its own wordings.ts, the apps their own text, and some messages came straight from the server or a rules engine as English sentences. Translating that as it stood would mean finding and translating the same sentence up to five times, and server English would still leak onto the screen. The plan is docs/plans/i18n.md.

Options considered

  1. Native catalogs per platform: .xcstrings on iOS, strings.xml on Android, JSON on the web, each written by hand. The closest to Reflex’s “no shared production code”.
  2. One shared catalog, generated into each platform’s format, the way bin/gen-theme already shares the design tokens.
  3. An i18n library on the web (FormatJS, i18next) on top of either.

Decision

We chose option 2, with no library:

  • design/strings/en.json (and later es.json) holds every user-facing string as an ICU message, keyed by area (table.draw, refusal.pileFrozen), each with a note for translators.
  • bin/gen-strings generates typed TypeScript for the web now; iOS (.xcstrings) and Android (strings.xml) outputs come with the apps’ localization. Its --check mode runs in bin/test.
  • Messages are compiled into small functions at build time. Plurals and numbers use the platform’s own Intl.PluralRules and Intl.NumberFormat: no parser and no new dependency.
  • Codes, not prose. Servers and rules engines answer with codes. spec/errors.json lists every rule and server code, the build fails if one has no words in the catalog, and clients never show a server’s English message; an unknown code gets a generic catalog sentence.
  • A pseudo-locale (en-XA, accented and longer) is used in tests, with checks that text is never clipped horizontally or vertically at phone width and Large text.

Consequences

  • Good: each sentence is translated once per language, and every platform says the same thing.
  • Good: a refusal or a server error can appear in any language, because only its code travels.
  • Good: long Spanish text is caught by tests before anyone sees it; the first pseudo-locale run found a status line that scrolled out of view at Large text, fixed in #144.
  • Bad: one more generator to maintain, and strings are now shared data across platforms. Like the design tokens, they are data, not logic, so Reflex’s rule still holds for code.
  • Bad: every new user-facing string needs a key and a note, and a regenerate step.

More information