The text of Monogatari’s interface, the buttons, labels and messages, comes in 18 languages. From your game’s JavaScript you can change any of its wording, add strings for your own components, and add a language.

This page is about the interface. To tell your story in more than one language, see Translating Your Game. To add a language to Monogatari itself, for every game, see Translations in Working on Monogatari.

How interface strings work

Every piece of interface text has a key, like Start, Save or Settings, and each language has a string for every key. The player’s language is their Language preference, 'English' unless your game sets another in js/options.js or the player picks one.

  • monogatari.string('Start') returns the string for Start in the player’s language.
  • An element with data-string="Start" gets its text replaced by that string when the game starts and whenever the player changes the language.

The built-in components use both: they render this.engine.string('Start') inside an element with data-string="Start". To see every key and its English string, type monogatari.translation('English') in your browser’s console while the game is open.

Change a built-in string

Call monogatari.translation() with the language’s name and the strings to change, in js/main.js above $_ready(…). It merges them into that language’s strings:

monogatari.translation('English', {
  'Start': 'Begin',
});

The main menu’s first button now reads Begin. Change the string in every language your game offers.

Strings for your own interface

Give the text in your own components a key, render it with this.engine.string(), and mark its element with data-string, so it changes when the player changes the language:

render() {
  return `<span data-string="Affection">${this.engine.string('Affection')}</span>`;
}

Then add the key to every language your game offers:

monogatari.translation('English', {
  'Affection': 'Affection',
});

monogatari.translation('Español', {
  'Affection': 'Afecto',
});

A key missing from the player’s language opens a “Translation for string “Affection” could not be found” dialog while the debug module is loaded, and monogatari.string() returns the English string instead. A key English doesn’t have either gives undefined, which the markup above shows as the word “undefined”. An element with data-string and no string for its key in any language keeps the text it had.

A screen of your own gives its title and its main menu button a key this way.

Interface strings in the script

A statement can use an interface string too: _(Key) in it is replaced by the string for Key in the player’s language, before the statement runs. With the Start string changed to Begin as above, 'Press _(Start) to play again.' shows “Press Begin to play again.”

Add a language Monogatari doesn’t ship

A new language needs a string for every key the interface uses. A key it lacks shows in English, with an error dialog while you develop. Start from a copy of the English strings, so the keys you haven’t translated yet show in English without the dialog, and translate over them:

monogatari.translation('Italiano', Object.assign({}, monogatari.translation('English'), {
  'Start': 'Inizia',
  'Load': 'Carica',
  'Settings': 'Impostazioni',
  'Help': 'Aiuto',
}));

monogatari.languageMetadata('Italiano', {
  code: 'it',
  icon: '🇮🇹',
});
  • languageMetadata() gives the language its code (it, used for dates in the save slots, the page’s lang attribute and the writing direction) and the icon the language selection screen shows next to its name. Without it, that screen shows a “Metadata for language “Italiano” could not be found.” dialog.
  • The languages a player can choose from are the languages of your script: a game with 'MultiLanguage': true in js/options.js and a script with an 'Italiano' part offers Italiano, in the language selection screen and in the settings. Translating Your Game shows how to set that up.

With an English and an Italiano script, the language selection screen offers both, and choosing Italiano shows Inizia, Carica, Impostazioni and Aiuto in the main menu.

The language selection screen with two buttons, "English" with the United States flag and "Italiano" with the Italian flag, under the title "Select your language"
The language selection screen of a game with an English and an Italiano script

The built-in languages

These are the names to use with monogatari.translation(), exactly as written:

Language Name
Arabic اللغه العربية
Belarusian Беларуская
Bulgarian Български
Chinese, simplified 简体中文
Chinese, traditional 繁體中文
Dutch Nederlands
English English
French Français
German Deutsch
Hungarian Magyar
Indonesian Bahasa Indonesia
Japanese 日本語
Korean 한국어
Portuguese Português
Portuguese, Brazil Português do Brasil
Russian Русский
Spanish Español
Toki Pona toki pona