Localised string translation and dictionary organization.
local translation = require("__flib__.translation")
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. |
ResultSortData | A mapping of a translated string’s dictionaries and internal names. |
StringData | A registry of strings to translate. |
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.
Perform translation operations.
Must be called during an on_tick
event.
Process a received translation.
Must be called during an on_string_translated
event.
Add translation requests for the given player, to be performed over the next several ticks.
Parameters:
Cancel a player’s translations.
Parameters:
Check whether a player is actively translating.
Parameters:
Check the number of players currently translating.
Returns:
Serialise a localised string into a form readable by the API.
Gives a similar result to serpent.line(), but is much faster.
Parameters: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 match to the translated string. This greatly eases the process of sorting translations into various dictionaries.
Usage:{
entities = {"crude-oil"},
fluids = {"crude-oil"}
}
{
entities = {"iron-ore"},
items = {"iron-ore"},
recipes = {"iron-ore"}
}
A registry of strings to translate.
This is an array of tables, each of which contain the following fields:
{
{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"}}
}