translation module

Localised string translation and dictionary organization.

See also

Usage

local translation = require("__flib__.translation")

Functions

init() Initial setup.
iterate_batch(event_data) Perform translation operations.
process_result(event_data) Process a received translation.
add_requests(player_index, strings) Add translation requests for the given player, to be performed over the next several ticks.
cancel(player_index) Cancel a player’s translations.
is_translating(player_index) Check whether a player is actively translating.
translating_players_count() Check the number of players currently translating.
serialise_localised_string(localised_string) Serialise a localised string into a form readable by the API.

Concepts

ResultSortData A mapping of a translated string’s dictionaries and internal names.
StringData Dictioanry data for a localised string.

Functions

# init()

Initial setup.

Must be called at the beginning of on_init, and during on_configuration_changed before any translations are started.

This function will effectively cancel all running translations, so if that functionality is desired, this function is a good fit for it.

# iterate_batch(event_data)

Perform translation operations.

Must be called during an on_tick event.

Parameters:
  • event_data : (OnTickEventData)
# process_result(event_data)

Process a received translation.

Must be called during an on_string_translated event.

Parameters:
  • event_data : (OnStringTranslatedEventData)
Returns:
# add_requests(player_index, strings)

Add translation requests for the given player, to be performed over the next several ticks.

Parameters:
# cancel(player_index)

Cancel a player’s translations.

Parameters:
# is_translating(player_index)

Check whether a player is actively translating.

Parameters: Returns:
# translating_players_count()

Check the number of players currently translating.

Returns:
# serialise_localised_string(localised_string)

Serialise a localised string into a form readable by the API.

Gives a similar result to serpent.line(), but is much faster.

Parameters: Returns:

Concepts

# ResultSortData

A mapping of a translated string’s dictionaries and internal names.

Dictionary string –> array of string. Each key is a dictionary name, each value is an array of internal names that the translation matches. Use this data to sort the translation into its appropriate locations.

Usage:
{
  entities = {"crude-oil"},
  fluids = {"crude-oil"}
}
{
  entities = {"iron-ore"},
  items = {"iron-ore"},
  recipes = {"iron-ore"}
}
# StringData

Dictioanry data for a localised string.

  • dictionary : (string) The “dictionary” (subtable) that this string belongs to.
  • internal : (string) The internal name that will be used to reference this string.
  • localised : (LocalisedString) The localised string to translate.
Usage:
{
  {dictionary="fluids", internal="crude-oil", localised={"fluid-name.crude-oil"}},
  {dictionary="items", internal="iron-ore", localised={"item-name.iron-ore"}},
  {dictionary="gui", internal="search-ellipses", localised={"demo-gui.search-ellipses"}}
}