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
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) =

View File

@ -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()

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/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):

View File

@ -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")

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/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 \

View File

@ -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()