Localization
The Localization subsystem provides a simple way to creating multilingual applications.
Initialization
Before using the subsystem, the localization string collection(s) need to be loaded. A common practice is to do this at application startup. Multiple collection files can be loaded, and each can define either just one or several languages. For example:
JSON files must be in UTF8 encoding without BOM. Sample files are in the bin/Data directory. The JSON files must have one of the following formats:
LoadJSONFile("StringsEnRu.json")
method will automatically pick the language from the JSON file{"string id 1":{"language 1":"value11","language 2":"value12","language 3":"value13"},"string id 2":{"language 1":"value21","language 2":"value22","language 3":"value23"}}- You must pass 2nd argument to the
LoadJSONFile("StringsLv.json", "lv")
method to tell the parser which language will be loaded{"string id 1": "value 1","string id 2": "value 2","string id 3": "value 3"}
Any number of languages can be defined. Remember that language names and string identifiers are case sensitive. "En" and "en" are considered different languages. During the loading process languages are numbered in order of finding. Indexing starts from zero. The first found language is set to be initially active.
Using
The Get function returns a string with the specified string identifier in the current language.
If the string id is empty, an empty string will be returned. If the translation is not found, the id will be returned unmodified and a warning will be logged.
Use SetLanguage() function to change language at runtime.
When the language is changed, the E_CHANGELANGUAGE event will be sent. Subscribe to it to perform the necessary relocalization of your user interface (texts, sprites etc.)
Text UI elements also support automatic translation to avoid manual work.
Wherein text value is used as an identifier.
Also see the example 40_Localization.