In order to distribute games to a wider audience, you might need to translate text to different languages. The localization API provides a way to easily translate your text to different languages.

Setting up for localization

Before we begin, you need to create a new folder under Config/, called Translations. Inside of it, you need to create a file called translation-base.yaml. This file will act like a layout for your other translations. Example:

origin-locale: "en-US"
  - "The quick brown fox jumps over the lazy dog"
  - "Hello, World!"

The origin-locale field specifies the initial and default locales. These locales are formatted in the standard lang_COUNTRY code. A full list of the available locales can be seen here The strings field is a sequence of strings in the origin locale. These strings will then be used as identifiers for translating.

Creating translations

To create a translation, create a new file with its name being one of the languages in our list of supported locales e.g. bg_BG.yaml and fill it with data like this:

  - string: "The quick brown fox jumps over the lazy dog"
    translation: "Бързата кафява лисица прескача над мързеливото куче"
  - string: "Hello, World!"
    translation: "Здравей свят!"

Here we have translated our original English text to Bulgarian. The strings tag is a list of objects, each of these objects is of type string, which in its parent data contains the original en_US text, while under the translation child it holds the Bulgarian text.

These files are automatically indexed, so adding a new translation is as easy as adding a new file with a new locale name

Using localized strings

The Locale interface contains a bunch of functions to interact with the localization system.