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:

  • key string The hotkey (optional)
  • description string The description (optional)

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.
    
normalise(lstring)
Normalises a localised string.

Result is identical to a factorio engine LuaPlayer.request_translationon_string_translated cycle.

Parameters:

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 or localised_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 to serpent.line(lstring, {compact = true}) but 14 times faster.

Parameters:

  • nlstring NormalisedLocalisedString

Returns:

    string
nlstring_is_equal(A, B)
Test if two NormalisedLocalisedStrings are equal.
Result is identical to Table.is_equal(A, B) but 3 times faster.

Parameters:

  • A NormalisedLocalisedString
  • B NormalisedLocalisedString

Returns:

    boolean
generated by LDoc 1.4.6 Last updated 2021-09-10 19:51:19