I18n System

Let's initialize a simple GM-I18n system to translate the text in the game. We will use the en and id locale, and translate the "Hello World" text.


Import Locale Files

  1. Prepare your locale files. Currently, GM-I18n only support JSON file as the locale file. Create a JSON file that contains the translation data. The file structure is as follows:
en.json
{
    "hello": "Hello World!"
}
id.json
{
    "hello": "Halo Dunia!"
}
The file name can be anything, but for clarity, we will use the locale code as the file name, for example en.json and id.json.The locale files are optional. You can add the text translation later with the i18n_add_messages() function.
  1. Click Menu button in the Asset Browser (that one with 3 stripes icon), and then click Included Files. The Included Files window will open, and then click Open in Explorer.
    Included Files
  2. A window will open and show you the datafiles folder of your project. Copy your locale files there. You can also make a folder for your locale files, for example langs.
    Copy Locale Files
  3. In the Included Files window, click Refresh button. Your locale files should now appear in the list.

Initialize the System

  1. Create a new object, for example objI18n. It's recommended to mark it as Persistent object.
  2. Create the I18n system in objI18n:

Using global variable

Using instance variable

It's highly recommended to use global variable to store the I18n system, but you can use it on objI18n instance variable instead. If you're using instance variable, you need to pass the I18n struct created by the i18n_create() function.

The var_name is the actual variable name. It need to match with the variable name that you use to store the I18n system. We're using i18n global variable, so the var_name is global.i18n. If it's declared on instance variable, you can remove the global keyword.

You can use standard locale code (such as en_US), but don't use stripe (-) for the separator. You can also add "~/" to the file path as a shorthand of working_directory. But if you're targeting on HTML5 export, please don't use this shorthand.

The i18n_update_loader() function is used to update the loading progress of the locale files. Only use this function if you're importing the text translation through JSON files.

The i18n_create() function used in the code above is a really basic initialization. You can find the full documentation of the i18n_create() function.

Create Font Assets

If you haven't created the font assets for each language you're using, you need to create it first. Let's assume we've created the font assets through IDE called fnNotoSans. Because both locale we're using is Latin-based, we can use the same font asset for both locale.

You can skip this step if you're only using Latin-based languages.

You can find the detailed instruction in the Configuration section.

Create Drawing Presets

It's optional, but it's recommended to create a drawing preset for each locale. Let's create a simple header and body drawing presets!

Using global variable

Using instance variable

You can skip this step if you don't want to use the drawing preset feature.

You can find the detailed instruction in the Drawing section.

As you can see, you need to pass the I18n struct everytime you're using any i18n_* functions. What a hassle, right? That's why I recommend to create the i18n system in the global variable.

Refresh the Drawing Presets

If you're targetting on HTML5 export, you need to follow the temporary solution.

You can skip this step if you're targetting other than HTML5 platform.

  Congrats, you're ready to use the GM-I18n system!