Locale module

The text the player reads, in the player's own language.

Properties

  • trx.locale.signals.changed (trx.signal.Signal). Says when the game text changes, such as when the player picks another language or a level brings text of its own. It holds a count that goes up with each change. (read-only)

Structures

  • trx.locale.Text

    Text that looks itself up again in the player's language, for anything that shows text on screen. A label that is given one shows it in the current language, and changes when the player picks another one.

    Text resolves when it is turned into a string, and keeps the result until the game text changes, so showing it again costs nothing. Text made from the same key and arguments is equal.

    Operators:

    • text .. text. Joins text into a new text, whichever side of the .. it is on.
    • text == text. Two texts are equal when they are made from the same parts.
    • #text. The length of the text in the player's language.
    • tostring(text). The text in the player's language.

    Methods:

Functions

  • trx.locale.signals
    The signals the text speaks through, for a script that would rather hear about a change than ask after one.

  • trx.locale.declare(strings)
    Declares game string keys and the text behind them.

    A key belongs with the script that shows it, so a command carries its own wording. What is declared here is a fallback, and it takes only for a key nothing else holds: the strings files, their translations, and any earlier declaration keep the text they already carry.

    Parameters:

    • strings (table). Keys to their English text.

    Example:

    trx.locale.declare({
      ["console/cmd/heal/help"] = "Heals Lara back to full health.",
      ["console/cmd/heal/success"] = "Healed Lara back to full health",
    })
    
  • trx.locale.text_languages()
    The languages that the game has strings files for, by the codes that the language setting takes.

    Returns: a list of string. The codes.

  • trx.locale.voice_languages()
    The dubs installed beside the retail files, by the codes that the audio.media_language setting takes.

    Returns: a list of string. The codes.

  • trx.locale.language_name(code)
    The name a language gives itself in its strings file.

    Parameters:

    • code (string). The language code, such as fr.

    Returns: string or nil. The name, or nil where no strings file names it.

  • trx.locale.get(key)
    The text behind a game string key.

    Parameters:

    • key (string). The key, e.g. general/misc/off.

    Returns: string. The key itself if nothing is behind it, so a typo shows up on screen rather than as a nil further down.

    Example:

    trx.console.log(trx.locale.get("general/misc/off"))
    
  • trx.locale.format(key, ...)
    The text behind a key with its placeholders filled in.

    Parameters:

    • key (string). The key, e.g. general/misc/off.
    • ... (any). What to fill the placeholders with.

    Returns: string. The text with the arguments in it. A translation whose placeholders do not line up with the arguments comes back unformatted, with a warning in the log: a player is better served by text they can read than by a script that stops.

    Example:

    trx.console.log(trx.locale.format("general/misc/pagination_nav", 1, 5))
    
  • trx.locale.reload()
    Reloads the current language's text from disk.

    Returns: boolean. Whether the reload succeeded.

  • trx.locale.text(key, ...)
    The text behind a game string key, as text that follows the player's language. Use it for text that goes on screen, and trx.locale.get for text that a script reads.

    Parameters:

    • key (string). The key, e.g. general/misc/off.
    • ... (any). What to fill the placeholders with. A trx.locale.Text among them follows the player's language too.

    Returns: trx.locale.Text. The text.

    Example:

    local hint = trx.locale.text("general/misc/pagination_nav", 1, 5)
    
  • trx.locale.object_name(object)
    The name the game shows for an object, as text that follows the player's language.

    Parameters:

    Returns: trx.locale.Text. The name, which is empty where the object has none.

  • trx.locale.level_title(level)
    The name the game shows for a level, as text that follows the player's language.

    Parameters:

    Returns: trx.locale.Text. The name.