feat: add changeTranslation function

This commit is contained in:
Jonathan Rainville 2020-07-20 10:28:32 -04:00 committed by Iuri Matias
parent 4bd70b2ce7
commit 489ad7052f
7 changed files with 108 additions and 7 deletions

View File

@ -18,10 +18,10 @@ type ProfileController* = ref object of SignalSubscriber
variant*: QVariant variant*: QVariant
status*: Status status*: Status
proc newController*(status: Status): ProfileController = proc newController*(status: Status, changeLanguage: proc(locale: string)): ProfileController =
result = ProfileController() result = ProfileController()
result.status = status result.status = status
result.view = newProfileView(status) result.view = newProfileView(status, changeLanguage)
result.variant = newQVariant(result.view) result.variant = newQVariant(result.view)
proc delete*(self: ProfileController) = proc delete*(self: ProfileController) =

View File

@ -20,6 +20,7 @@ QtObject:
network: string network: string
status*: Status status*: Status
isDeviceSetup: bool isDeviceSetup: bool
changeLanguage*: proc(locale: string)
proc setup(self: ProfileView) = proc setup(self: ProfileView) =
self.QObject.setup self.QObject.setup
@ -31,7 +32,7 @@ QtObject:
if not self.profile.isNil: self.profile.delete if not self.profile.isNil: self.profile.delete
self.QObject.delete self.QObject.delete
proc newProfileView*(status: Status): ProfileView = proc newProfileView*(status: Status, changeLanguage: proc(locale: string)): ProfileView =
new(result, delete) new(result, delete)
result = ProfileView() result = ProfileView()
result.profile = newProfileInfoView() result.profile = newProfileInfoView()
@ -42,6 +43,7 @@ QtObject:
result.network = "" result.network = ""
result.status = status result.status = status
result.isDeviceSetup = false result.isDeviceSetup = false
result.changeLanguage = changeLanguage
result.setup result.setup
proc addMailServerToList*(self: ProfileView, mailserver: MailServer) = proc addMailServerToList*(self: ProfileView, mailserver: MailServer) =
@ -117,6 +119,9 @@ QtObject:
proc logout*(self: ProfileView) {.slot.} = proc logout*(self: ProfileView) {.slot.} =
self.status.profile.logout() self.status.profile.logout()
proc changeLocale*(self: ProfileView, locale: string) {.slot.} =
self.changeLanguage(locale)
proc nodeVersion*(self: ProfileView): string {.slot.} = proc nodeVersion*(self: ProfileView): string {.slot.} =
self.status.getNodeVersion() self.status.getNodeVersion()

View File

@ -1,4 +1,4 @@
import NimQml, eventemitter, chronicles, os import NimQml, eventemitter, chronicles, os, strformat
import app/chat/core as chat import app/chat/core as chat
import app/wallet/core as wallet import app/wallet/core as wallet
@ -55,7 +55,11 @@ proc mainProc() =
var node = node.newController(status) var node = node.newController(status)
engine.setRootContextProperty("nodeModel", node.variant) 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) engine.setRootContextProperty("profileModel", profile.variant)
status.events.once("login") do(a: Args): status.events.once("login") do(a: Args):

View File

@ -3,6 +3,7 @@ import QtQuick.Controls 2.13
import QtQuick.Layouts 1.13 import QtQuick.Layouts 1.13
import "../../../../imports" import "../../../../imports"
import "../../../../shared" import "../../../../shared"
import "./Data/locales.js" as Locales_JSON
Item { Item {
property var appSettings property var appSettings
@ -73,11 +74,39 @@ Item {
} }
RowLayout { RowLayout {
id: walletTabSettings property string currentLocale: "en" // TODO get from settings
id: languageSetting
anchors.top: compactModeSetting.bottom anchors.top: compactModeSetting.bottom
anchors.topMargin: 20 anchors.topMargin: 20
anchors.left: parent.left anchors.left: parent.left
anchors.leftMargin: 24 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 { StyledText {
//% "Wallet Tab" //% "Wallet Tab"
text: qsTrId("wallet-tab") text: qsTrId("wallet-tab")

View File

@ -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"
];

View File

@ -135,6 +135,7 @@ DISTFILES += \
app/AppLayouts/Chat/components/EmojiPopup.qml \ app/AppLayouts/Chat/components/EmojiPopup.qml \
app/AppLayouts/Chat/components/InviteFriendsPopup.qml \ app/AppLayouts/Chat/components/InviteFriendsPopup.qml \
app/AppLayouts/Wallet/components/HeaderButton.qml \ app/AppLayouts/Wallet/components/HeaderButton.qml \
app/AppLayouts/Profile/Sections/Data/locales.js \
fonts/InterStatus/InterStatus-Black.otf \ fonts/InterStatus/InterStatus-Black.otf \
fonts/InterStatus/InterStatus-BlackItalic.otf \ fonts/InterStatus/InterStatus-BlackItalic.otf \
fonts/InterStatus/InterStatus-Bold.otf \ fonts/InterStatus/InterStatus-Bold.otf \

View File

@ -130,7 +130,7 @@ Item {
Component { Component {
id: menuItem id: menuItem
MenuItem { MenuItem {
property var onClicked: console.log("Default click function. Override me please") property var onClicked: function () {}
property color bgColor: Style.current.white property color bgColor: Style.current.white
onTriggered: function () { onTriggered: function () {
onClicked() onClicked()