Skip to content
This repository has been archived by the owner on Nov 12, 2023. It is now read-only.

[EU] Localisation

Madman10K edited this page Aug 10, 2023 · 6 revisions

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"
strings:
  - "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:

strings:
  - 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.

  • The getLocaleName function returns a string containing the short or long name of the provided locale. You can enable short text by setting the last parameter to true and vice-versa
  • The getLocaleID function takes a string formatted in the short locale form and returns the given locale
  • The getLocaleString function takes a string and a locale argument. On call, it fetches the translation of the string for the specified locale and returns it if valid
  • The getCurrentLayout and getFallbackLayout functions are self-explanatory
Clone this wiki locally