A super lightweight and easy-to-use localization library for GameMaker, written in GML. Works for GameMaker 2.3+
Go to the releases and download the latest .yymps file.
You can then drag the downloaded file into your project, or select Tools > Import Local Package from the toolbar at the top of GameMaker.
Then find and select the downloaded file and import all from there.
Here's an example as to how your localization file should be laid out (before encryption if you are using it)
| English | Italiano | |
|---|---|---|
| text_test | This is test dialogue. | Questo è il dialogo test. |
| hud_test | Health: {x} | Punti Ferita: {x} |
Initializes GMLocale and loads the localization file into memory.
locale_init(_file, [_columnsToIgnore], [_deobfuscationFunction]);| Argument | Type | Description |
|---|---|---|
_file |
String | The file to load (should be a csv, but can be parsed however you'd like through the next parameter) |
_columnsToIgnore |
Array | An array of column indexes that should be skipped when reading the localization file. This is useful if you have additional column(s) that only serve as comments or explanations that shouldn't be loaded into the localization data. Defaults to [] |
[_deobfuscationFunction] |
Function | The function used to deobfuscate the localization file. This is useful if the file is encrypted and you wish to decrypt it on load. Defaults to function(_file){ return load_csv(_file); } |
Nonelocale_init("locale.csv");The above code will load the locale.csv file to be used for localization functions.
Returns a localized string based on a key and locale.
localize(_key, [_locale]);| Argument | Type | Description |
|---|---|---|
_key |
String | The unique key of the string in your localization file. |
[_locale] |
Real | The locale index to localize the string within. Defaults to locale_get() |
Stringvar _greeting = localize("text_greeting");The above code will find the string associated with the "text_greeting" key under the current locale.
Returns a localized string based on a key and locale and inserts a variable in place of any instance of "{x}" within the returned string.
localize_with_variable(_key, _var, [_locale]);| Argument | Type | Description |
|---|---|---|
_key |
String | The unique key of the string in your localization file. |
_var |
String | The string to insert in place of "{x}". |
[_locale] |
Real | The locale index to localize the string within. Defaults to locale_get() |
String// "hud_health" - "HP: {x}"
var _health = localize_with_variable("hud_health", string(global.hp));The above code will get the localized string for "hud_health" and replace all instances of "{x}" with global.hp as a string.
Returns a localized string based on a key and locale and inserts variables in the string from a struct.
localize_with_variables(_key, _struct, [_locale]);| Argument | Type | Description |
|---|---|---|
_key |
String | The unique key of the string in your localization file. |
_struct |
Struct | The struct containing variables to insert into the string. |
[_locale] |
Real | The locale index to localize the string within. Defaults to locale_get() |
String// "text_action" - "{person} is {action}"
var _log = localize_with_variable("text_action", {person: "Carson", action: "Coding");The above code will get the localized string for "text_action" and replace all instances of "{person}" with "Carson" and "{action}" with "Coding".
Returns the index of the current locale.
locale_get()Realvar _locale = locale_get();
locale_set(_locale + 1);The above code will set the locale to the current locale index + 1.
Sets the current locale from it's index.
locale_set(_index);| Argument | Type | Description |
|---|---|---|
_index |
Real | The index of the locale. |
Nonevar _locale = locale_get();
locale_set(_locale + 1);The above code will set the locale to the current locale index + 1.
This function will return the name of a locale from it's index.
locale_get_name([_locale])| Argument | Type | Description |
|---|---|---|
[_locale] |
Real | The locale index to localize the string within. Defaults to locale_get() |
Stringvar _localeName = locale_get_name();The above code will get the name of the current locale.
Returns the index of a locale given it's name. Returns -1 if invalid.
locale_get_index(_name);| Argument | Type | Description |
|---|---|---|
_name |
String | The name of the locale. |
Realvar _englishIndex = locale_get_index("English");The above code will get the index for the locale "English".
Returns an array of strings containing the names of all loaded locales.
locale_get_locales();Array<String>var _locales = locale_get_locales();
for(var i=0; i<array_length(_locales); i++){
show_debug_message(_locales[i]);
}The above code will get the names of all loaded locales and print them to the console.
Returns the count of all loaded locales.
locale_get_count();Realvar _locale = locale_get();
var _localeCount = locale_get_count();
_locale++;
if(_locale >= _localeCount) _locale = 0;
locale_set(_locale);The above code will try to set the locale to the next index, but will loop back to 0 if the new locale is greater than the count.