mirror of
https://github.com/Insality/druid
synced 2025-09-28 02:22:19 +02:00
Update docs
This commit is contained in:
@@ -2,12 +2,13 @@ local event = require("event.event")
|
||||
local component = require("druid.component")
|
||||
local settings = require("druid.system.settings")
|
||||
|
||||
---The component used for displaying localized text, can automatically update text when locale is changed
|
||||
---@class druid.lang_text: druid.component
|
||||
---@field text druid.text
|
||||
---@field node node
|
||||
---@field on_change event
|
||||
---@field private last_locale_args table
|
||||
---@field private last_locale string
|
||||
---@field text druid.text The text component
|
||||
---@field node node The node of the text component
|
||||
---@field on_change event The event triggered when the text is changed
|
||||
---@field private last_locale_args table The last locale arguments
|
||||
---@field private last_locale string The last locale
|
||||
local M = component.create("lang_text")
|
||||
|
||||
|
||||
@@ -38,7 +39,7 @@ end
|
||||
|
||||
---Setup raw text to lang_text component
|
||||
---@param text string Text for text node
|
||||
---@return druid.lang_text Current instance
|
||||
---@return druid.lang_text self Current instance
|
||||
function M:set_to(text)
|
||||
self.last_locale = nil
|
||||
self.text:set_text(text)
|
||||
@@ -50,7 +51,7 @@ end
|
||||
|
||||
---Setup raw text to lang_text component
|
||||
---@param text string Text for text node
|
||||
---@return druid.lang_text Current instance
|
||||
---@return druid.lang_text self Current instance
|
||||
function M:set_text(text)
|
||||
return self:set_to(text)
|
||||
end
|
||||
@@ -59,7 +60,7 @@ end
|
||||
---Translate the text by locale_id
|
||||
---@param locale_id string Locale id
|
||||
---@param ... string Optional params for string.format
|
||||
---@return druid.lang_text Current instance
|
||||
---@return druid.lang_text self Current instance
|
||||
function M:translate(locale_id, ...)
|
||||
self.last_locale_args = { ... }
|
||||
self.last_locale = locale_id or self.last_locale
|
||||
@@ -71,7 +72,7 @@ end
|
||||
|
||||
---Format string with new text params on localized text
|
||||
---@param ... string Optional params for string.format
|
||||
---@return druid.lang_text Current instance
|
||||
---@return druid.lang_text self Current instance
|
||||
function M:format(...)
|
||||
self.last_locale_args = { ... }
|
||||
self.text:set_text(settings.get_text(self.last_locale, ...) or "")
|
||||
|
Reference in New Issue
Block a user