Strings and translation
Every word the web game shows or says (text, aria-label, title, alt, the tab’s title, card
names for screen readers, refusals) comes from one catalog, design/strings/en.json. The plan and
its decisions are in plans/i18n.md; this page is how to work with it. The web game
speaks English and Spanish from Spain (design/strings/es.json, written from
glossary-es.md). iOS (L4) and Android (L5) will generate their own files from the
same catalog.
The catalog
Each key is a dotted name, grouped by area, with an ICU message and a note for translators:
"cards.count": { "message": "{count, plural, one {1 card} other {# cards}}", "description": "A number of cards (a seat's hand, the pile)." }| Area | Keys |
|---|---|
| Rule refusals, by the engine’s code | refusal.<code>.title, .detail (and .detailNoMinimum, .detailNoPoints when the context lacks a number) |
| Server refusals, by the server’s code | serverError.<code>.title, .detail; serverError.unknown.* for a code without words |
| Cards and melds | card.rank.<rank>, card.suit.<S/H/D/C>, card.name, meld.rank.<rank>, meld.short.<rank>, meld.kind.<kind> |
| Rule sets | ruleset.<id>.name, the id in camel case (modern-american is ruleset.modernAmerican.name; the engine’s name for a rule set without one) |
| Screens | home.*, root.*, table.*, action.*, status.*, score.*, online.*, … |
The ICU subset, which every platform can express: {name} (as it is), {name, number} (the
locale’s format), and at most one {name, plural, =0 {…} one {…} other {…}} or
{name, select, a {…} other {…}} per message, never nested; # in a plural is the number,
formatted. Braces are never literal text; an apostrophe is. bin/gen-strings rejects anything
else. Prefer phrasing around gender to a select on a player (plans/i18n.md, “The ICU subset”).
Codes, never sentences. The engine and the server answer with codes; the screen looks the code
up (lookup in web/src/i18n.ts). Never show an error’s message: it is English for logs.
spec/errors.json lists every code; bin/gen-strings fails when a rule code or a server code
(outside kind protocol) has no words.
Translations
A translation sits beside en.json, named for its locale (es.json), with every English key and a
message only: the English description serves both. bin/gen-strings fails when a translation
lacks a key or has one English doesn’t, when a message changes an argument’s name or kind, drops a
select’s choice or a plural’s branch (one, other, an exact =N), or leaves the ICU subset. A
plural may add the language’s own forms (Spanish has one, many and other; a missing many
falls back to other). Each
translation becomes web/src/strings.<locale>.generated.ts, a chunk the page fetches only when that
language is chosen.
Spanish is Spain’s: tú to one player, vosotros to several, and one word per concept, pinned in glossary-es.md. Changing a pinned word takes a new decision there first.
Adding or changing a string
- Add the key to
design/strings/en.jsonwith itsmessageand adescriptionthat says where it shows and what each argument is. One message per sentence: no gluing pieces together, except a complete noun phrase passed as an argument (a card’s name, a side’s name). - Add the same key to
design/strings/es.jsonwith its Spanishmessage(the glossary’s words). Eduardo reviews every Spanish key. - Run
bin/gen-strings. It rewritesweb/src/strings.generated.ts(the keys, their arguments’ types and the English functions),web/src/strings.pseudo.generated.ts(theen-XApseudo-locale) andweb/src/strings.es.generated.ts. Commit them; never edit them. - Use it:
t("cards.count", { count })fromweb/src/i18n.tsis typed, so a missing key or a wrong argument failsnpm run typecheck. A key built from a code goes throughlookup(`refusal.${code}.title`), which answers null for a key the catalog lacks. To bold an argument,rich("stock.caption", { count }, { count: (text) => <b>{text}</b> })fromweb/src/rich.tsxkeeps the sentence whole. - Numbers that are not in a message go through
formatNumber, and any otherIntlcall takeslocale().
The locale
web/src/main.tsx picks the language once, before the first render: resolveLocale reads the
locale setting in homefelt.settings (missing or "system" follows navigator.languages) and
matches it on the language (en-GB is en), falling back to English. setLocale loads that
catalog and sets <html lang> and dir. The pseudo-locale en-XA is chosen only by name in the
setting, never from the browser, and no screen offers it.
A link from the Spanish marketing site adds ?lang=es: main.tsx saves it as the setting before
the first render and drops it from the address (docs/marketing-site.md, “Languages”).
The Language switch, in Settings on the home page and at the table, offers
Automatic ("system"), English and Español, each language named in itself. Choosing one loads
that catalog, sets <html lang> and the tab’s title, and draws the page again in place, so focus
stays on the choice (arrow keys select as they move). Text a model built earlier (a refusal card on
screen, the connection banner) keeps its words until it is replaced. When choices come quickly, the
last one wins; when a catalog can’t load, the page keeps its language and says so under the choice. The choice is saved with the
other settings and stays in this browser: it doesn’t follow the account (decision 0011).
A seat in a sentence
A seat without a person’s name has two forms: seat.player on its own (“Jugador 1”, a seat’s label
or a player addressed: “Jugador 1: selecciona cartas…”) and seat.playerRef inside a sentence
about the player, which in Spanish carries its article (“el jugador 1”). seatRef in each platform
picks it. The runtime’s grammar then contracts Spanish “de el” and “a el” and capitalises a
sentence that starts with the article: “Turno del jugador 1”, “El jugador 1 pregunta al jugador 3”.
A person’s own name goes in as it is (“Turno de Abuela”). An online player who has not chosen a
name (nameChosen false) has no name to the screens, never the server’s stored text: shownName in
web/src/tableModel.ts answers null, so their seat shows by its number like a hot-seat one.
player.unnamed is only your own name line, which has no seat.
The apps
bin/gen-strings also writes the iPhone and Android apps’ words from the same catalog, every key
in every language:
| iPhone | Android | |
|---|---|---|
| Messages | swift/App/Sources/Localizable.xcstrings |
kotlin/app/src/main/res/values/strings.xml, values-es/strings.xml |
| Accessors | Strings.generated.swift: Strings.tableNewGame, Strings.cardsCount(count: 2) |
Strings.generated.kt: Strings.tableNewGame(r), Strings.cardsCount(r, 2) (r: Resources) |
| Runtime | Localization.swift |
Localization.kt |
An accessor’s name is the key’s, with the dots dropped (refusal.pileFrozen.title is
refusalPileFrozenTitle). A key built from a code goes through Localization.lookup, which
answers nil (null) for a key the catalog lacks. Arguments are typed as in the web (Int for
{n, number} and plurals, else String). They reach the native string as text, numbers formatted
for the language first: 1500 and 10.000 in Spanish. A plural becomes the whole message in each
form. Android picks the form itself (<plurals>). iOS keeps one key per form (cards.count#one)
and picks it with Localization.pluralForm, which knows English and Spanish: a new language adds
its rule there. The apps take no select and no exact =N branch yet; the generator says so if a
message uses one.
The language is the app’s own. iOS lists it in Settings › Canasta › Language once the app has two
localizations (knownRegions in project.yml). The app’s Settings sheet has a Language row that opens that page
(UIApplication.openSettingsURLString); the app never writes AppleLanguages. iOS tests speak Spanish
through Localization.$testLanguage.withValue("es") { … } (task-local, so parallel tests keep
English), and SpanishUITests launches the app with -AppleLanguages (es). Android 13 and later list it in the system’s app
languages (generateLocaleConfig, with localeFilters keeping it to en and es).
Android also has its own Language setting (Settings: Automatic, English, Español, each named in
itself; AppLanguage in DisplaySettings.kt). It calls AppCompatDelegate.setApplicationLocales,
so MainActivity is an AppCompatActivity and the manifest’s AppLocalesMetadataHolderService
(autoStoreLocales) keeps the choice before Android 13. android.icu ignores Spanish’s minimum
grouping and writes 1.500, so Localization.number leaves the separator out below 10.000 for the
languages it lists. aapt2 trims a resource’s outer spaces, so the generator writes them as \u0020
(list.separator is “, “). Code that isn’t a composable takes the Resources (seatName(r, …),
Refusal.title(r)); models keep catalog keys (Refusal.detailKey, HandScoreRow.labelKey), which the
JVM tests check, and src/androidTest/LocalizationTest checks the words in both languages.
web/test/strings.test.ts counts a key as used when an app calls its accessor.
Testing
bin/test strings runs bin/gen-strings --check and web/test/strings.test.ts:
- every key the code names exists, and every key is named (literally, by a
lookuppattern, by the apps, or as a coach text or title of aspec/tutorialsfile); - no JSX in
web/srcwrites words of its own: text nodes, text props (aria-label,title,alt,placeholder,label,legend,lead, …) andtitle/detailfields with literal letters fail. Symbols (★, ⚠) are allowed; - every code in
spec/errors.jsonhas words; - the plural and number runtime (
web/src/icu.ts) and the locale choice.
web/e2e/localeScreens.ts holds the screen checks below for any locale. web/e2e/pseudo.spec.ts
renders the home page, the /canasta table, a refusal and online play
in en-XA (every letter accented, each message about 35% longer, in ⟦ ⟧) on a 390 px phone at
Standard and Large text, and fails when the page scrolls sideways. A word without brackets on
those screens skipped the catalog. E2E_LOCALE_SHOTS=<dir> npm run e2e -- pseudo es saves
screenshots. web/e2e/es.spec.ts runs the same screens in Spanish, chosen by an es-ES browser,
and the Language switch there and back. To look by hand, set {"locale":"en-XA"} in homefelt.settings (with deck and
text) in the browser’s storage and reload.