From ef455a71eb4663e0f485e4e2550865b817fc449a Mon Sep 17 00:00:00 2001 From: Insality Date: Thu, 27 Jan 2022 01:12:49 +0200 Subject: [PATCH] #00 Add more self chaining to Lang text component --- druid/extended/lang_text.lua | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/druid/extended/lang_text.lua b/druid/extended/lang_text.lua index 06b5a8e..61f473a 100755 --- a/druid/extended/lang_text.lua +++ b/druid/extended/lang_text.lua @@ -29,6 +29,7 @@ local LangText = component.create("lang_text", { component.ON_LANGUAGE_CHANGE }) function LangText.init(self, node, locale_id, no_adjust) self.druid = self:get_druid() self.text = self.druid:new_text(node, locale_id, no_adjust) + self.node = self.text.node self.last_locale_args = {} self.on_change = Event() @@ -51,10 +52,13 @@ end --- Setup raw text to lang_text component -- @tparam LangText self -- @tparam string text Text for text node +-- @treturn LangText Current instance function LangText.set_to(self, text) self.last_locale = false self.text:set_to(text) self.on_change:trigger() + + return self end @@ -62,19 +66,25 @@ end -- @tparam LangText self -- @tparam string locale_id Locale id -- @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) self.last_locale_args = { a, b, c, d, e, f, g } 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 "") + + return self end --- Format string with new text params on localized text -- @tparam LangText self -- @tparam string ... Locale arguments to pass in text function +-- @treturn LangText Current instance function LangText.format(self, 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 "") + + return self end return LangText