Add locale_id in Lang Text component optional

This commit is contained in:
Insality 2021-04-01 20:28:09 +03:00
parent b254448e54
commit fe3ac2e985
2 changed files with 6 additions and 3 deletions

View File

@ -138,3 +138,4 @@ Desc
- Input component: rename field _selected_ to _is_selected_ (according to the docs) - Input component: rename field _selected_ to _is_selected_ (according to the docs)
- Add EmmyLua annotations. See how to use it FAQ - Add EmmyLua annotations. See how to use it FAQ
- Lang text now can be initialized without default locale id

View File

@ -21,7 +21,7 @@ local LangText = component.create("lang_text", { component.ON_LANGUAGE_CHANGE })
--- Component init function --- Component init function
-- @tparam LangText self -- @tparam LangText self
-- @tparam node node The text node -- @tparam node node The text node
-- @tparam string locale_id Default locale id -- @tparam string locale_id Default locale id, optional
-- @tparam bool no_adjust If true, will not correct text size -- @tparam bool no_adjust If true, will not correct text size
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()
@ -30,7 +30,9 @@ function LangText.init(self, node, locale_id, no_adjust)
self.on_change = Event() self.on_change = Event()
if locale_id then
self:translate(locale_id) self:translate(locale_id)
end
return self return self
end end
@ -59,7 +61,7 @@ end
function LangText.translate(self, locale_id, ...) function LangText.translate(self, locale_id, ...)
self.last_locale_args = {...} self.last_locale_args = {...}
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, ...)) self.text:set_to(settings.get_text(self.last_locale, ...) or "")
end end