mirror of
https://github.com/Insality/druid
synced 2025-06-27 18:37:45 +02:00
#00 Add more self chaining to Lang text component
This commit is contained in:
parent
30f48f1d27
commit
ef455a71eb
@ -29,6 +29,7 @@ local LangText = component.create("lang_text", { component.ON_LANGUAGE_CHANGE })
|
|||||||
function LangText.init(self, node, locale_id, no_adjust)
|
function LangText.init(self, node, locale_id, no_adjust)
|
||||||
self.druid = self:get_druid()
|
self.druid = self:get_druid()
|
||||||
self.text = self.druid:new_text(node, locale_id, no_adjust)
|
self.text = self.druid:new_text(node, locale_id, no_adjust)
|
||||||
|
self.node = self.text.node
|
||||||
self.last_locale_args = {}
|
self.last_locale_args = {}
|
||||||
|
|
||||||
self.on_change = Event()
|
self.on_change = Event()
|
||||||
@ -51,10 +52,13 @@ end
|
|||||||
--- Setup raw text to lang_text component
|
--- Setup raw text to lang_text component
|
||||||
-- @tparam LangText self
|
-- @tparam LangText self
|
||||||
-- @tparam string text Text for text node
|
-- @tparam string text Text for text node
|
||||||
|
-- @treturn LangText Current instance
|
||||||
function LangText.set_to(self, text)
|
function LangText.set_to(self, text)
|
||||||
self.last_locale = false
|
self.last_locale = false
|
||||||
self.text:set_to(text)
|
self.text:set_to(text)
|
||||||
self.on_change:trigger()
|
self.on_change:trigger()
|
||||||
|
|
||||||
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@ -62,19 +66,25 @@ end
|
|||||||
-- @tparam LangText self
|
-- @tparam LangText self
|
||||||
-- @tparam string locale_id Locale id
|
-- @tparam string locale_id Locale id
|
||||||
-- @tparam string ... Locale arguments to pass in text function
|
-- @tparam string ... Locale arguments to pass in text function
|
||||||
|
-- @treturn LangText Current instance
|
||||||
function LangText.translate(self, locale_id, a, b, c, d, e, f, g)
|
function LangText.translate(self, locale_id, a, b, c, d, e, f, g)
|
||||||
self.last_locale_args = { a, b, c, d, e, f, g }
|
self.last_locale_args = { a, b, c, d, e, f, g }
|
||||||
self.last_locale = locale_id or self.last_locale
|
self.last_locale = locale_id or self.last_locale
|
||||||
self.text:set_to(settings.get_text(self.last_locale, a, b, c, d, e, f, g) or "")
|
self.text:set_to(settings.get_text(self.last_locale, a, b, c, d, e, f, g) or "")
|
||||||
|
|
||||||
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--- Format string with new text params on localized text
|
--- Format string with new text params on localized text
|
||||||
-- @tparam LangText self
|
-- @tparam LangText self
|
||||||
-- @tparam string ... Locale arguments to pass in text function
|
-- @tparam string ... Locale arguments to pass in text function
|
||||||
|
-- @treturn LangText Current instance
|
||||||
function LangText.format(self, a, b, c, d, e, f, g)
|
function LangText.format(self, a, b, c, d, e, f, g)
|
||||||
self.last_locale_args = { a, b, c, d, e, f, g }
|
self.last_locale_args = { a, b, c, d, e, f, g }
|
||||||
self.text:set_to(settings.get_text(self.last_locale, a, b, c, d, e, f, g) or "")
|
self.text:set_to(settings.get_text(self.last_locale, a, b, c, d, e, f, g) or "")
|
||||||
|
|
||||||
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
return LangText
|
return LangText
|
||||||
|
Loading…
x
Reference in New Issue
Block a user