Languages
Translate your game: the HUD, menus, messages and unit names come from a table per language, and the player picks one in Settings › Interface › Language. The simulation only sends keys, so one game can be played in Hebrew on one screen and English on the next.
Quick start
import type { GameView, MessagesFile } from '@v12-engine/client'
export const view: GameView = {
units: { looks: {} },
languages: {
en: {},
he: () => import('./languages/he.json').then((file) => file.default as MessagesFile)
}
}he.json:
{
"dir": "rtl",
"messages": {
"notEnough": "אין מספיק {resource, resource}",
"hud.idle": "ממתין",
"ui.menu.resume": "המשך",
"groups.members": "{count, plural, one {{unit, unit}} two {שני {unit, unit}} other {# {unit, unit}}}"
},
"names": { "unit.footman": "רגלי", "unit.footman.description": "חייל פשוט", "resource.gold": "זהב" }
}The first language listed is the one the game is written in. Others load only when chosen. Hebrew turns the HUD right to left.
Common tasks
Name a unit, ability or speaker
Put <kind>.<id> in the table's names, and <kind>.<id>.description for what it says it is: unit.footman, ability.holyLight, speaker.arthur (NameKind). Where a table has none, the definition's name is used.
Translate your own text
Anything your game or map writes as plain text is its own key: an objective, a mission's say line, a cinematic line, campaign mission names, a button label. A table with that text as a key translates it; without one it shows as written. You can also use clearer keys (mission.bridge.objective) and put the English in the first language's table.
Use plurals and parameters
{ "messages": { "unitsLeft": "{count, plural, =0 {none left} one {# unit left} other {# units left}}" } }Use a typeface for another script
@font-face {
font-family: 'Game Hebrew';
src: url(./fonts/hebrew.woff2) format('woff2');
unicode-range: U+0590-05FF, U+FB1D-FB4F;
}{ "dir": "rtl", "font": "'Game Hebrew'", "messages": {} }The language's font goes before the theme's (as --vg-language-typeface), so it draws only its own letters.
Translate the app's menus
startApp({ target: '#game', scenes, languages: view.languages })Test a translation
import { Words } from '@v12-engine/client'
const words = new Words({ languages: { en: {}, he: { messages: { queueFull: 'התור מלא' } } } })
await words.use('he')
words.text('queueFull') // 'התור מלא'
words.text('card.move') // 'Move': the client's, where Hebrew has noneEditor
- Open the Languages panel.
- Each row is a key or name with its source text; each column is a language.
- Type translations; they go into
languages/<id>.json. - Rows whose source changed since translation are marked stale.
- Export to CSV for a translator, and import it back.
Reference
A language table (MessagesFile)
| Field | What |
|---|---|
name | the language's name in itself, for the settings (the browser's by default: languageName) |
dir | rtl for right to left |
font | typefaces for its script, before the theme's |
messages | words per key: the game's, the engine's, the client's |
names | <kind>.<id> and <kind>.<id>.description |
sources | a hash of each source text, kept by the editor to mark stale rows |
Which language is used
The setting language starts as the browser's language where the game has it (by full id or language alone: pt-BR for pt, matchLanguage), else the game's first. It shows only when the game has two or more.
A key is looked up in order, the first that has it wins:
- the chosen language;
- the game's first language;
- the view's words (
GameView.hud.messages; a race's over them for its player,race.<race>.<key>); - the engine's (
engineWords) and the client's (CLIENT_WORDS); - the key itself.
Word syntax (formatWords)
A small part of ICU's message format:
| Written | Says |
|---|---|
{player} | the param |
{count, plural, =0 {none} one {# unit} other {# units}} | by the language's plural rules (Intl.PluralRules) |
{race, select, undead {bones} other {farms}} | one of several, by the param |
{amount, number} | a number in the language's format |
{unit, unit} | the name of an id (also ability, item, upgrade, buff, resource, race, speaker); a list is joined |
A blank with no param stays as written. Words in code (MessageWords) are told the reader's language (MessageViewer.language).
The client's own words
The client's table is messages.en.json (CLIENT_WORDS): copy it to start a translation.
| Keys | Of |
|---|---|
hud.idle, hud.orders.move… | what a unit is doing (HudWords, HUD_WORDS) |
card.move, card.build.about… | the command card |
ui.menu.resume, ui.log.title… | HUD parts, the pause menu, the app's screens |
save.newer… | why a save can't load |
moveHint, gatherHint… | hints |
Settings use setting.<id>, setting.<id>.hint, setting.<id>.<value>, setting.section.<id>, so your own settings translate too. The debug tools stay in English.
Right to left
"dir": "rtl" sets dir on the game's element (and the app's): the HUD's places mirror (minimap and command card swap sides), panels lay rows right to left. What is placed from a point stays: the minimap's picture, tooltips, a bar's fill, parts the player moved.
client.words (Words)
language() (a signal), use(id), text(key, params), message(message), name(kind, id), description(kind, id), dir(), onChange. Use it in your own HUD parts so they follow a language change.
Not yet
- An ability's worked-out tooltip text is English; a table's
ability.<id>.descriptionreplaces it. - The editor's interface, the shortcuts legend and action labels are English.
- One voice per line, not per language.
Melee has English and Hebrew (apps/example/src/games/melee/languages/he.json).