From 46aafa4a4d2ecb9e9cd2e0fe65cc3afc489bfa9c Mon Sep 17 00:00:00 2001 From: Sakamoto Shiina <68018796+ShiinaSakamoto@users.noreply.github.com> Date: Mon, 22 Jan 2024 18:20:10 +0900 Subject: [PATCH] =?UTF-8?q?[Update/Refactor]=20Main=20Window:=20Use=20tran?= =?UTF-8?q?slation=20feature=20ON/OFF=E6=99=82=E3=81=AEwidget=E8=AA=BF?= =?UTF-8?q?=E6=95=B4=E3=80=82=20Translation=20Each=20Other=E8=A1=A8?= =?UTF-8?q?=E7=A4=BA=E3=81=AF=E3=80=81=E7=BF=BB=E8=A8=B3=E6=A9=9F=E8=83=BD?= =?UTF-8?q?=E4=BD=BF=E3=82=8F=E3=81=AA=E3=81=84=E5=A0=B4=E5=90=88=E3=81=AF?= =?UTF-8?q?=E5=BF=85=E8=A6=81=E3=81=AE=E3=81=AA=E3=81=84=E6=83=85=E5=A0=B1?= =?UTF-8?q?=E3=81=AA=E3=81=AE=E3=81=A7=E3=80=81=E3=81=9D=E3=81=AE=E6=99=82?= =?UTF-8?q?=E3=81=AFSwap=20Language=E8=A1=A8=E7=A4=BA=E3=81=AB=E5=9B=BA?= =?UTF-8?q?=E5=AE=9A=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- locales/en.yml | 2 +- locales/ja.yml | 2 +- locales/ko.yml | 2 +- view.py | 47 ++++++++++++++----- .../createSidebarLanguagesSettings.py | 12 ++--- 5 files changed, 41 insertions(+), 24 deletions(-) diff --git a/locales/en.yml b/locales/en.yml index 31406a23..24ac7cd7 100644 --- a/locales/en.yml +++ b/locales/en.yml @@ -6,7 +6,7 @@ main_window: language_settings: Language Settings your_language: Your Language - both_direction_desc: Translate Each Other + translate_each_other_label: Translate Each Other swap_button_label: Swap Languages target_language: Target Language translator: Translator diff --git a/locales/ja.yml b/locales/ja.yml index 2b3eb2a8..4d972a18 100644 --- a/locales/ja.yml +++ b/locales/ja.yml @@ -6,7 +6,7 @@ main_window: language_settings: 言語設定 your_language: あなたの言語 - both_direction_desc: 双方向に翻訳 + translate_each_other_label: 双方向に翻訳 swap_button_label: 言語を入れ替え target_language: 相手の言語 translator: 翻訳エンジン diff --git a/locales/ko.yml b/locales/ko.yml index 11e23fae..ff30399f 100644 --- a/locales/ko.yml +++ b/locales/ko.yml @@ -6,7 +6,7 @@ main_window: language_settings: 언어 설정 your_language: 당신의 언어 - both_direction_desc: 양방향으로 번역 + translate_each_other_label: 양방향으로 번역 swap_button_label: 언어 교체 target_language: 상대방의 언어 diff --git a/view.py b/view.py index 20b9678e..3ed71a23 100644 --- a/view.py +++ b/view.py @@ -162,9 +162,10 @@ class View(): IS_OPENED_SELECTABLE_YOUR_LANGUAGE_WINDOW=False, CALLBACK_SELECTED_YOUR_LANGUAGE=None, - VAR_LABEL_BOTH_DIRECTION_DESC=StringVar(value=i18n.t("main_window.both_direction_desc")), - VAR_LABEL_BOTH_DIRECTION_SWAP_BUTTON=StringVar(value=i18n.t("main_window.swap_button_label")), + VAR_LABEL_BOTH_DIRECTION_SWAP_BUTTON=StringVar(value=""), CALLBACK_SWAP_LANGUAGES=None, + CALLBACK_ENTERED_SWAP_LANGUAGES_BUTTON=self._enteredSwapLanguagesButton, + CALLBACK_LEAVED_SWAP_LANGUAGES_BUTTON=self._leavedSwapLanguagesButton, VAR_LABEL_TARGET_LANGUAGE=StringVar(value=i18n.t("main_window.target_language")), VAR_TARGET_LANGUAGE = StringVar(value=f"{config.TARGET_LANGUAGE}\n({config.TARGET_COUNTRY})"), @@ -651,7 +652,9 @@ class View(): if config.USE_TRANSLATION_FEATURE is True: self.useTranslationFeatureProcess("Normal") + self.view_variable.VAR_LABEL_BOTH_DIRECTION_SWAP_BUTTON.set(i18n.t("main_window.translate_each_other_label")) else: + self.view_variable.VAR_LABEL_BOTH_DIRECTION_SWAP_BUTTON.set(i18n.t("main_window.swap_button_label")) self.useTranslationFeatureProcess("Disable") if config.CHOICE_MIC_HOST == "NoHost": @@ -879,27 +882,34 @@ class View(): } def useTranslationFeatureProcess(self, state:str): + def changeWidget_UseTranslationFeature(): + vrct_gui.sls__box_translation_optionmenu_wrapper.grid() + vrct_gui.compact_mode_translation_frame.grid() + vrct_gui.translation_frame.grid() + self.view_variable.VAR_LABEL_BOTH_DIRECTION_SWAP_BUTTON.set(i18n.t("main_window.translate_each_other_label")) + + def changeWidget_DontUseTranslationFeature(): + vrct_gui.sls__box_translation_optionmenu_wrapper.grid_remove() + vrct_gui.compact_mode_translation_frame.grid_remove() + vrct_gui.translation_frame.grid_remove() + self.view_variable.VAR_LABEL_BOTH_DIRECTION_SWAP_BUTTON.set(i18n.t("main_window.swap_button_label")) + + if state == "Normal": self.setLatestCTranslate2WeightType() self.openCtranslate2WeightTypeWidget() self.setTranslationSwitchStatus("normal", release_locked_state=True) - vrct_gui.sls__box_translation_optionmenu_wrapper.grid() - vrct_gui.compact_mode_translation_frame.grid() - vrct_gui.translation_frame.grid() + changeWidget_UseTranslationFeature() elif state == "Disable": view.closeCtranslate2WeightTypeWidget() view.setTranslationSwitchStatus("disabled", to_lock_state=True) - vrct_gui.sls__box_translation_optionmenu_wrapper.grid_remove() - vrct_gui.compact_mode_translation_frame.grid_remove() - vrct_gui.translation_frame.grid_remove() + changeWidget_DontUseTranslationFeature() elif state == "Restart": view.setLatestCTranslate2WeightType() view.setTranslationSwitchStatus("disabled", to_lock_state=True) - vrct_gui.sls__box_translation_optionmenu_wrapper.grid() - vrct_gui.compact_mode_translation_frame.grid() - vrct_gui.translation_frame.grid() + changeWidget_UseTranslationFeature() vrct_gui.update() vrct_gui.config_window.lift() @@ -1221,7 +1231,7 @@ class View(): self._clearEntryBox(vrct_gui.config_window.sb__entry_mic_word_filter_list) -# Widget Control (Whole) +# Widget Control def foregroundOnIfForegroundEnabled(self): if config.ENABLE_FOREGROUND: self.foregroundOn() @@ -1279,6 +1289,19 @@ class View(): vrct_gui.main_send_message_button_container.grid() vrct_gui.config_window.after(200, vrct_gui.config_window.lift) + def _enteredSwapLanguagesButton(self): + self.view_variable.VAR_LABEL_BOTH_DIRECTION_SWAP_BUTTON.set(i18n.t("main_window.swap_button_label")) + vrct_gui.sls__both_direction_desc.configure( + text_color=self.settings.main.ctm.SLS__BOX_ARROWS_SWAP_BUTTON_TEXT_COLOR, + ) + + def _leavedSwapLanguagesButton(self): + if config.USE_TRANSLATION_FEATURE is True: + self.view_variable.VAR_LABEL_BOTH_DIRECTION_SWAP_BUTTON.set(i18n.t("main_window.translate_each_other_label")) + vrct_gui.sls__both_direction_desc.configure( + text_color=self.settings.main.ctm.SLS__BOX_ARROWS_TEXT_COLOR, + ) + # Function def _adjustUiSizeAndRestart(self): current_percentage = int(config.UI_SCALING.replace("%","")) diff --git a/vrct_gui/main_window/widgets/_create_sidebar/createSidebarLanguagesSettings.py b/vrct_gui/main_window/widgets/_create_sidebar/createSidebarLanguagesSettings.py index e85e084a..6678ffd3 100644 --- a/vrct_gui/main_window/widgets/_create_sidebar/createSidebarLanguagesSettings.py +++ b/vrct_gui/main_window/widgets/_create_sidebar/createSidebarLanguagesSettings.py @@ -250,7 +250,7 @@ def createSidebarLanguagesSettings(settings, main_window, view_variable): main_window.sls__both_direction_desc = CTkLabel( main_window.sls__arrow_direction_swap_box, - textvariable=view_variable.VAR_LABEL_BOTH_DIRECTION_DESC, + textvariable=view_variable.VAR_LABEL_BOTH_DIRECTION_SWAP_BUTTON, height=0, font=CTkFont(family=settings.FONT_FAMILY, size=settings.uism.SLS__BOX_ARROWS_DESC_FONT_SIZE, weight="normal"), text_color=settings.ctm.SLS__BOX_ARROWS_TEXT_COLOR, @@ -286,16 +286,10 @@ def createSidebarLanguagesSettings(settings, main_window, view_variable): def adjustedCommand_Entered(): - main_window.sls__both_direction_desc.configure( - textvariable=view_variable.VAR_LABEL_BOTH_DIRECTION_SWAP_BUTTON, - text_color=settings.ctm.SLS__BOX_ARROWS_SWAP_BUTTON_TEXT_COLOR, - ) + callFunctionIfCallable(view_variable.CALLBACK_ENTERED_SWAP_LANGUAGES_BUTTON) def adjustedCommand_Leaved(): - main_window.sls__both_direction_desc.configure( - textvariable=view_variable.VAR_LABEL_BOTH_DIRECTION_DESC, - text_color=settings.ctm.SLS__BOX_ARROWS_TEXT_COLOR, - ) + callFunctionIfCallable(view_variable.CALLBACK_LEAVED_SWAP_LANGUAGES_BUTTON) bindEnterAndLeaveFunction( target_widgets=[