# gander languages: a game's text in the player's language A game's text in several languages: one JSON file per language in assets/lang/, `gander::tr(key)` where the text is drawn, plural forms, numbers written each language's way, a Language tab in Settings, and the fonts each language needs (gander build makes them). The engine's own menus, settings, save screens and score tables come translated into 18 languages already. A game adds its own text. ## The files One file per language, named by its code, in `assets/lang/`: ``` assets/lang/en.json English (the source language unless lang_source says otherwise) assets/lang/fr.json French assets/lang/ja.json Japanese assets/lang/pt-BR.json Portuguese as spoken in Brazil assets/lang/zh-Hans.json Chinese, simplified characters ``` Codes gander knows (the file name must be one of these, or the engine never finds it): `en en-GB en-US fr fr-CA de es es-419 es-MX it pt pt-BR pt-PT nl sv da nb no fi is pl cs sk hu ro bg el ru uk be kk tr et lv lt hr sr sl ca eu gl id ms vi fil sw af th ja ko zh-Hans zh-Hant zh-CN zh-TW` (and `ar he fa hi`, which draw unshaped: see Limits). A file is keys to text. Nested objects join their names with dots, so these two are the same key, `menu.play`: ```json { "menu": { "play": "Jouer", "quit": "Quitter" } } { "menu.play": "Jouer", "menu.quit": "Quitter" } ``` A whole game's text, English (`assets/lang/en.json`): ```json { "title": "Lantern Keeper", "menu": { "tap_to_start": "Tap to start" }, "hud": { "score": "Score: {0}", "lanterns": { "one": "{n} lantern lit", "other": "{n} lanterns lit" } }, "dialogue": { "keeper_1": "The ships come home at dawn.", "keeper_2": "Light the harbour lantern first, {0}." }, "over": { "win": "Every lantern burns", "lose": "The fog took the harbour" } } ``` and French (`assets/lang/fr.json`), same keys: ```json { "title": "Le Gardien des lanternes", "menu": { "tap_to_start": "Touchez pour commencer" }, "hud": { "score": "Score : {0}", "lanterns": { "one": "{n} lanterne allumée", "other": "{n} lanternes allumées" } }, "dialogue": { "keeper_1": "Les navires rentrent à l'aube.", "keeper_2": "Allume d'abord la lanterne du port, {0}." }, "over": { "win": "Toutes les lanternes brûlent", "lose": "Le brouillard a pris le port" } } ``` ## Drawing text ```goose // in frame(): call tr where the text is drawn, every frame gander::text(gander::DEFAULT_FONT, gander::tr("title"), 40.0, 40.0, 48.0, gander::WHITE, gander::ALIGN_LEFT); let s = gander::text(gander::DEFAULT_FONT, gander::tr("hud.score", gander::number(score as f64)), 20.0, 20.0, 24.0, gander::WHITE, gander::ALIGN_LEFT); let l = gander::text(gander::DEFAULT_FONT, gander::tr_n("hud.lanterns", lit), 20.0, 50.0, 24.0, gander::YELLOW, gander::ALIGN_LEFT); if gander::flow_update(flow, gander::tr("title"), gander::tr("menu.tap_to_start")) { ... } gander::flow_game_over(flow, gander::tr("over.win"), gander::tr("hud.score", str(score))); let k = gander::dialogue(gander::tr("names.keeper"), gander::tr("dialogue.keeper_2", player_name)); ``` | Call | Does | | --- | --- | | `tr(key) -> u8[>..]` | the key's text in the current language | | `tr(key, a, b, c, d)` | the same with `{0}` `{1}` `{2}` `{3}` filled in (text: `str(x)` for a value) | | `tr_n(key, n: i64, a, b)` | the plural form for count `n` (below); `{n}` is `n` written the language's way, `{0}` `{1}` are `a`, `b` | | `tr_list("menu.play,menu.quit")` | each key's text, comma joined: menu items for `main_menu`, `ui_segmented` | | `tr_has(key) -> bool` | some file has the key | | `number(v: f64, decimals = 0)` | `12,345.5` (en), `12.345,5` (de), `12 345,5` (fr) | | `lang() -> u8[>..]` | the current language's code | | `lang_set(code) -> bool` | switch now and keep the choice (next sessions too); `""` goes back to the system's language | | `lang_count()`, `lang_code(i)`, `lang_name(i)`, `lang_index()` | the game's languages (the source first), each one's name in its own words ("Deutsch", "日本語"), the current one | | `lang_version() -> i32` | changes every time the language does | | `lang_source(code)` | in `main()`: the language the source text is in (default `"en"`) | | `font_fallback(path) -> bool` | a font every font draws missing characters from (symbols; see Fonts) | `tr` makes a fresh string on each call, so text drawn with it follows a language switch at once. Text a game keeps (a level's dialogue read into an array at load) is read again when `lang_version()` changes. When a key has no text in the current language, the source language's text shows (and the log says which key is missing); when no file has it, the key itself shows. `{{` and `}}` are literal braces. **Never build sentences from pieces** (`tr("you_have") + n + tr("coins")`): word order differs between languages. One key with placeholders, the whole sentence: `"Allume d'abord la lanterne du port, {0}."` ## Plural forms `tr_n("hud.lanterns", n)` reads `hud.lanterns.
`, the form picked by the language's own rules for whole numbers: | Language | Forms the file needs | | --- | --- | | en, de, nl, sv, da, nb, fi, it, es, el, hu, tr, bg, ca, et, eu, gl, is | `one` (1), `other` | | fr, pt-BR | `one` (0 and 1), `other` | | pt-PT | `one` (1), `other` | | ru, uk, be, pl | `one` (1, 21, 31...), `few` (2-4, 22-24...), `many` (5-20, 25-30...) | | cs, sk | `one` (1), `few` (2-4), `other` | | hr, sr, ro, lt | `one`, `few`, `other` | | lv | `zero`, `one`, `other` | | sl | `one`, `two`, `few`, `other` | | ja, zh, ko, vi, id, ms, th | `other` only | Russian: ```json "lanterns": { "one": "Зажжён {n} фонарь", "few": "Зажжено {n} фонаря", "many": "Зажжено {n} фонарей" } ``` Any language may add `zero` for n = 0 ("No lanterns lit yet"). A missing form falls back to `other`, then to the key as a plain string. ## Which language plays 1. `gander test --lang fr` (the `gander_lang` launch option, `?gander_lang=fr` on the web) 2. the player's own choice: the Language tab in Settings, or `lang_set` 3. the system's languages (the browser's, the phone's, the desktop's), matched to the files present: `fr-CA` takes `fr-CA.json`, else `fr.json`; `zh-TW` takes `zh-Hant`; `pt` takes `pt-BR` or `pt-PT` 4. the source language The Settings screen (`ui_settings`, the Flow's Settings) gets a **Language** tab once the game has two or more languages; nothing to add. For a picker of your own: ```goose for i: i32 in 0..gander::lang_count() { if gander::ui_button(gander::lang_name(i)) { let ok = gander::lang_set(gander::lang_code(i)); } } ``` ## Source language and keys The source language is the one the game is written in: `en` unless `main()` calls `gander::lang_source("ja")` before any text. Its file is the fallback for every other language, and `gander lang check` compares every file with it. Keys can also be the source text itself, with no source file at all: `tr("Play")` shows "Play" in English and `fr.json` holds `{"Play": "Jouer"}`. Named keys (`menu.play`) are better for anything longer than a word: the English can change without breaking every other file. ## The engine's own words The Flow's menus, Settings, the save and load screens, toasts, score tables, `save_ago` text and the touch prompt use `gander.*` keys with built-in text in en, de, es, fr, id, it, ja, ko, nl, pl, pt-BR, pt-PT, ru, th, tr, uk, vi, zh-Hans and zh-Hant. A game's file overrides any of them (`"gander.play": "Embark"`); for other languages, put them in that language's file or they show in English: `gander.paused continue new_game load_game save_game settings quit play resume main_menu play_again game_saved save_failed audio controls graphics language master_volume music effects voices look_sensitivity invert_look_y quality low medium high show_fps delete autosave saved_game empty_slot no_saves overwrite_title overwrite_body overwrite cancel delete_title delete_body loading no_scores tap done back just_now min_ago hr_ago yesterday days_ago months date_short date_long auto` (all prefixed `gander.`; the English is in `runtime/lang_builtin.json`). ## Fonts The built-in font draws Latin scripts (English, French, German, Spanish, Portuguese, Italian, Polish, Turkish, Dutch, the Nordic languages...). For everything else, **gander build** looks at every character in assets/lang/ (and the game's string literals), finds those the game's fonts lack, and cuts just those from Noto (Sans, JP, SC, TC, KR, Thai) at the built-in font's weight into `assets/lang/fonts/.ttf`. A Japanese game's few hundred kanji come to tens of kilobytes. Nothing to call: the engine draws missing characters from the current language's font first (Chinese text takes Chinese shapes, Japanese text Japanese ones), then the other languages'. * Keep `assets/lang/fonts/` (it is part of the game); it is remade whenever the text changes. Do not edit those files. * Own font for a language: `"_meta": {"font": "assets/fonts/MyKana.ttf"}` in its file; it is used before the generated one. * Lighter fallback glyphs to suit a regular-weight game font: `"_meta": {"weight": 400}` (the built-in font is 700). * A game font with only some letters (a display font with no accents): the missing letters come from Noto mid-word. Check a heading font's coverage before using it for a language; a body font that has the letters reads better than a mix. * **Pixel-art games:** `"_meta": {"style": "pixel"}` in a language's file cuts its missing characters from pixel fonts instead of Noto: Fusion Pixel 12px for Chinese (Simplified and Traditional drawn their own way), Japanese, Korean, Vietnamese and other Latin, and gander's pixel Thai; anything they lack still comes from Noto. Put it in every language file of a pixel game (the source language's too, for its string literals). CJK and Thai glyphs fill the whole line: give wrapped text in those languages a little more line spacing than the Latin text needs. * **A PixelLab font** (and any pixel font with only A-Z a-z 0-9): it has no accents and no `# & @ [ ] < > \ | ^ ~`, so French, Spanish, Portuguese, Vietnamese... would mix in Noto letters. `gander lang pixel-font assets/fonts/title.ttf` adds them in the font's own pixels (accented Latin for those languages, Vietnamese tones, the symbols, curly quotes, dashes, ellipsis, guillemets); run it once when the font comes in. * A game font of its own (`gander::font`) draws what it has; the characters it lacks come from the language fonts the same way. * Symbols no lang file holds (a "★" drawn from a literal): build covers string literals too; for a whole symbol font, `gander::font_fallback("assets/fonts/symbols.ttf")`. ## Checking and testing ``` gander lang check every file against the source: keys missing or extra, placeholders a translation lost, plural forms the language needs, tr("...") keys no file has, characters no font draws (gander check runs it too) gander lang fonts make assets/lang/fonts/ now (gander build does it) gander test --lang fr play in French: screenshots, probes, logs gander test --lang pseudo the source text accented and a third longer, in brackets: text that is not bracketed is not going through tr, text cut off or overflowing its box will be in German too gander capture --lang ja ... record in Japanese (store videos per language) ``` Check every language with a screenshot run: German and Russian run about a third longer than English, so size buttons and panels from the text (`text_width`, `text_wrap_height`), never fixed widths. ## Translating (for the agent) When asked to localize a game: 1. Move every player-facing string into the source file and draw it with `tr` (titles, menus, HUD, dialogue, tutorial prompts, item names, game over text). Keep debug text and log lines out. `gander test --lang pseudo` shows what was missed. 2. Write each language's file with **every** key of the source: natural, idiomatic text a native player expects in a game, not word for word. Keep `{0}` `{n}` placeholders, keep terms consistent across the game, keep the tone (playful, grim) of the source. Give each plural key the forms in the table above. 3. `gander lang check` to zero warnings, `gander build`, then a `gander test --lang ` screenshot per language to see the fonts and the lengths. ## Thai Thai draws with its marks in place: the engine puts tone marks over upper vowels (ที่), marks left of tall letters (ปี่ ฟ้า), lower vowels under tails (ฎุ), ญ ฐ without their tail over a lower vowel (ญุ ฐู), and SARA AM with its ring under a tone mark (น้ำ). Thai writes no spaces between words, so **put a zero width space (U+200B, `\u200b` in JSON) between words** in th.json: lines break there. A paragraph with none breaks between syllables (before เ แ โ ใ ไ, after ะ ำ ๆ), which is readable but not as a Thai reader expects; `gander lang check` warns about long runs without one. Spaces stay where Thai puts them (between phrases and sentences). ```json { "story": "ผู้\u200bเฝ้า\u200bคน\u200bเก่า\u200bออก\u200bจาก\u200bเกาะ\u200bตอน\u200bค่ำ" } ``` ## Limits * Right-to-left and shaped scripts (Arabic, Hebrew, Persian, Hindi) draw as separate letters left to right: their files load and the check warns, but the text does not read correctly yet. * No kerning or ligatures (as for all gander text). * CJK lines break between any two characters, never before a closing mark or small kana (。、」っ) or after an opening one; Thai at U+200B (above); other languages break at spaces. * Glyphs are made as text first shows; the current language's characters are made a little each frame in the background after a switch, so long text draws without a stall.