Internationalization
Making Monogatari games multilingual.
Last updated
Making Monogatari games multilingual.
Last updated
You can create a multi-language game pretty easily. To do so you need to follow these simple steps:
MultiLanguage
settingGo to the options.js
file and change the 'MultiLanguage'
value to true
.
This will let monogatari know that you're planning to have your script in multiple languages. If you reload the page however, you'll most likely get an error like this one:
This is normal and is caused because while we have indicated we would be having multiple versions of our script in multiple languages, we haven't changed the structure of our script to match that.
Next we will be changing the script to support Multi Language games. A single language script as you know is defined as an object with a list of labels and usually looks something like this:
Note how each label is in the top level of the script objects hierarchy.
A Multi Language script will instead have language objects in the top level and inside of them, the labels of the script that correspond to that language, for example:
Note how we essentially duplicated our script inside this new language objects and translated it for each language.
When saving a game, monogatari saves the label
and step
(index of the statement) it's currently on. For saved games to be fully compatible with each other, your different scripts should have the same label names and number of statements in them, otherwise, a game saved in one language would be invalid if the player changed language again and tried to load it. If you do a jump to a label that exists in one translation, but does not exist in the language that the player has selected for example, they will get an error telling them that the label does not exist, so be careful when crafting your script!
In case some differences can't be avoided, you can rely on the next action to fill act as a filler and make all scripts have the same size.
If you have your script split in multiple files, you can read more on how to configure internationalization with split files here:
Once you've formatted your script correctly, a language selection screen will appear for players that haven't selected a language yet. It will automatically detect the languages in your script and show buttons like the ones shown in the image.
You most likely won't see this screen appear to you because you transitioned from a single language game to a multi language one and thus, your settings were already set.
If you want to trigger this screen, you'll have to remove the settings from your storage using the dev tools.
Players are also able to change their language from the settings screen. The following image shows the language selection setting that appears automatically when a multi language game is configured:
In case you don't want the language selection screen to appear or have built your own, it can be disabled from the options.js file by changing the LanguageSelectionScreen
property to false
:
Finally, you need to provide a default language for your game. While players will be able to choose their language, monogatari does need something to fall back to. Go to the options.js
file once more and this time, go to the preferences section in the bottom. There, you should change the 'Language'
property to the name of the language you want to have by default.
Monogatari already has built-in support for the following languages:
Bahasa Indonesia
Беларуская
Deutsch
English
Español
Français
Nederlands
Português
Русский
اللغه العربية
한국어
日本語
简体中文
toki pona
That means UI translations for those languages are available and the full UI will be shown in the correct language. You can also retrieve the list of available translations programmatically using the monogatari.translations ()
function. This function will return an object with all the available languages and the UI string translations for them.
If you need to translate the game into a language that Monogatari doesn't include in the supported languages or simply want to modify an existing translation, you can define your own UI translations as follows:
You can also contribute to monogatari by adding new language translations to it or updating existing ones. You can learn more here:
To make a new language available for your players to choose from, you'll have to add translations for all the strings the UI requires. You can take the English strings file as reference so you can gather all the required strings and add your own translations for your language.
You can also get a complete list of every string to translate programmatically by using the monogatari.translation ('<language_key>')
function, for example:
Each language also requires some metadata that will be used by monogatari.
Here's an example of the definition of a language metadata:
Once you've setup all the string translations and language metadata, all you need is adding your script for your new language and the option will appear automatically both on the language selection and the settings screens.
Metadata
Description
code
The 2 letter code that represents that language. This code must be a valid ISO 639-1 code since it will be used to format the dates shown on the save slots.
icon
An emoji that will be shown as the icon for the language in the language selection screen.