Translations

You write the game in English. Each other language is one file that maps the English text to its translation. Most text is translated without you doing anything; pnpm lang tells you what's missing.

The idea: the English text is the key

// You write:
await say('anna', 'Hello there!')

// src/content/lang/pl/index.ts has:
'Hello there!': 'Cześć!',

// A player who picked Polski sees "Cześć!". Without that entry they see "Hello there!".

The language the game is written in is described in src/content/lang/source.ts (its name, "English", shown in the language list).

What is translated automatically

All of this goes through the translator on its way to the screen. Just write English:

WhereWhat
Scenessay / narrate lines, speaker names (character name, and as), choice labels and their disabled reasons
.vn scriptsLines, narration, options
MapObject labels, speech bubbles (bark), touch button labels
ScreensWindow titles, title menu labels
Engine messagesToasts the engine makes ("New quest: …", item gained, achievements, journal, level up, relationship changes), money (money.format)

Item names and descriptions, quest titles and steps, shop names, achievements, journal entries, enemy and skill names are translated by the windows that show them (they call t()). If you write your own window, do the same.

Translating your own text

// Anywhere (managers, scripts, map hooks)
game.t('Saved!')
game.toast(game.t('You found {count} coins', { count: 5 }))

// React: useLang() returns t and re-renders the component when the language changes
import { useLang } from '@/core/lang'
function Panel() {
  const t = useLang()
  return <Button>{t('Inventory')}</Button>
}
game.toast(text) does not translate: pass game.t('…'). In React always use useLang() rather than importing t, or the text won't update when the player switches language.

Placeholders

t('Health {value}', { value: 50 })            // "Health 50"
// pl: 'Health {value}': 'Zdrowie {value}'     → "Zdrowie 50"

t('{name} joined the party', { name: t(member.name) })   // translate the inserted name too

Never build sentences with ${…} or +: t(`Health ${hp}`) makes a different key for every number, and the scanner can't find it. Use {placeholders}; translators can then move them where their grammar needs them.

Plurals

t('I have {count} apples.', { count })      // also in say(): { count } picks the form

// src/content/lang/pl/index.ts
'I have {count} apples.': {
  one: 'Mam {count} jabłko.',
  few: 'Mam {count} jabłka.',
  many: 'Mam {count} jabłek.',
  other: 'Mam {count} jabłka.',
},

// src/content/lang/source.ts: English needs "1 apple" too
strings: {
  'I have {count} apples.': { one: 'I have {count} apple.', other: 'I have {count} apples.' },
},

The value named count picks the form with the language's own rules (one / few / many / other…; other is required). A plain string still works for texts that don't change.

Rewording text in English

// src/content/lang/source.ts
strings: {
  'Quest complete: {title}': 'Mission done: {title}',   // an engine toast, your words
},

Any text can be reworded in the source language this way, the engine's own included (toasts, buttons, settings). Use the text exactly as written. Translations keep using the original text as their key.

Text kept in constants: tx()

import { tx } from '@/core/lang'

const REASONS = { money: tx('Not enough money'), stock: tx('Sold out') }   // marked, not translated yet
…
<Button>{t(REASONS[result])}</Button>                                       // translated when shown

tx() does nothing at runtime; it marks the text so pnpm lang finds it. Use it for labels in objects, arrays and module-level constants, and for text passed through variables (e.g. a disabled reason built with &&).

Markup

'Hey, friend! {wave}Good to see you!{/wave}': 'Hej, przyjacielu! {wave}Dobrze cię widzieć!{/wave}',

Keep the tags in the translation and translate the text between them. You may move tags (and pauses like {w=0.5}) to fit the sentence.

The automatic pause after . ! ? works on the translated text, so it follows the translation's punctuation. Full-width 。!? count too. Add noAutoPause: true to a line to turn it off.

