IAVRA.I18N.language; Returns the current language.
IAVRA.I18N.language = lang; Sets the current language to lang.
IAVRA.I18N.languages(); Returns a list of all available languages.
IAVRA.I18N.localize(text); Localizes the given text.
Plugin
Iavra Localization - Core
Description
The core plugin for localization, which contains all logic to load text and convert escape codes.
Parameters
@param Escape Code
@desc Code, that will be used to retrieve localized strings. "{key}" serves as placeholder for the text key.
@default #{{key}}
@param Languages
@desc Comma-separated list of languages, that should be supported. The first entry will be used as the default.
@default en
@param File Path
@desc Path to the language files to load. The sequence "{lang}" will be replaced with the languages entered above.
@default {lang}.json
How to Use
To setup this plugin, register all supported languages inside the "Languages" parameter, separated by commas. You also need to place the corresponding files inside your project folder. So, for example, if you want to support the languages "en" (english) and "de" (german) and the parameter "File Path" is set to its default value, you'll need to add the two files "de.json" and "en.json" to the root folder of your project.
The first language will automatically used as the default langage.
During runtime, every instance of "#{...}" (can be changed via plugin parameter "Escape Code") will get replaced with a localized string, where "..." stands for a text key. So, if your language file looks like this:
{
"text.test": "This is a test text"
}
Every instance of "#{text.test}" will be replaced with "This is a test text". For better maintainability, it's also possible to split keys at dots:
{
"text": {
"test": "This is a test text"
}
}
The above example will result in the same key as the first one, but makes it easier to construct nested keys, for example for the names of all actors. Instead of objects, you can also use arrays, like this:
{
"text": [
"Text 1",
"Text 2",
"Text 3"
]
}
This will create the keys "text.0", "text.1" and "text.2", each pointing to the text listed at that array index. If needed, you are free to combine the object and array notations.
Keys can also contain keys themselves, which will be replaced recursively. This allows you, to define important strings, like city names, at a single position and reference it everywhere else:
{
"text": "Hi, my name is #{actor}",
"actor": "Harold"
}
You can use all escape characters, like "\V[...]" inside the files, but will need to double the backslashes. Line breaks can be entered by using "\n", since JSON doesn't support real linebreaks inside strings.
The plugin offers the following script calls:
Code:
IAVRA.I18N.language; Returns the current language.
IAVRA.I18N.language = lang; Sets the current language to lang.
IAVRA.I18N.languages(); Returns a list of all available languages.
IAVRA.I18N.localize(text); Localizes the given text.