Constructors

Constructors are used to create new instances of a struct. They are used to initialize the struct with the required data.

There are 3 constructors in the GM-I18n API:


I18nLocaleInit

The I18nLocaleInit constructor is used to create a new locale data.

Syntax

Usage
new I18nLocaleInit(lang_code, lang_name, [lang_file]);
Signature
function I18nLocaleInit(
    lang_code: string,
    lang_name: string,
    lang_file?: string | string[]       // default = ""
): I18nLocaleInit
Interface
interface I18nLocaleInit {
    code: string;
    name: string;
    file?: string | string[];
}

Parameters

NameTypeDefaultDescription
lang_codeStringThe locale code, for example en or id.
lang_nameStringThe locale name, for example English or Indonesian.
lang_fileString | String[]""The locale file path, for example ~/langs/en.json. You can also pass an array of string if you want to load multiple files for a single locale.

Returns

I18nLocaleInit

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", "Indonesian", "~/langs/id.json")
]);

// initialize the GM-I18n system with multiple files for a single locale
global.i18n = i18n_create("global.i18n", "en", [
    new I18nLocaleInit("en", "English", ["~/langs/en1.json", "~/langs/en2.json"]),
    new I18nLocaleInit("id", "Indonesian", "~/langs/id.json")
]);
You can use "~/" as a shorthand of working_directory in the lang_file parameter. But if you're targeting on HTML5 export, please don't use this shorthand.

I18nLoad

Internal   The I18nLoad constructor is used to create a new locale files loader.

Syntax

Usage
new I18nLoad(interval, [i18n]);
Signature
function I18nLoad(
    interval: number | number[],
    i18n?: I18n | boolean           // default = false (using global i18n struct)
): I18nLoad
Interface
interface I18nLoad {
    i18n: I18n;
    files: string[];
    files_locale: string[];
    max_step: number;               // integer
    step: number;                   // integer
    step_index: number;             // integer
    step_time: number[];            // integer[]
    time: number | number[];
    dt: () => number;
    update: (
        use_delta_time?: boolean    // default = false
    ) => void;
    load: (
        filename: string, 
        locale: string
    ) => void;
    flatten: (
        struct: { 
            [key: string]: string 
        }, 
        i18n: I18n, 
        locale?: string,            // default = ""
        prefix?: string             // default = ""
    ) => void;
}

Parameters

NameTypeDefaultDescription
intervalRealThe interval between each locale file loading in seconds.
i18nBoolean | I18nfalseThe i18n struct reference, or leave it empty to use the global i18n struct.

Returns

I18nLoad

This constructor is used internally by thei18n_create()function. You don't need to use it directly.

I18nDrawings

The I18nDrawings constructor is used to create a new drawing preset.

Syntax

Usage
new I18nDrawings([draw_font], [draw_halign], [draw_valign], [draw_color], [draw_scale], [draw_rotation], [draw_alpha], [text_sep], [text_width]);
Signature
function I18nDrawings(
    draw_font?: Font,
    draw_halign?: fa_left | fa_center | fa_right,
    draw_valign?: fa_top | fa_middle | fa_bottom,
    draw_color?: number | number[],     // color constants, or color gradient [c1, c2, c3, c4]
    draw_scale?: number,
    draw_rotation?: number,
    draw_alpha?: number,                // 0 - 1
    text_sep?: number,                  // default = -1
    text_width?: number                 // default = room_width
): I18nDrawings
Interface
interface I18nDrawings {
    alpha?: number;                     // 0 - 1
    color?: number | number[];          // color constants, or color gradient [c1, c2, c3, c4]
    draw_type: I18N_DRAW_TEXT;
    font?: Font;
    halign?: fa_left | fa_center | fa_right;
    rotation?: number;
    scale?: number;
    sep: number;                        // default = -1
    valign?: fa_top | fa_middle | fa_bottom;
    width: number;                       // default = room_width
}

Parameters

NameTypeDefaultDescription
draw_fontFont AssetundefinedThe font to use in draw_set_font() function.
draw_halignHAlignundefinedThe horizontal alignment to use in draw_set_halign() function.
draw_valignVAlignundefinedThe vertical alignment to use in draw_set_valign() function.
draw_colorColor | Color[]undefinedThe color to use in draw_set_color() function, or the color gradient to use in draw_text*_color() function.
draw_scaleRealundefinedThe both scale (x_scale and y_scale) of the text.
draw_rotationRealundefinedThe angle (rotation) of the text.
draw_alphaRealundefinedThe opacity (alpha) of the text.
text_sepReal-1The distance between each line (sep) of the text.
text_widthRealroom_widthThe maximum width (w) of the text.

Returns

I18nDrawings

Examples

Raw
// only for explanation purpose, DON'T copy-paste this code
// title
I18nDrawings(fnNotoSans, fa_center, fa_middle, #FFFFFF, 1.2, 0, 1);

// header
I18nDrawings(fnNotoSans, fa_left, fa_middle, #FFFFFF, 1, 0, 1);

// body
I18nDrawings(fnNotoSans, fa_left, fa_top, #CCCCCC, 0.8, 0, 1, 32, 700);

// with other font
I18nDrawings(fnRoboto, fa_right, fa_bottom, #999999, 0.7, 0, 1, -1, 700);

// font asset created from code
I18nDrawings(global.font_ja, fa_left, fa_middle, #FFFFFF, 1, 0, 1);
Create Event
// assume the system is initialized on global variable
// focus only on the I18nDrawings constructor

// standard
i18n_add_drawings("en", "title", 
    new I18nDrawings(fnNotoSans, fa_center, fa_middle, #FFFFFF, 1.2, 0, 1)
);

// completed
i18n_add_drawings("en", "header", 
    new I18nDrawings(fnRoboto, fa_right, fa_bottom, #999999, 0.7, 0, 1, -1, 700)
);

// skip some parameters
i18n_add_drawings("ja", "header", 
    new I18nDrawings(global.font_ja, , , #FFFFFF)
);

i18n_add_drawings("ja", "body", 
    new I18nDrawings(, , , , 0.8, 0, 1, 32, 700)
);
You can skip any parameters you don't want to use. The missing parameters will be ignored when used in i18n_use_drawing() function.

You can read the detailed explanation in the Drawing section.

  These constructors only be used in the GM-I18n initialization process. So, you likely won't need to use them again after the initialization.