i18n_create()
The i18n_create()
function is used to create a new GM-I18n system. This function will initialize the i18n system and return a struct reference to it.
This is the most important function in the GM-I18n API. You must call this function before using any other functions in the API.
Syntax
Usage
i18n_create(var_name, default_locale, locales, [options]);
Parameters
Name | Type | Default | Description |
---|---|---|---|
var_name | String | The name of the variable to store the i18n system (e.g. global.i18n ). Use global keyword if you want to store it in global variable. | |
default_locale | String | The default locale code to use (e.g. en , id , ja , etc.). | |
locales | I18nLocaleInit[] | The array of I18nLocaleInit struct to initialize the available locales. | |
options | Boolean | Struct | false | The options to configure the i18n system. You can pass your desired options as a struct (e.g. { debug: true, default_message: "N/A" } ). |
Returns
I18n
Examples
Create Event
// initialize the GM-I18n system
global.i18n = i18n_create("global.i18n", "en", [
new I18nLocaleInit("en", "English", "~/langs/en.json"),
new I18nLocaleInit("id", "Bahasa Indonesia", "~/langs/id.json")
]);
// initialize the GM-I18n system with options
global.i18n = i18n_create("global.i18n", "en", [
new I18nLocaleInit("en", "English", "~/langs/en.json"),
new I18nLocaleInit("id", "Bahasa Indonesia", "~/langs/id.json"),
new I18nLocaleInit("ja", "日本語", "~/langs/ja.json")
], {
debug: true,
default_message: "N/A",
hashed: true,
plural_start_at: 1,
time: 0.5
});
// initialize the GM-I18n system in instance variable (not recommended)
i18n = i18n_create("i18n", "en", [
new I18nLocaleInit("en", "English", "~/langs/en.json"),
new I18nLocaleInit("id", "Bahasa Indonesia", "~/langs/id.json")
]);
The
You can optimize the locale files loading by using the
i18n_create()
function will automatically set the global.i18n_name
variable to the name of the i18n system you created. You can use this variable to access the i18n system from anywhere in your game. You can optimize the locale files loading by using the
time
option. Please read the Chunk Loading section for more information.Though you can create multiple GM-I18n system, it's not recommended, unless you know what you're doing.
You're heavily recommended to use
global
variable to store the i18n system.Table of Contents