Update docs

This commit is contained in:
Insality
2025-04-15 21:49:22 +03:00
parent e2c9a7d9d6
commit 9e2a14c6dd
48 changed files with 1097 additions and 1289 deletions

View File

@@ -2,19 +2,27 @@
> at /druid/extended/lang_text.lua
The component used for displaying localized text, can automatically update text when locale is changed
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
- [init](#init)
- [on_language_change](#on_language_change)
- [set_to](#set_to)
- [set_text](#set_text)
- [translate](#translate)
- [format](#format)
## Fields
- [text](#text)
- [node](#node)
- [on_change](#on_change)
@@ -31,19 +39,12 @@ 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
- `[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)*:
### on_language_change
---
```lua
lang_text:on_language_change()
```
### set_to
---
@@ -51,7 +52,7 @@ lang_text:on_language_change()
lang_text:set_to(text)
```
Setup raw text to lang_text component
Setup raw text to lang_text component. This will clear any locale settings.
- **Parameters:**
- `text` *(string)*: Text for text node
@@ -66,7 +67,7 @@ Setup raw text to lang_text component
lang_text:set_text(text)
```
Setup raw text to lang_text component
Setup raw text to lang_text component. This will clear any locale settings.
- **Parameters:**
- `text` *(string)*: Text for text node
@@ -81,10 +82,10 @@ Setup raw text to lang_text component
lang_text:translate(locale_id, ...)
```
Translate the text by locale_id
Translate the text by locale_id. The text will be automatically updated when locale changes.
- **Parameters:**
- `locale_id` *(string)*: Locale id
- `locale_id` *(string)*: Locale id to get text from
- `...` *(...)*: vararg
- **Returns:**
@@ -97,7 +98,7 @@ Translate the text by locale_id
lang_text:format(...)
```
Format string with new text params on localized text
Format string with new text params on localized text. Keeps the current locale but updates the format parameters.
- **Parameters:**
- `...` *(...)*: vararg