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!".
- No ids to invent and nothing to keep in sync by hand: the text in your code is the key.
- A missing (or empty) translation shows the English text, so the game never breaks.
- If you change the English text, its key changes too: the old translation becomes "unused" and the new text "missing".
pnpm langshows both, so you can carry the translation over. - An entry left as
''shows the English text in the game.pnpm langlists it as "empty" and does not count it as translated.
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:
| Where | What |
|---|---|
| Scenes | say / narrate lines, speaker names (character name, and as), choice labels and their disabled reasons |
.vn scripts | Lines, narration, options |
| Map | Object labels, speech bubbles (bark), touch button labels |
| Screens | Window titles, title menu labels |
| Engine messages | Toasts 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
- 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: {}, }) - Run
pnpm lang --write. It appends every game text as an empty entry ('Inventory': '',), grouped at the end ofstrings. - Fill them in. Empty ones still show English, so you can translate bit by bit.
- Pick it in Settings → Language (or the dev panel's language switch). It appears there automatically.
- 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_brfor pt-BR), else the source language. Once a language is saved on the device, that one stays. Turn it off withfollowSystem: falseinsrc/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).
localepicks the plural rules, the line-breaking rules (Japanese, Chinese) and the voice for Read text aloud.fontreplaces the game's font while the language is chosen (a font the player picks in Settings wins). Put the file insrc/content/fonts/(as afallbackfont if it should only fill in this language's letters) and use its id here: see Fonts.
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.
| What | The version in a language | Example |
|---|---|---|
| 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 |
| Sounds | The same, in src/content/audio | sfx/shout.ja.wav next to shout.wav |
| Voices, music and movies | A 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 file | In Jack's portrait: open.ja next to Open inside @Eyes |
<lang>is a folder insrc/content/lang(ja,pl). A name ending in anything else is just a name.- Aseprite layers: the language layer takes the other's place, in drawing order, with the other's visibility: hide it while you paint the original. Capitals and spaces around the name don't matter (
Openandopen.ja, oropen.JA, pair up). It works for any layer: a part's option, an always-drawn layer (Shirt.ja), a CG toggle, a sprite layer in every frame. Only pictures that really change get stored, in the same generated sheet (portraits) or as extra files next to it (jack.ja.gen.pngfor sprites,pond.ja.gen.pngfor CGs). - Tilesets have no language versions: they are always one picture.
- A version with no original next to it is ignored, with a warning in the build.
- Where it applies by itself: event backgrounds, CGs and the gallery (thumbnails too), portraits, map and battle sprites, movies and their Extras tiles, scene cards, boot and title screens, and the event look-ahead loads the player's language's files. In your own code, wrap a picture or video URL:
<img src={lang.image(url)} />, withuseLang()in the component so it changes with the language. - Boot screens wait for the player's language before they start, and boot / title
preloadlists load the language's file, so the right logo shows from the first frame. - Changing language: pictures in scenes, windows and the title change at once; map sprites change on the next map load.
- Which assets have a version:
pnpm lang --assets(see below).
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"
- missing: text in the game with no translation yet.
- unused: a translation whose English text no longer exists. Usually the English was edited: copy the translation to the new key and delete the old entry.
- Run it after writing new content; it only reads files (no dev server needed).
--assetslists, per language, the files that have a version and those without one (tilesets left out). It is a separate report because most files need no version: only those with words in them.
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:
t('…')andtx('…')say(who, '…'),narrate('…'),bark('…')- Every string inside
choice({ … })/choice([ … ])/menu({ … }), and queststeps: { … } - Fields
name,title,label,description,as,disabled,replay,category,text,hiddenTextwritten as a plain string - Text built in a function (an item's
useLabel): wrap it yourself,game.t('Light'), sopnpm langfinds it .vnscripts (compiled first, then read like the above)
In src/core (the engine) only t('…') and tx('…'). Commented-out lines are ignored. Language files themselves and tests aren't scanned.
| Not found | Do 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 variable | Mark it with tx() where it's written |
A character's unknownName, and names given with rename | Add the entry to the language file by hand (pnpm lang then lists it as unused: keep it) |
Things to know
- Same English, same translation. "Back" (a button) and "Back" (a body part) share one key. If a language needs different words, make the English differ (e.g. "Go back").
- Plurals. One text, one form per number: see Plurals.
- Gender. The player has no gender setting; the Polish lines currently address the player in the masculine form.
- Names in data. Character, item and enemy names are text like any other: translate them in the language file.
- Anything shown with
console.log, the dev panel and error screens stays English.
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