Localization and internationalization across Homefelt
Summary. Homefelt is English only, and every platform writes its own English today: the
33 rule refusals are copied by hand three times (swift/App/Sources/Refusal.swift,
kotlin/app/src/main/kotlin/canasta/app/Refusal.kt, web/src/refusal.ts), there is no
strings.xml or .xcstrings file, and plurals are written as n === 1 ? "1 card" : .... Spanish
is planned next (docs/plans/spanish-deck.md). Key decisions:
- One shared catalog, generated into native formats.
design/strings/en.jsonandes.jsonhold ICU messages. A newbin/gen-stringsturns them into a String Catalog, Androidstrings.xmland typed TypeScript, the same waybin/gen-themehandles tokens. The catalog is data, likespec/rulesets/anddesign/tokens.json, so it fits Reflex. - The platform formats; we add no i18n dependency. The generator compiles each message into
a plain function at build time. On the web and the site those functions call
Intl.PluralRulesandIntl.NumberFormat.Intl.MessageFormatis not usable yet, and FormatJS is the fallback. - One Spanish,
es, written as Spain’s Spanish (decision 0011). Sparse regional files (es-419,es-AR) can override single keys later. The stores get the same copy under each Spanish locale.
1. Principles
| Rule | What it means here |
|---|---|
| Codes, never sentences | The cores already return RuleError codes with a numeric context (spec/README.md “Errors”, “Rule error context”). The server returns kind + code. Its English message stays for logs and developers, and no client ever shows it |
| Every user-facing string is in the catalog | That covers UI text, accessibility labels, refusals, card names, rule wording and store copy. A user’s own content (display names, custom rule-set names) is not translated |
| Plurals and agreement use ICU | Messages use {n, plural, one {…} other {…}}. Spanish also has the CLDR many category (“1.000.000 de días”) |
| Numbers and dates use the platform | Intl.NumberFormat(locale), .formatted(), NumberFormat.getIntegerInstance(locale). web/src/TableView.tsx:22 and HandScoreView.tsx:33 hard-code "en" today |
| No concatenation | "Hand \(game.hand) is over", "Add to \(rank.code)s" and `Meld ${count} cards` become one message each. A message may insert another key’s output only when that output is a complete noun phrase (a card name, a meld name) |
| Logical layout | CSS uses margin-inline-*, padding-inline and text-align: start. SwiftUI uses leading/trailing and Compose uses start/end. Set dir and lang on <html>. RTL is not a target, but nothing may assume left-to-right |
The ICU subset. Messages may use {name}, {n, number} and {n, plural, =0 {…} one {…} many {…} other {…}}, with at most one plural per message and no nesting. They may not use
select, so there is no gender switch on players: copy is phrased around gender instead. Card
gender is fixed (“carta” is feminine, so “seleccionada” is a constant). The generator rejects
anything outside the subset, which keeps every target able to express every message.
Today’s leaks to close
- The web shows the server’s
message.web/src/online/wordings.ts:34falls back to the server message for an unknown code. Fix it with a generic localized card that names the code. - Raw error text reaches the screen. The web shows the CLI’s error text as
saveProblem(web/src/nodeState.ts:165), and “Something went wrong” showserror.message. - The server stores an English name.
rust/canasta-server/src/db/users.rs:34stores"Player"as the default display name, and other players see it. Change it so the seat view carriesnameChosen: falseand each client rendersplayer.unnamedin the viewer’s language. This changes the protocol, so change the spec first (spec/protocol/server.md). - Rule codes need a machine-readable list. They exist only as a Markdown table and three
enums. Add
spec/errors.json(rule codes plus serverkind/codepairs). The cores test theirRuleErroragainst it, andgen-stringschecks that every code has its keys.
2. Source of truth: one catalog, generated
design/strings/ en.json source language; each key has "message" and "description" (translator note) es.json same keys; "message" only glossary.md pinned game terms per language (canasta, comodín, ...)bin/gen-strings Python, like bin/gen-theme; --check fails when generated files differKeys are flat and namespaced. Rule refusals are refusal.<code>.title and
refusal.<code>.detail, server refusals are online.<code>.*, and card names are
card.rank.A, card.suit.S, card.name (“{rank} of {suit}” / “{rank} de {suit}”) and
card.selected. Meld names are meld.rank.K (en “Kings”, es “los reyes”). Rule sets use
ruleset.<id>.name. Rule wording is rules.<settingPath>.<value>, which moves the site’s
sentence templates (docs/marketing-site.md, “Rules pages are generated”) into the catalog. When
platforms need different words (“tap” or “click”), a platform suffix overrides the base key
(hint.selectCard.web).
| Target | Generated files | Runtime |
|---|---|---|
| iOS | swift/App/Sources/Localizable.xcstrings (every key extractionState: manual, plurals as variations.plural), Strings.generated.swift (typed accessors) |
Foundation String(localized:). Set SWIFT_EMIT_LOC_STRINGS: NO in project.yml so Xcode adds no extracted literals, and list knownRegions: [en, es] |
| Android | kotlin/app/src/main/res/values/strings.xml, values-es/strings.xml (<plurals>, positional %1$s), res/resources.properties (unqualifiedResLocale=en), Strings.generated.kt (maps RuleError to R.string ids, mirroring the Swift file) |
stringResource and pluralStringResource(id, n, formatted(n)): the count picks the form and the formatted number is what shows |
| Web | web/src/strings.generated.ts: one function per key per locale. English loads eagerly and Spanish as a lazy chunk |
about 40 lines in web/src/i18n.ts: the active locale, cached Intl.PluralRules and Intl.NumberFormat |
| Site | site/src/strings.generated.ts (same generator, same shape) |
Build time only; no client script |
| Server | nothing | stays code-first |
Why not native catalogs per platform? Reflex favours platform ownership, and native tools are good (Xcode extraction and translation state, Android Studio’s translations editor). But most of our strings are shared meaning keyed by spec codes, and the refusals are already copied verbatim three times: the drift a translation multiplies. Like rule sets and tokens, a generated catalog is data; each platform still runs only its own APIs. The cost is the generator and losing Xcode’s auto-extraction, which the lint in §5 replaces. Decision: shared catalog.
Why not Intl.MessageFormat or FormatJS? The TC39 proposal is at Stage 1, parses
MessageFormat 2 rather than ICU syntax, and ships in no browser. FormatJS’s intl-messageformat
can drop its parser with precompiled ASTs, but it is still a runtime dependency for work our
subset doesn’t need. Build-time compilation gives typed keys and no parser. If the subset grows
(say, selectordinal), the generated TypeScript switches to FormatJS ASTs with the same keys.
3. What gets localized
| Area | Count today (rough grep) |
Notes |
|---|---|---|
iOS UI (swift/App/Sources) |
~155 literals, 55 interpolated | 66 are the refusal titles and details |
Android UI (kotlin/app/src/main) |
~155 literals, 56 interpolated | mirrors iOS; no strings.xml exists |
Web (web/src) |
~350 unique literals, ~155 template strings | includes refusal.ts (66) and online/wordings.ts (~44 codes × 2) |
Site (site/src) |
~2,500 words over 4 pages and the layout | long-form copy, not keys |
Server (rust/canasta-server) |
~66 English messages | not localized: they become developer text |
| Cores | 33 rule codes, no prose | nothing to translate; context is numbers |
That comes to roughly 400–500 catalog keys once the duplicates merge.
- Refusals:
refusal.<code>fromRuleErrorand itscontext(minimum,points);online.<code>for server kinds. - Rule-set descriptions:
rules.*templates build/es/canasta/rulesand/es/canasta/family-rulesfrom the samespec/rulesets/*.json; the “no template, build fails” check runs per locale. - Card names for screen readers: “Ace of spades” / “As de picas”, “Joker” / “Comodín”,
“…, seleccionada” when selected. Spanish keeps “canasta” and says “comodín” for a wild card;
glossary.mdsettles meld, pile, stock, frozen and going out. The decided Spanish terms are indocs/glossary-es.md. The Spanish deck’s names (“Caballo de copas”) use the same keys (spanish-deck.md §2). - Store listings and screenshots: source in
design/store/<locale>/(name, subtitle, description, keywords, release notes), with a test against the store field limits; Spanish screenshots from the same capture run. - Marketing site: Astro i18n routing,
defaultLocale: "en",locales: ["en", "es"],prefixDefaultLocale: false, so English stays at/and Spanish lives under/es/. Long-form pages get one file per locale (src/pages/es/accessibility.astro).Base.astrowrites<html lang>,hreflangforen,esandx-default, and a footer language link;@astrojs/sitemapwith itsi18noption lists the alternates. No browser-language redirect: the site is static and sets no cookies. - Emails and notifications: none today. When they arrive, the server renders them from the
same catalog in the recipient’s stored
locale(§4). - Update and sunset messages (docs/plans/app-messaging.md): fixed prompts (“Update
required”) are catalog keys. A notice written after a build shipped can’t be in its catalog,
so the feed carries text per locale (
{"en": "…", "es": "…"}), falling back toen: content, not UI, and the one exception to “codes, not sentences”.
4. Locale choice
The order: a per-user override, then the device’s language list matched against en and es,
then en.
| Platform | Override | Where it is stored |
|---|---|---|
| iOS | A “Language” row opens the app’s page in Settings (UIApplication.openSettingsURLString). iOS adds the per-app language picker there once the app has two localizations. Apple says in-app switching is unsupported, so don’t write AppleLanguages |
the system |
| Android | An in-app picker calls AppCompatDelegate.setApplicationLocales. MainActivity moves from ComponentActivity to AppCompatActivity; minSdk 29 needs autoStoreLocales. Turn on generateLocaleConfig so Android 13+ lists the app in system settings |
the system / AppCompat |
| Web | homefelt.settings.language: "system", "en" or "es", beside deck and text in web/src/settings.ts. "system" reads navigator.languages |
localStorage |
| Server | Nothing for now: the choice stays on each device (decision 0011) | none |
A server copy (a locale column on users, PATCH /me) waits until email, push or invite pages
need a language. Native apps never override the system.
es-ES or es-419? One Spanish, Spain’s. With ~540 keys, two full catalogs double the review
for a small difference. The first players are Eduardo’s family in Spain, so es is written as
Spain’s Spanish: tú to one player, vosotros to several, and the terms Eduardo picks in
docs/glossary-es.md (decision 0011). Fallback runs es-AR → es-419 → es → en, so a regional file lists only the
keys it changes. The stores take the same copy under App Store Connect’s Spanish (Spain) and
Spanish (Mexico), and Play’s es-ES, es-419 and es-US.
5. Workflow and tests
Who translates. For UI strings, Claude drafts es.json from en.json, each key’s
description and the glossary; Eduardo reviews every key. Store copy and the privacy page get a
professional or native-speaker review. Play Console sells listing translation from about USD 0.07
a word, and its free machine translation (es-ES, es-419) is a draft, not something to publish.
Pseudo-localization. gen-strings also emits a pseudo locale (en-XA on Android, a
debug-only localization on iOS, ?lang=pseudo on the web): every letter accented, each message
padded 40% and wrapped in ⟦ ⟧, so truncation and hard-coded strings show up before Spanish
exists.
Checks in bin/test, in a new strings target and the platform targets:
| Check | Where |
|---|---|
bin/gen-strings --check: the generated files match the catalog |
strings |
Every key exists in every language, with the same argument names and plural argument; the ICU subset parses; description is set |
strings |
Every code in spec/errors.json has refusal.* or online.* keys; every rule-set path has a rules.* key |
strings |
No literal UI strings: a grep fails on Text(" with a literal in Swift and Kotlin UI files, and on JSX text nodes in web/src (an allowlist covers symbols) |
swift, kotlin, wasm/web |
Numbers in es: 1500 shows as “1500” and 10000 as “10.000” (CLDR minimum grouping) on all four. If Android’s java.text.NumberFormat disagrees, use android.icu.text.NumberFormat |
each platform |
Spanish screens: Playwright e2e with locale: "es-ES", axe on each page, Large text at 320px. The site’s e2e adds /es/ pages to its light/dark × text-size runs. iOS UI tests launch in Spanish at the largest Dynamic Type size; Android runs Compose previews with locale = "es" and fontScale = 2f |
site, web e2e, apps |
The layout risk for older players. Spanish runs longer, and Large text multiplies it. The
site’s promise “A hand that wraps, never shrinks” applies to copy too: no lineLimit(1) or
maxLines = 1 on prose or buttons, action-bar buttons wrap to two lines before they shrink,
refusal cards grow, and only user names may truncate. The pseudo locale at Large text gates every
UI PR.
6. Phased rollout
Each checkpoint is one issue and one small PR across the spec and all platforms, as AGENTS.md
asks.
| Phase | Checkpoints | Done when | Effort |
|---|---|---|---|
| 0. Codes only | spec/errors.json and core tests; the unnamed player as nameChosen in the seat view; clients stop showing message |
No server or engine prose reaches a screen | 0.5–1 day |
| 1. Extraction (English only) | 1a bin/gen-strings, en.json, refusals and online wordings replace Refusal.* and wordings.ts. 1b card names and accessibility labels. 1c the rest of the UI, plurals, Intl locale fix. 1d the pseudo locale, the lint and the key checks in bin/test |
Pseudo locale renders on all three apps; no visible English change | 3–5 days |
| 2. Spanish in the apps and the web | 2a glossary.md (with Eduardo), then es.json drafted and reviewed. 2b locale choice: iOS Settings row, Android AppCompat picker, web setting. The web game goes first (decision 0011). 2c Spanish screenshot and Large-text tests |
A family can play a full game in Spanish on every platform | 3–4 days, plus about 1 day of Eduardo’s review |
| 3. The site | 3a Astro i18n, Base.astro lang and hreflang, sitemap, language link. 3b /es/ home, Canasta and how-to-play. 3c generated rules pages in Spanish. 3d accessibility and privacy, reviewed |
/es/ passes the site’s e2e and link check |
2–3 days |
| 4. The stores | design/store/en and es, the length test, Spanish screenshots, uploads to the es-ES/es-MX and es-ES/es-419/es-US locales |
Spanish listings live | 1–2 days, plus a professional review |
Phases 1 and 3a can run in parallel. The Spanish deck’s card names (spanish-deck.md) go in once phase 1b lands.
Open questions for Eduardo
Spain or Latin America first.Decided: Spain (decision 0011).The glossary.Decided 2026-11-24:docs/glossary-es.mdpins every term (meld, pile, stock, frozen pile, going out, natural and mixed canasta, and the rest) forglossary.md.- Translation for the stores and privacy. Will you review all the Spanish yourself, or pay for a professional pass on the store copy and the privacy page?
Does the language follow the account?Decided: no, it stays per device (decision 0011).- Which language ships with the first Spanish-deck game? Should Chinchón (spanish-deck.md) ship in Spanish only at first, or in both languages?
Sources opened
- Apple, “Discover String Catalogs” (WWDC23): https://developer.apple.com/videos/play/wwdc2023/10155/
- Apple forums on in-app language switching and
openSettingsURLString: https://developer.apple.com/forums/thread/741550 - App Store localizations: https://developer.apple.com/help/app-store-connect/reference/app-store-localizations/
- Android string resources and plurals: https://developer.android.com/guide/topics/resources/string-resource
- Android per-app languages: https://developer.android.com/guide/topics/resources/app-languages
- Google Play listing translation: https://support.google.com/googleplay/android-developer/answer/9844778
- TC39
Intl.MessageFormat(Stage 1, MF2): https://github.com/tc39/proposal-intl-messageformat - MDN
Intl.PluralRules(widely available since 2019): https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/PluralRules - FormatJS
intl-messageformat: https://formatjs.github.io/docs/intl-messageformat/ - CLDR plural rules (Spanish one/many/other): https://www.unicode.org/cldr/charts/latest/supplemental/language_plural_rules.html
- Astro i18n routing: https://docs.astro.build/en/guides/internationalization/
- Astro sitemap
i18n: https://docs.astro.build/en/guides/integrations-guide/sitemap/