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:
-locale: "en-US"
origin:
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
andgetFallbackLayout
functions are self-explanatory
- Home
- Beginner concepts
- Advanced concepts
- Engine developer and contributor resources