Adding a language

  1. Make src/content/lang/de/index.ts (the folder name is the language id):
    import { defineLanguage } from '@/core/lang/define'
    
    export default defineLanguage({
      name: 'Deutsch',          // shown in Settings → Language, in its own language
      strings: {},
    })
  2. Run pnpm lang --write. It appends every game text as an empty entry ('Inventory': '',), grouped at the end of strings.
  3. Fill them in. Empty ones still show English, so you can translate bit by bit.
  4. Pick it in Settings → Language (or the dev panel's language switch). It appears there automatically.
  5. First start: the game uses the device's language when it has it (the device's preferred languages in order; a folder named like the code: ja, pl, pt_br for pt-BR), else the source language. Once a language is saved on the device, that one stays. Turn it off with followSystem: false in src/content/lang/source.ts.

Each language loads only when chosen (its own code chunk). The choice is a per-device setting, not part of save files.

What a language file can set

export default defineLanguage({
  name: 'Polski',
  locale: 'pl',                                  // default: the folder name
  font: "'Noto Sans', sans-serif",               // a font that has its letters
  strings: { … },
})

Pictures, videos and sounds are not listed here: they are found by name (below).

Pictures, videos, sounds and Aseprite art per language

For art with words in it (a sign, a logo, a shirt, a sung or spoken line). Nothing to register: add the language's version next to the original. Without one, every language uses the original. Only versions that exist are ever loaded; the build lists them, so the game never asks for a file that isn't there.

WhatThe version in a languageExample
Pictures (PNG, JPG, WebP, AVIF, GIF, SVG), videos (mp4, webm)A file <name>.<lang>.<ext> next to <name>.<ext>assets/logo.ja.svg next to assets/logo.svg
SoundsThe same, in src/content/audiosfx/shout.ja.wav next to shout.wav
Voices, music and moviesA voice language folder (the player's voice language, not the text language): audio/voice/<lang>/…, audio/music/<lang>/…, movies/<id>/<lang>/…voice/ja/anna/hello/anna_0001.wav, music/ja/town.ogg, movies/opening/ja/opening.mp4
Aseprite files (portraits, map sprites, battle sprites, layered CGs)A layer (or folder) <name>.<lang> next to the layer <name>, in the same fileIn Jack's portrait: open.ja next to Open inside @Eyes

Day-to-day: pnpm lang

pnpm lang            # per language: how many are translated, missing and unused strings
pnpm lang --write    # also adds the missing ones as empty entries
pnpm lang --assets   # which pictures, videos, sounds and Aseprite files have a version per language
[lang] pl: 222/225 translated
  unused (maybe text that changed): "You won?! Fine, take a look at my wares."
  missing: "You won?! Fine, have some coins for that."
  missing: "Sold out"

Checking in the game

Dev builds remember every text that was shown without a translation. In the dev panel's Translations section, copy missing puts them on the clipboard as lines ready to paste into the language file ( "Some text": '',). This also catches text the scanner can't see.

How pnpm lang finds text

It reads the source files (it doesn't run the game). In src/content it finds:

In src/core (the engine) only t('…') and tx('…'). Commented-out lines are ignored. Language files themselves and tests aren't scanned.

Not foundDo instead
say('anna', `Hi ${name}`)say('anna', t('Hi {name}', { name }))… or simpler: {name} placeholders need t(), so avoid names in lines when you can
const lines = ['Hey!', 'Hi!'][tx('Hey!'), tx('Hi!')]
disabled: cond && 'Too far away'disabled: cond && tx('Too far away')
Text from a function or another file's variableMark it with tx() where it's written
A character's unknownName, and names given with renameAdd the entry to the language file by hand (pnpm lang then lists it as unused: keep it)

Things to know

API

game.t(text, values?)              // translate now
game.lang.current()                // 'source' | 'pl' | …
await game.lang.set('pl')          // switch (Settings does this and remembers it)
game.lang.ids                      // ['pl']
await game.lang.name('pl')         // 'Polski'
game.lang.locale()                 // 'pl': for Intl formatting
game.lang.image(url)               // this language's version of a picture
game.lang.missing()                // dev: shown-but-missing lines, ready to paste
useLang()                          // React: t + re-render on change
tx(text)                           // mark for the scanner