Lua API

I18N module

Functions for localization.

See the I18N section for more information.

Usage

local I18N = ELONA.require("core.I18N")

Functions

get (key) Gets a localized string and optionally formats it with arguments.
get_optional (key) Gets a localized string and optionally formats it with arguments.
get_enum (key, index) Gets a localized string from an enum-style localization object.
get_enum_optional (key, index) Gets a localized string from an enum-style localization object and optionally formats it with arguments.
get_enum_property (key_base, key_property, index) Gets a localized string from an enum-style localization object where the enum's children are themselves objects.
get_enum_property_optional (key_base, key_property, index) Gets a localized string from an enum-style localization object where the enum's children are themselves objects.
get_data_text (prototype_id, instance_id, property_name) Get a localized text associated with the given data ID.
register_function (language, name, func) Registers a new function for use inside localization files.

Functions

# get (key)

Gets a localized string and optionally formats it with arguments.

This will return a string with a warning if the localization string doesn't exist.

Parameters:
  • key : (string) the ID of the localization string
Returns:
  • (string) the formatted string
Usage:
I18N.get("core.map.you_see", "Vernis")
# get_optional (key)

Gets a localized string and optionally formats it with arguments.

This will return nil if the localization string doesn't exist.

Parameters:
  • key : (string) the ID of the localization string
Returns:
  • (string) the formatted string
Or
# get_enum (key, index)

Gets a localized string from an enum-style localization object.

This will return a string with a warning if the localization string doesn't exist.

Parameters:
  • key : (string) the ID of the localization string
  • index : (num) the index into the enum
Returns:
  • (string) the formatted string
# get_enum_optional (key, index)

Gets a localized string from an enum-style localization object and optionally formats it with arguments.

This will return nil if the localization string doesn't exist.

Parameters:
  • key : (string) the ID of the localization string
  • index : (num) the index into the enum
Returns:
  • (string) the formatted string
Or
# get_enum_property (key_base, key_property, index)

Gets a localized string from an enum-style localization object where the enum's children are themselves objects.

This will return a string with a warning if the localization string doesn't exist.

Parameters:
  • key_base : (string) the base ID of the localization string
  • key_property : (string) the property of the enum object to get
  • index : (num) the index into the enum
Returns:
  • (string) the formatted string
# get_enum_property_optional (key_base, key_property, index)

Gets a localized string from an enum-style localization object where the enum's children are themselves objects.

This will return nil if the localization string doesn't exist.

Parameters:
  • key_base : (string) the base ID of the localization string
  • key_property : (string) the property of the enum object to get
  • index : (num) the index into the enum
Returns:
  • (string) the formatted string
Or
# get_data_text (prototype_id, instance_id, property_name)

Get a localized text associated with the given data ID.

This will return a string with a warning if the localization string doesn't exist.

Parameters:
  • prototype_id : (string) Data prototype ID.
  • instance_id : (string) Data instance ID.
  • property_name : (string) I18N key of the property to get.
Returns:
  • (string) The formatted string
# register_function (language, name, func)

Registers a new function for use inside localization files.

Parameters:
  • language : (string) Localized language the function is valid in
  • name : (string) The function's name
  • func : (function) A function taking arguments and returning a string