Module Locale
Description
Module Status: Work in progress.
Usage:
local Locale = require('__eradicators-library__/erlib/factorio/Locale')()
Misc
format_hotkey_tooltip([key[, description]]) | Applies rich text tags to mimic vanilla hotkey tooltips. |
LocalisedString
compress(lstring) | In-place. Fixes very long localised strings. |
normalise(lstring) | Normalises a localised string. |
NormalisedLocalisedString
NormalisedLocalisedString | A strict subset of LocalisedString. |
nlstring_size(nlstring) | Measures the size of a NormalisedLocalisedString. |
nlstring_to_string(nlstring) | Serializes a NormalisedLocalisedString. |
nlstring_is_equal(A, B) | Test if two NormalisedLocalisedStrings are equal. |
Misc
- format_hotkey_tooltip([key[, description]])
-
Applies rich text tags to mimic vanilla hotkey tooltips.
Intended to format tooltips for custom guis that can't
use
"__CONTROL-foobar__
" localisation because LuaGuiElement buttons are hardcoded.Parameters:
Returns:
-
string
A richt-text-tag decorated plain string.
Usage:
game.print{'', Locale.format_hotkey_tooltip('Left mouse button', 'to do something awesome!')}
LocalisedString
- compress(lstring)
-
In-place. Fixes very long localised strings.
Circumvents factorios hard limitation of allowing only up to 20 parameters per key by creating a deeply nested table with <= 20 parameters per level.
Intended to create gui elements or tooltips with procedurally generated content.
Parameters:
- lstring
LocalisedString
A generically
joined localised string
{"", string_1, lstring_2, ...}
. The key must be""
the empty string.
Returns:
-
LocalisedString
A reference to the now compressed input table.
Usage:
local test = {'', 'This', ' ', 'is', ' ', 'a', ' ', 'very', ' ', 'long' , ' ', 'string', ' ', 'that', ' ', 'the', ' ', 'engine' , ' ', 'would', ' ', 'not', ' ', 'normally', ' ', 'allow.'} game.print(test) > Error: Too many parameters for localised string: 25 > 20 (limit). Locale.compress(test) game.print(test) > This is a very long string that the engine would not normally allow.
- lstring
LocalisedString
A generically
joined localised string
- normalise(lstring)
-
Normalises a localised string.
Result is identical to a factorio engine
LuaPlayer.request_translation
→on_string_translated
cycle.Parameters:
- lstring LocalisedString
Returns:
-
NormalisedLocalisedString
NormalisedLocalisedString
- NormalisedLocalisedString
-
A strict subset of LocalisedString.
Contrary to normal LocalisedString a NormalisedLocalisedString does not contain number or nil values. Each number value is cast to string. Each nil value and each
{""}
(key-free localised string without paramters) is replaced by an EmptyString.Localised strings read from Lua*Prototypes (i.e.
localised_name
orlocalised_description
) are pre-normalized by the factorio engine.Processing NormalisedLocalisedString requires fewer type checks, making it significantly faster.
- nlstring_size(nlstring)
-
Measures the size of a NormalisedLocalisedString.
Result is almost identical to#serpent.line(nlstring, {compact = true})
but 50 times faster.The only known differences to serpent is that
\n
(_ escaped newline_) is counted as one byte, but it's string representation has two bytes.Parameters:
- nlstring NormalisedLocalisedString
Returns:
-
NaturalNumber
The approximate size in bytes.
- nlstring_to_string(nlstring)
-
Serializes a NormalisedLocalisedString.
Result is identical toserpent.line(lstring, {compact = true})
but 14 times faster.Parameters:
- nlstring NormalisedLocalisedString
Returns:
- nlstring_is_equal(A, B)
-
Test if two NormalisedLocalisedStrings are equal.
Result is identical toTable.is_equal(A, B)
but 3 times faster.Parameters:
- A NormalisedLocalisedString
- B NormalisedLocalisedString
Returns: