From 489ad7052fedacab1eb0c180993e0234fb30f691 Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Mon, 20 Jul 2020 10:28:32 -0400 Subject: [PATCH] feat: add changeTranslation function --- src/app/profile/core.nim | 4 +- src/app/profile/view.nim | 7 ++- src/nim_status_client.nim | 8 ++- .../Profile/Sections/AdvancedContainer.qml | 31 +++++++++- .../Profile/Sections/Data/locales.js | 62 +++++++++++++++++++ ui/nim-status-client.pro | 1 + ui/shared/Select.qml | 2 +- 7 files changed, 108 insertions(+), 7 deletions(-) create mode 100644 ui/app/AppLayouts/Profile/Sections/Data/locales.js diff --git a/src/app/profile/core.nim b/src/app/profile/core.nim index 1500315bb0..af2210c435 100644 --- a/src/app/profile/core.nim +++ b/src/app/profile/core.nim @@ -18,10 +18,10 @@ type ProfileController* = ref object of SignalSubscriber variant*: QVariant status*: Status -proc newController*(status: Status): ProfileController = +proc newController*(status: Status, changeLanguage: proc(locale: string)): ProfileController = result = ProfileController() result.status = status - result.view = newProfileView(status) + result.view = newProfileView(status, changeLanguage) result.variant = newQVariant(result.view) proc delete*(self: ProfileController) = diff --git a/src/app/profile/view.nim b/src/app/profile/view.nim index ba7768f2a5..68e1ccf07e 100644 --- a/src/app/profile/view.nim +++ b/src/app/profile/view.nim @@ -20,6 +20,7 @@ QtObject: network: string status*: Status isDeviceSetup: bool + changeLanguage*: proc(locale: string) proc setup(self: ProfileView) = self.QObject.setup @@ -31,7 +32,7 @@ QtObject: if not self.profile.isNil: self.profile.delete self.QObject.delete - proc newProfileView*(status: Status): ProfileView = + proc newProfileView*(status: Status, changeLanguage: proc(locale: string)): ProfileView = new(result, delete) result = ProfileView() result.profile = newProfileInfoView() @@ -42,6 +43,7 @@ QtObject: result.network = "" result.status = status result.isDeviceSetup = false + result.changeLanguage = changeLanguage result.setup proc addMailServerToList*(self: ProfileView, mailserver: MailServer) = @@ -117,6 +119,9 @@ QtObject: proc logout*(self: ProfileView) {.slot.} = self.status.profile.logout() + proc changeLocale*(self: ProfileView, locale: string) {.slot.} = + self.changeLanguage(locale) + proc nodeVersion*(self: ProfileView): string {.slot.} = self.status.getNodeVersion() diff --git a/src/nim_status_client.nim b/src/nim_status_client.nim index 7b28f7d58c..562c0f6bf4 100644 --- a/src/nim_status_client.nim +++ b/src/nim_status_client.nim @@ -1,4 +1,4 @@ -import NimQml, eventemitter, chronicles, os +import NimQml, eventemitter, chronicles, os, strformat import app/chat/core as chat import app/wallet/core as wallet @@ -55,7 +55,11 @@ proc mainProc() = var node = node.newController(status) engine.setRootContextProperty("nodeModel", node.variant) - var profile = profile.newController(status) + proc changeLanguage(locale: string) = + echo "CHanging to " & locale + engine.setTranslationPackage(fmt"/home/jonathan/dev/nim-status-client/ui/i18n/qml_{locale}.qm") + + var profile = profile.newController(status, changeLanguage) engine.setRootContextProperty("profileModel", profile.variant) status.events.once("login") do(a: Args): diff --git a/ui/app/AppLayouts/Profile/Sections/AdvancedContainer.qml b/ui/app/AppLayouts/Profile/Sections/AdvancedContainer.qml index cf9d37f7a2..990b1ed23c 100644 --- a/ui/app/AppLayouts/Profile/Sections/AdvancedContainer.qml +++ b/ui/app/AppLayouts/Profile/Sections/AdvancedContainer.qml @@ -3,6 +3,7 @@ import QtQuick.Controls 2.13 import QtQuick.Layouts 1.13 import "../../../../imports" import "../../../../shared" +import "./Data/locales.js" as Locales_JSON Item { property var appSettings @@ -73,11 +74,39 @@ Item { } RowLayout { - id: walletTabSettings + property string currentLocale: "en" // TODO get from settings + id: languageSetting anchors.top: compactModeSetting.bottom anchors.topMargin: 20 anchors.left: parent.left anchors.leftMargin: 24 + StyledText { + text: qsTr("Language") + } + Select { + selectedText: languageSetting.currentLocale + anchors.right: undefined + anchors.left: undefined + width: 100 + Layout.leftMargin: Style.current.padding + selectOptions: Locales_JSON.locales.map(locale => { + return { + text: locale, + onClicked: function () { + profileModel.changeLocale(locale) + languageSetting.currentLocale = locale + } + } + }) + } + } + + RowLayout { + id: walletTabSettings + anchors.top: languageSetting.bottom + anchors.topMargin: 20 + anchors.left: parent.left + anchors.leftMargin: 24 StyledText { //% "Wallet Tab" text: qsTrId("wallet-tab") diff --git a/ui/app/AppLayouts/Profile/Sections/Data/locales.js b/ui/app/AppLayouts/Profile/Sections/Data/locales.js new file mode 100644 index 0000000000..f5995e9aed --- /dev/null +++ b/ui/app/AppLayouts/Profile/Sections/Data/locales.js @@ -0,0 +1,62 @@ +var locales = [ + "af", + "ar", + "bel", + "cs", + "da", + "de", + "de_ch", + "el", + "en", + "es", + "es_419", + "es_ar", + "es_mx", + "fa", + "fi", + "fil", + "fr", + "fr_ch", + "fy", + "he", + "hi", + "hu", + "id", + "it", + "it_ch", + "ja", + "ko", + "la", + "lt", + "lv", + "ms", + "nb", + "ne", + "nl", + "pl", + "pt", + "pt_BR", + "pt_pt", + "ro", + "ru", + "sl", + "sr_rs_cyrl", + "sr_rs_latn", + "sv", + "sw", + "th", + "tr", + "uk", + "ur", + "vi", + "zh", + "zh_Hans_CN", + "zh_TW", + "zh_hans", + "zh_hant", + "zh_hant_hk", + "zh_hant_sg", + "zh_hant_tw", + "zh_wuu", + "zh_yue" + ]; diff --git a/ui/nim-status-client.pro b/ui/nim-status-client.pro index 9cfb259c56..b46f75bc99 100644 --- a/ui/nim-status-client.pro +++ b/ui/nim-status-client.pro @@ -135,6 +135,7 @@ DISTFILES += \ app/AppLayouts/Chat/components/EmojiPopup.qml \ app/AppLayouts/Chat/components/InviteFriendsPopup.qml \ app/AppLayouts/Wallet/components/HeaderButton.qml \ + app/AppLayouts/Profile/Sections/Data/locales.js \ fonts/InterStatus/InterStatus-Black.otf \ fonts/InterStatus/InterStatus-BlackItalic.otf \ fonts/InterStatus/InterStatus-Bold.otf \ diff --git a/ui/shared/Select.qml b/ui/shared/Select.qml index 3acd1bc1a9..bf0c436363 100644 --- a/ui/shared/Select.qml +++ b/ui/shared/Select.qml @@ -130,7 +130,7 @@ Item { Component { id: menuItem MenuItem { - property var onClicked: console.log("Default click function. Override me please") + property var onClicked: function () {} property color bgColor: Style.current.white onTriggered: function () { onClicked()