i18n_create_ref_message()
The i18n_create_ref_message()
function is used to create a reference to the localized message. This reference will automatically update itself when the locale is changed by calling i18n_set_locale()
function.
This function can only be used after the i18n_create()
function is called.
Syntax
Usage
i18n_create_ref_message(var_name, key, [data], [i18n]);
Parameters
Name | Type | Default | Description |
---|---|---|---|
var_name | String | The name of the variable that will store the message reference. The var_name can be in any level of the instance variable or global variable (e.g. global.my_obj.my_msg , my_obj.my_msg , my_arr.0 , my_struct.my_msg , etc.). | |
key | String | The message key you want to reference (e.g. hello , button.text , menu.help.about , etc.). | |
data | Real | Array | Struct | undefined | The data to pass to the message. You can pass an integer for pluralization, an array for indexed data interpolation, or a struct for named data interpolation (e.g. 1 , ["Hello", "World"] , { name: "John" } ). |
i18n | Boolean | I18n | false | The i18n struct reference, or leave it empty to use the global i18n struct. |
Returns
String
(message based on thekey
in the current locale of thei18n
struct)
Examples
Create Event
// assume the system is initialized on global variable
// the variable name is "msg"
msg = i18n_create_ref_message("msg", "hello");
// the variable name is "button_text"
button_text = i18n_create_ref_message("button_text", "button.text");
// message ref in array, the variable name is "my_arr"
my_arr = [
i18n_create_ref_message("my_arr.0", "hello"), // this reference is created in index 0
i18n_create_ref_message("my_arr.1", "bye"), // this one is in index 1, separate the array index with dot "."
"",
i18n_create_ref_message("my_arr.3", "long_text") // not always need to be created consecutively
];
// message ref in struct, the variable name is "my_struct"
my_struct = {
text : i18n_create_ref_message("my_struct.text", "hello"), // the key is "hello"
button : i18n_create_ref_message("my_struct.button", "button.text"), // the var_name is this struct member name
about : i18n_create_ref_message("my_struct.edit", "menu.help.about"), // separate the struct member with dot "."
nested : {
bye : i18n_create_ref_message("my_struct.nested.bye", "bye") // you can nest the struct as deep as you want
},
arr : [
i18n_create_ref_message("my_struct.arr.0", "hello"), // you can also create the reference in array
i18n_create_ref_message("my_struct.arr.1", "bye")
]
}
// message ref in global variable, the variable name is "global.hello_text"
global.hello_text = i18n_create_ref_message("global.hello_text", "hello"); // use "global" keyword like you're defining a global variable
global.button_text = i18n_create_ref_message("g.button_text", "button.text"); // you can use "g." shorthand for "global."
// message ref in global array
global.gb_arr = [
i18n_create_ref_message("g.gb_arr.0", "hello"), // same as you're creating the reference in instance variable,
i18n_create_ref_message("global.gb_arr.1", "bye") // but use "global." or "g." as the prefix
];
// message ref in global struct
global.gb_struct = {
text : i18n_create_ref_message("global.gb_struct.text", "hello"), // same as you're creating the reference in instance variable,
button : i18n_create_ref_message("g.gb_struct.button", "button.text"), // but use "global." or "g." as the prefix
menu : {
about : i18n_create_ref_message("g.gb_struct.menu.about", "menu.help.about") // a nested struct in global struct
},
arr : [
i18n_create_ref_message("global.gb_struct.arr.0", "hello"), // you can also create the reference in array
i18n_create_ref_message("g.gb_struct.arr.1", "bye")
]
};
The
For the detailed usage of
var_name
is not the name of the message itself. You can name the var_name
as you want, as long as it's unique (no duplicated name) in the same level of the variable. For the detailed usage of
data
parameter, you can see the Interpolation and Pluralization section.You're heavily recommended to create any i18n references in the
Create Event
.Table of Contents