Contributing Translations
The engine’s interface (the main menu, the settings, the save and load screens, the quick menu, the alerts) has 64 strings, and 2.9.0 ships them in 18 languages. This page is about translating those strings, the engine’s own. To translate a game’s story and its labels, see Translating Your Game.
Where the translations live
Each language is one file in src/translations/, named after the language (Espanol.ts, Deutsch.ts, 日本語.ts), whose default export maps each string’s key to its text:
/**
* ============================================================
* Español
* ============================================================
*
* Translators:
*
* Hyuchia <diana@hyuchia.com>
*/
export default {
'AdvanceHelp': 'Para avanzar en el juego, presiona espacio o haz click',
…
};The keys are the same in every file: the engine and dist/index.html refer to them (data-string="Load", monogatari.string('SaveInSlot')). Only the values are translated. The comment at the top credits the translators.
src/index.ts registers each file twice, under the language’s own name:
Monogatari._translations = {
…
'Español': spanish,
…
};
Monogatari._languageMetadata = {
…
'Español': {
code: 'es',
icon: '🇲🇽',
},
…
};- The name (
'Español') is what a player’sLanguagepreference holds and what the settings screen shows. In a game withMultiLanguageon, the game’s script is keyed by the same names, so a game’s'Español'script and the engine’s'Español'interface go together. codebecomes Luxon’s locale when the language is selected (localize()insrc/engine/i18n.ts), so dates, such as a save slot’s, are written in that language. It also becomes the page’s<html lang>, and decides<html dir>: a right-to-left language ('ar','fa','he','ur', or a code with a right-to-left script such as'az-Arab') turns the page right to left. It’s a locale tag: most are two letters ('es'), a few have a region or script ('pt-br','zh-hans','zh-hant'), andtoki ponauses'en'.iconis shown next to the name on the language selection screen. A language a game’s script uses without metadata shows thecomponent:language_selection_screen:metadata_not_founderror there.
When the player picks a language, the engine sets the preference and calls localize(), which writes the translation of each element’s data-string key into it. A key missing from the selected language shows the engine:translation:key_not_found error in development, and the element gets the English text.
Translate without the toolchain
A translation is a text file, and translating needs nothing installed. Copy src/translations/English.ts from the repository on GitHub (the starter game’s download doesn’t include it), translate the text between the quotes on the right of each line in any text editor, and send the file in an issue or a pull request. A maintainer registers it.
A game doesn’t have to wait for a release to use a language: it can add one in its own js/main.js with monogatari.translation('Italiano', { … }) and monogatari.languageMetadata('Italiano', { code: 'it', icon: '🇮🇹' }). Translating Your Game covers that side.
Find what needs translating
At 2.9.0, 13 languages have all 64 keys. Bulgarian, Hungarian, Беларуская, العربية and toki pona lack StorageBlocked and StorageUpdated, the two strings 2.9.0 added, and show them in English until someone translates them. To check a file, or all of them, against English, save this as a scratch script outside the repository (/tmp/check-translations.ts):
import { readdirSync } from 'fs';
const dir = process.argv[2];
const english = (await import(`${dir}/English.ts`)).default;
const englishKeys = Object.keys(english);
for (const file of readdirSync(dir)) {
const strings = (await import(`${dir}/${file}`)).default;
const keys = Object.keys(strings);
const missing = englishKeys.filter((key) => !(key in strings));
const extra = keys.filter((key) => !(key in english));
console.log(`${file}: ${keys.length} keys, missing ${missing.length}${missing.length ? ' (' + missing.join(', ') + ')' : ''}, extra ${extra.length}${extra.length ? ' (' + extra.join(', ') + ')' : ''}`);
}and run it from the repository’s root:
bun /tmp/check-translations.ts "$PWD/src/translations"Each line names a file, its key count, and the keys it lacks or has extra: Espanol.ts: 62 keys, missing 0, extra 0. A value still in English is a string waiting for a translator; the script can’t tell those apart, so read the file.
Add a new language
- Copy
English.tsto a file named after the language, such assrc/translations/Italiano.ts, and change the name and the translators in the comment at the top. - Translate every value. Keep the keys as they are.
- Register it in
src/index.ts: import it (import italian from './translations/Italiano';), add'Italiano': italiantoMonogatari._translations, and add'Italiano': { code: 'it', icon: '🇮🇹' }toMonogatari._languageMetadata. - Build:
bun run build, and run the check script above:Italiano.ts: 62 keys, missing 0, extra 0. - See it. Serve
dist/, open the game, and in the console typemonogatari.preference('Language', 'Italiano'); monogatari.localize();. The main menu’s buttons change to your strings. (Done with a two-string test file: the menu went fromStart,LoadtoInizia,Carica.) Then set the preference back, since it’s saved. - Send it as a pull request against
developwith the file, the registration and the rebuilt bundles (How a Change Gets In).
Add a string to the interface
A new button or message in the engine needs a key in all 18 files: the English text in English.ts, a translation where you have one, and the English text in the others until a translator replaces it. Use it in markup with data-string="YourKey" (and the English text inside the element, which stays if a key is missing) or in code with this.engine.string('YourKey'). Run the check script: every file must report the same number of keys.