i18n_update_plurals()

The i18n_update_plurals() function is used to update the plural value and the used plural form in the message reference created by using the i18n_create_ref_message() function.

This function can only be used after the i18n_create() function is called.

Syntax

Usage
i18n_update_plurals(var_name, value, [update_refs], [i18n]);
Signature
function i18n_update_plurals(
    var_name: string,
    value: number,
    update_refs?: boolean,         // default = false
    i18n?: I18n | boolean          // default = false (using global i18n struct)
): void

Parameters

NameTypeDefaultDescription
var_nameStringThe name of the variable that store the message reference created by i18n_create_ref_message() function (e.g. global.my_obj.my_msg, my_obj.my_msg, my_arr.0, my_struct.my_msg, etc.).
valueRealThe new plural value (e.g. 0, 10, 213, etc.).
update_refsBooleanfalseUpdate all references (message and asset) to the new plural value and the used plural form.
i18nBoolean | I18nfalseThe i18n struct reference, or leave it empty to use the global i18n struct.

Returns

Void

Examples

Create Event
// assume the system is initialized on global variable, and the locale is "en"

apple_count = 0;

// create a message references with pluralization
ref_msg = i18n_create_ref_message("ref_msg", "shop.has_apple", {
    plural: function(plural_value) {
        switch (i18n_get_locale()) {
            case "en":
                return (plural_value <= 0 ? 0 : (plural_value == 1 ? 1 : 2));
            case "id":
                return (plural_value <= 0 ? 0 : 1);
        }
    },
    plural_value: 0
});
Key Pressed - Up
// increase the apple count
apple_count++;

// update the plural value in the message reference
i18n_update_plurals("ref_msg", apple_count, true);
Key Pressed - Down
// decrease the apple count
apple_count--;

// update the plural value in the message reference
i18n_update_plurals("ref_msg", apple_count, true);
en.json
{
    "hello": "Hello World!",
    "bye": "Goodbye World!",
    "greet": "Hello, {name}!",
    "greet_2": "What a nice day to {0}, right, {1}?",
    "shop": {
        "greet": "Welcome to {shop_name}, {name}!",
        "has_apple": "I don't have any apple. | I have 1 apple. | I have {plural_value} apples."
    }
}
id.json
{
    "hello": "Halo Dunia!",
    "bye": "Sampai jumpa Dunia!",
    "greet": "Halo, {name}!",
    "greet_2": "Hari yang cerah untuk {0}, 'kan, {1}?",
    "shop": {
        "greet": "Selamat datang di {shop_name}, {name}!",
        "has_apple": "Aku tidak punya apel. | Aku punya {plural_value} apel."
    }
}

For the detailed example of this function, you can see the Pluralization section.
You need to use named data for pluralization, with plural (for the pluralization rule) and plural_value (for the value to be passed to the pluralization rule) key. You can't use the indexed data for pluralization. See the Interpolation section for more information.