i18n_get_messages()
The i18n_get_messages()
function is used to get the localized message from the GM-I18n system.
This function can only be used after the i18n_create()
function is called.
Syntax
Usage
i18n_get_messages(key, [data], [locale], [i18n]);
Parameters
Name | Type | Default | Description |
---|---|---|---|
key | String | String[] | The message key(s) to get (e.g. hello , bye , long_text , etc.). You can pass a string for single message, or an array of string for multiple messages (e.g. ["hello", "bye", "long_text"] ). | |
data | Integer | Any[] | Struct | undefined | The data to pass to the message, whether it's for pluralization (Integer ), indexed interpolation (Any[] ), or named interpolation (Struct ). |
locale | String | "" | The locale code to get the message from (e.g. en , id , ja , etc.). Leave it empty to get the message from the current locale. |
i18n | Boolean | I18n | false | The i18n struct reference, or leave it empty to use the global i18n struct. |
Returns
String
orString[]
Examples
Create Event
// assume the system is initialized on global variable
// get a message from "hello" key, from "en" locale
msg = i18n_get_messages("hello", , "en"); // "Hello World!"
// get a message from "bye" key, from current locale
msg = i18n_get_messages("bye"); // "Goodbye World!" (if the current locale is "en")
// get multiple messages from "hello" and "bye" key, from "id" locale
msg = i18n_get_messages(["hello", "bye"], , "id"); // ["Halo Dunia!", "Sampai jumpa Dunia!"]
// get a message from "greet" key, from current locale
// using named data interpolation
msg = i18n_get_messages("greet", {
name: "John" // {name} = "John"
}); // "Hello, John!" (if the current locale is "en")
// get a message from "greet_2" key, from "id" locale
// using indexed data interpolation
player_name = "John";
msg = i18n_get_messages("greet_2", [
"memancing", player_name // {0} = "memancing", {1} = player_name = "John"
], "id"); // "Hari yang cerah untuk memancing, 'kan, John?"
// get a message from "shop.has_apple" key, from current locale
// using static pluralization
apple_count = 0;
msg = i18n_get_messages("shop.has_apple", {
plural: 0, // use the first form (index 0) (static)
plural_value: apple_count // interpolate the {plural_value} placeholder
}); // "I don't have any apple" (if the current locale is "en")
// get multiple message from "greet" and "shop.greet" keys, from "en" locale
// using named data interpolation
msg = i18n_get_messages(["greet", "shop.greet"], {
name: "John", // {name} = "John"
shop_name: "The Chosen Apple" // {shop_name} = "The Chosen Apple"
}, "en"); // ["Hello, John!", "Welcome to The Chosen Apple, John!"]
The
You can pass an array of keys to the
If you pass a data to the
For the detailed usage of this function, you can see the Messages, Interpolation, and Pluralization section.
data
parameter is optional. You can leave it empty if you don't want to interpolate the message. You can pass an array of keys to the
key
parameter to get multiple messages at once. The function will return an array of messages. If you pass a data to the
data
parameter and you pass an array of keys to the key
parameter, the data will be applied to all of the messages. For the detailed usage of this function, you can see the Messages, Interpolation, and Pluralization section.
Table of Contents