2025-04-20 12:15:31 +03:00

2.6 KiB

druid.lang_text API

at /druid/extended/lang_text.lua

The component used for displaying localized text, can automatically update text when locale is changed. It wraps the Text component to handle localization using druid's get_text_function to set text by its id.

Setup

Create lang text component with druid: text = druid:new_lang_text(node_name, locale_id)

Notes

  • Component automatically updates text when locale is changed
  • Uses druid's get_text_function to get localized text by id
  • Supports string formatting with additional parameters

Functions

Fields

init


lang_text:init(node, [locale_id], [adjust_type])
  • Parameters:

    • node (string|node): The node_id or gui.get_node(node_id)
    • [locale_id] (string|nil): Default locale id or text from node as default. If not provided, will use text from the node
    • [adjust_type] (string|nil): Adjust type for text. By default is DOWNSCALE. Look const.TEXT_ADJUST for reference
  • Returns:

    • `` (druid.lang_text):

set_to


lang_text:set_to(text)

Setup raw text to lang_text component. This will clear any locale settings.

  • Parameters:

    • text (string): Text for text node
  • Returns:

    • self (druid.lang_text): Current instance

set_text


lang_text:set_text(text)

Setup raw text to lang_text component. This will clear any locale settings.

  • Parameters:

    • text (string): Text for text node
  • Returns:

    • self (druid.lang_text): Current instance

translate


lang_text:translate(locale_id, ...)

Translate the text by locale_id. The text will be automatically updated when locale changes.

  • Parameters:

    • locale_id (string): Locale id to get text from
    • ... (...): vararg
  • Returns:

    • self (druid.lang_text): Current instance

format


lang_text:format(...)

Format string with new text params on localized text. Keeps the current locale but updates the format parameters.

  • Parameters:

    • ... (...): vararg
  • Returns:

    • self (druid.lang_text): Current instance

Fields

  • text (druid.text): The text component

  • node (node): The node of the text component

  • on_change (event): fun(self: druid.lang_text) The event triggered when the text is changed

  • druid (druid.instance): The Druid Factory used to create components