From f534baf2ee1379389e2c4c61fc8952107515549e Mon Sep 17 00:00:00 2001 From: Insality Date: Thu, 27 Jan 2022 18:31:33 +0200 Subject: [PATCH] #163 Default locale id from text node for lang_text component --- druid/extended/lang_text.lua | 6 ++---- example/examples/general/overview/overview.gui | 16 ++++++++-------- .../general/overview/overview.gui_script | 16 ++++++++-------- 3 files changed, 18 insertions(+), 20 deletions(-) diff --git a/druid/extended/lang_text.lua b/druid/extended/lang_text.lua index 658d8a8..b801890 100755 --- a/druid/extended/lang_text.lua +++ b/druid/extended/lang_text.lua @@ -24,7 +24,7 @@ local LangText = component.create("lang_text") --- Component init function -- @tparam LangText self -- @tparam node node The text node --- @tparam string locale_id Default locale id, optional +-- @tparam string locale_id Default locale id or text from node as default -- @tparam bool no_adjust If true, will not correct text size function LangText.init(self, node, locale_id, no_adjust) self.druid = self:get_druid() @@ -34,9 +34,7 @@ function LangText.init(self, node, locale_id, no_adjust) self.on_change = Event() - if locale_id then - self:translate(locale_id) - end + self:translate(locale_id or gui.get_text(self.node)) return self end diff --git a/example/examples/general/overview/overview.gui b/example/examples/general/overview/overview.gui index 45dc4b9..d78289b 100644 --- a/example/examples/general/overview/overview.gui +++ b/example/examples/general/overview/overview.gui @@ -210,7 +210,7 @@ nodes { } type: TYPE_TEXT blend_mode: BLEND_MODE_ALPHA - text: "Button:" + text: "ui_section_button" font: "game" id: "text_button" xanchor: XANCHOR_NONE @@ -604,7 +604,7 @@ nodes { } type: TYPE_TEXT blend_mode: BLEND_MODE_ALPHA - text: "Text:" + text: "ui_section_text" font: "game" id: "text_text" xanchor: XANCHOR_NONE @@ -848,7 +848,7 @@ nodes { } type: TYPE_TEXT blend_mode: BLEND_MODE_ALPHA - text: "Timer:" + text: "ui_section_timer" font: "game" id: "text_timer" xanchor: XANCHOR_NONE @@ -1029,7 +1029,7 @@ nodes { } type: TYPE_TEXT blend_mode: BLEND_MODE_ALPHA - text: "Progress bar:" + text: "ui_section_progress" font: "game" id: "text_progress" xanchor: XANCHOR_NONE @@ -1320,7 +1320,7 @@ nodes { } type: TYPE_TEXT blend_mode: BLEND_MODE_ALPHA - text: "Slider:" + text: "ui_section_slider" font: "game" id: "text_slider" xanchor: XANCHOR_NONE @@ -1611,7 +1611,7 @@ nodes { } type: TYPE_TEXT blend_mode: BLEND_MODE_ALPHA - text: "Radio:" + text: "ui_section_radio" font: "game" id: "text_radio" xanchor: XANCHOR_NONE @@ -2234,7 +2234,7 @@ nodes { } type: TYPE_TEXT blend_mode: BLEND_MODE_ALPHA - text: "Checkbox:" + text: "ui_section_checkbox" font: "game" id: "text_checkbox" xanchor: XANCHOR_NONE @@ -2857,7 +2857,7 @@ nodes { } type: TYPE_TEXT blend_mode: BLEND_MODE_ALPHA - text: "Input:" + text: "ui_section_input" font: "game" id: "text_input" xanchor: XANCHOR_NONE diff --git a/example/examples/general/overview/overview.gui_script b/example/examples/general/overview/overview.gui_script index 6d7a5d1..e01f846 100644 --- a/example/examples/general/overview/overview.gui_script +++ b/example/examples/general/overview/overview.gui_script @@ -25,14 +25,14 @@ end local function setup_texts(self) - self.druid:new_lang_text("text_button", "ui_section_button") - self.druid:new_lang_text("text_text", "ui_section_text") - self.druid:new_lang_text("text_timer", "ui_section_timer") - self.druid:new_lang_text("text_progress", "ui_section_progress") - self.druid:new_lang_text("text_slider", "ui_section_slider") - self.druid:new_lang_text("text_radio", "ui_section_radio") - self.druid:new_lang_text("text_checkbox", "ui_section_checkbox") - self.druid:new_lang_text("text_input", "ui_section_input") + self.druid:new_lang_text("text_button") + self.druid:new_lang_text("text_text") + self.druid:new_lang_text("text_timer") + self.druid:new_lang_text("text_progress") + self.druid:new_lang_text("text_slider") + self.druid:new_lang_text("text_radio") + self.druid:new_lang_text("text_checkbox") + self.druid:new_lang_text("text_input") self.druid:new_lang_text("text_translated", "ui_text_example") self.druid:new_lang_text("text_button_lang", "ui_text_change_lang")