From c548a96a2a0b193822a2db37a1dc60c3d26ff9d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Tinkl?= Date: Thu, 27 Apr 2023 13:30:15 +0200 Subject: [PATCH] fix(Settings/LanguageView): do not change language on the fly disable retranslation, display a confirmation dialog and apply the language change after app restart rationale: the way the retranslation works internally is that it force reevaluation of _all_ QML bindings which: - might lead to crashes (immediately or later) - lots of warnings printed to console, some bindings can get broken as a result - not all UI is correctly retranslated on the fly (we have lots of places where we assign the text imperatively via JS code), so these wouldn't appear translated before app restart anyway Fixes #7823 --- src/app_service/service/language/service.nim | 2 +- .../AppLayouts/Profile/views/LanguageView.qml | 30 ++++--------------- vendor/DOtherSide/lib/src/DOtherSide.cpp | 3 +- 3 files changed, 9 insertions(+), 26 deletions(-) diff --git a/src/app_service/service/language/service.nim b/src/app_service/service/language/service.nim index 18e5f86f5e..8413924503 100644 --- a/src/app_service/service/language/service.nim +++ b/src/app_service/service/language/service.nim @@ -28,7 +28,7 @@ proc delete*(self: Service) = proc newService*(events: EventEmitter): Service = result = Service() result.events = events - result.shouldRetranslate = false #not defined(linux) + result.shouldRetranslate = false proc obtainLanguages(dir: string): seq[string] = let localeRe = re".*qml_(.*).qm" diff --git a/ui/app/AppLayouts/Profile/views/LanguageView.qml b/ui/app/AppLayouts/Profile/views/LanguageView.qml index 36a5352e07..a37a86ebf7 100644 --- a/ui/app/AppLayouts/Profile/views/LanguageView.qml +++ b/ui/app/AppLayouts/Profile/views/LanguageView.qml @@ -39,7 +39,7 @@ SettingsContentBase { function changeLanguage(key) { languagePicker.newKey = key - languagePause.start() + Qt.callLater(root.languageStore.changeLanguage, languagePicker.newKey) } ColumnLayout { @@ -105,14 +105,6 @@ SettingsContentBase { return "" } - Timer { - id: languagePause - interval: 100 - onTriggered: { - // changeLanguage function operation blocks a little bit the UI so getting around it with a small pause (timer) in order to get the desired visual behavior - root.languageStore.changeLanguage(languagePicker.newKey) - } - } objectName: "languagePicker" inputList: SortFilterProxyModel { sourceModel: root.languageStore.languageModel @@ -154,18 +146,9 @@ SettingsContentBase { onItemPickerChanged: { if(selected && root.languageStore.currentLanguage !== key) { - // IMPORTANT: Workaround to temporary resolve the crash we have when language is changed (`startupModule` is null and some qml bindings are still calling this dead pointer) so, change language will not retranslate - // and instead, also on mac and win, the app will quit to apply the new language - // TEMPORARY: It should be removed as it is only used in Linux OS but it must be investigated how to change language in execution time, as well, in Linux (will be addressed in another task) - //if (Qt.platform.os === Constants.linux) { - root.changeLanguage(key) - linuxConfirmationDialog.active = true - linuxConfirmationDialog.item.open() - // } - - //else { - // root.changeLanguage(key) - //} + root.changeLanguage(key) + languageConfirmationDialog.active = true + languageConfirmationDialog.item.open() } } } @@ -206,16 +189,15 @@ SettingsContentBase { } } - // TEMPORARY: It should be removed as it is only used in Linux OS but it must be investigated how to change language in execution time, as well, in Linux (will be addressed in another task) Loader { - id: linuxConfirmationDialog + id: languageConfirmationDialog active: false sourceComponent: ConfirmationDialog { header.title: qsTr("Change language") confirmationText: qsTr("Display language has been changed. You must restart the application for changes to take effect.") confirmButtonLabel: qsTr("Close the app now") onConfirmButtonClicked: { - linuxConfirmationDialog.active = false + languageConfirmationDialog.active = false Qt.quit() } } diff --git a/vendor/DOtherSide/lib/src/DOtherSide.cpp b/vendor/DOtherSide/lib/src/DOtherSide.cpp index 5dfd208dbb..a087687798 100644 --- a/vendor/DOtherSide/lib/src/DOtherSide.cpp +++ b/vendor/DOtherSide/lib/src/DOtherSide.cpp @@ -439,7 +439,8 @@ void dos_qguiapplication_load_translation(::DosQQmlApplicationEngine *vptr, cons if (g_translator.load(translationPackage)) { bool success = QGuiApplication::installTranslator(&g_translator); auto engine = static_cast(vptr); - if (shouldRetranslate) engine->retranslate(); + if (engine && success && shouldRetranslate) + engine->retranslate(); } else { printf("Failed to load translation file %s\n", translationPackage); }