refactor(@desktop/settings-language): language settings added
This commit is contained in:
parent
46869afa5f
commit
b4df87b7a6
|
@ -1,4 +1,4 @@
|
||||||
import NimQml, os, strformat
|
import NimQml
|
||||||
|
|
||||||
import ../../app_service/common/utils
|
import ../../app_service/common/utils
|
||||||
|
|
||||||
|
@ -39,28 +39,6 @@ import ../global/global_singleton
|
||||||
|
|
||||||
import ../core/[main]
|
import ../core/[main]
|
||||||
|
|
||||||
var i18nPath = ""
|
|
||||||
if defined(development):
|
|
||||||
i18nPath = joinPath(getAppDir(), "../ui/i18n")
|
|
||||||
elif (defined(windows)):
|
|
||||||
i18nPath = joinPath(getAppDir(), "../resources/i18n")
|
|
||||||
elif (defined(macosx)):
|
|
||||||
i18nPath = joinPath(getAppDir(), "../i18n")
|
|
||||||
elif (defined(linux)):
|
|
||||||
i18nPath = joinPath(getAppDir(), "../i18n")
|
|
||||||
|
|
||||||
proc setLanguage(locale: string) =
|
|
||||||
let shouldRetranslate = not defined(linux)
|
|
||||||
singletonInstance.engine.setTranslationPackage(joinPath(i18nPath, fmt"qml_{locale}.qm"), shouldRetranslate)
|
|
||||||
|
|
||||||
proc changeLanguage(locale: string) =
|
|
||||||
let currentLanguageCode = singletonInstance.localAppSettings.getLocale()
|
|
||||||
if (locale == currentLanguageCode):
|
|
||||||
return
|
|
||||||
|
|
||||||
singletonInstance.localAppSettings.setLocale(locale)
|
|
||||||
setLanguage(locale)
|
|
||||||
|
|
||||||
type
|
type
|
||||||
AppController* = ref object of RootObj
|
AppController* = ref object of RootObj
|
||||||
statusFoundation: StatusFoundation
|
statusFoundation: StatusFoundation
|
||||||
|
@ -230,6 +208,7 @@ proc delete*(self: AppController) =
|
||||||
self.startupModule.delete
|
self.startupModule.delete
|
||||||
self.mainModule.delete
|
self.mainModule.delete
|
||||||
self.ethService.delete
|
self.ethService.delete
|
||||||
|
self.languageService.delete
|
||||||
|
|
||||||
self.localAppSettingsVariant.delete
|
self.localAppSettingsVariant.delete
|
||||||
self.localAccountSettingsVariant.delete
|
self.localAccountSettingsVariant.delete
|
||||||
|
@ -261,9 +240,8 @@ proc startupDidLoad*(self: AppController) =
|
||||||
singletonInstance.engine.setRootContextProperty("localAccountSettings", self.localAccountSettingsVariant)
|
singletonInstance.engine.setRootContextProperty("localAccountSettings", self.localAccountSettingsVariant)
|
||||||
singletonInstance.engine.load(newQUrl("qrc:///main.qml"))
|
singletonInstance.engine.load(newQUrl("qrc:///main.qml"))
|
||||||
|
|
||||||
# We need to set a language once qml is loaded
|
# We need to init a language service once qml is loaded
|
||||||
let locale = singletonInstance.localAppSettings.getLocale()
|
self.languageService.init()
|
||||||
setLanguage(locale)
|
|
||||||
|
|
||||||
proc mainDidLoad*(self: AppController) =
|
proc mainDidLoad*(self: AppController) =
|
||||||
self.statusFoundation.onLoggedIn()
|
self.statusFoundation.onLoggedIn()
|
||||||
|
@ -289,7 +267,6 @@ proc load(self: AppController) =
|
||||||
self.providerService.init()
|
self.providerService.init()
|
||||||
self.walletAccountService.init()
|
self.walletAccountService.init()
|
||||||
self.transactionService.init()
|
self.transactionService.init()
|
||||||
self.languageService.init()
|
|
||||||
self.stickersService.init()
|
self.stickersService.init()
|
||||||
self.networkService.init()
|
self.networkService.init()
|
||||||
self.activityCenterService.init()
|
self.activityCenterService.init()
|
||||||
|
|
|
@ -30,7 +30,7 @@ import ../../../app_service/service/accounts/service as accounts_service
|
||||||
import ../../../app_service/service/settings/service_interface as settings_service
|
import ../../../app_service/service/settings/service_interface as settings_service
|
||||||
import ../../../app_service/service/contacts/service as contacts_service
|
import ../../../app_service/service/contacts/service as contacts_service
|
||||||
import ../../../app_service/service/about/service as about_service
|
import ../../../app_service/service/about/service as about_service
|
||||||
import ../../../app_service/service/language/service as language_service
|
import ../../../app_service/service/language/service_interface as language_service
|
||||||
import ../../../app_service/service/mnemonic/service as mnemonic_service
|
import ../../../app_service/service/mnemonic/service as mnemonic_service
|
||||||
import ../../../app_service/service/privacy/service as privacy_service
|
import ../../../app_service/service/privacy/service as privacy_service
|
||||||
import ../../../app_service/service/stickers/service as stickers_service
|
import ../../../app_service/service/stickers/service as stickers_service
|
||||||
|
|
|
@ -29,6 +29,9 @@ method contactsModuleDidLoad*(self: AccessInterface) {.base.} =
|
||||||
method languageModuleDidLoad*(self: AccessInterface) {.base.} =
|
method languageModuleDidLoad*(self: AccessInterface) {.base.} =
|
||||||
raise newException(ValueError, "No implementation available")
|
raise newException(ValueError, "No implementation available")
|
||||||
|
|
||||||
|
method getLanguageModule*(self: AccessInterface): QVariant {.base.} =
|
||||||
|
raise newException(ValueError, "No implementation available")
|
||||||
|
|
||||||
method mnemonicModuleDidLoad*(self: AccessInterface) {.base.} =
|
method mnemonicModuleDidLoad*(self: AccessInterface) {.base.} =
|
||||||
raise newException(ValueError, "No implementation available")
|
raise newException(ValueError, "No implementation available")
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
import ./controller_interface
|
import ./controller_interface
|
||||||
import io_interface
|
import io_interface
|
||||||
import ../../../../../app_service/service/language/service as language_service
|
import ../../../../../app_service/service/language/service_interface as language_service
|
||||||
|
|
||||||
# import ./item as item
|
|
||||||
|
|
||||||
export controller_interface
|
export controller_interface
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
import ../../../../../app_service/service/language/service as language_service
|
|
||||||
|
|
||||||
type
|
type
|
||||||
AccessInterface* {.pure inheritable.} = ref object of RootObj
|
AccessInterface* {.pure inheritable.} = ref object of RootObj
|
||||||
## Abstract class for any input/interaction with this module.
|
## Abstract class for any input/interaction with this module.
|
||||||
|
@ -11,9 +9,4 @@ method init*(self: AccessInterface) {.base.} =
|
||||||
raise newException(ValueError, "No implementation available")
|
raise newException(ValueError, "No implementation available")
|
||||||
|
|
||||||
method changeLanguage*(self: AccessInterface, locale: string) {.base.} =
|
method changeLanguage*(self: AccessInterface, locale: string) {.base.} =
|
||||||
raise newException(ValueError, "No implementation available")
|
raise newException(ValueError, "No implementation available")
|
||||||
|
|
||||||
type
|
|
||||||
## Abstract class (concept) which must be implemented by object/s used in this
|
|
||||||
## module.
|
|
||||||
DelegateInterface* = concept c
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
import NimQml
|
||||||
|
|
||||||
type
|
type
|
||||||
AccessInterface* {.pure inheritable.} = ref object of RootObj
|
AccessInterface* {.pure inheritable.} = ref object of RootObj
|
||||||
## Abstract class for any input/interaction with this module.
|
## Abstract class for any input/interaction with this module.
|
||||||
|
@ -11,6 +13,9 @@ method load*(self: AccessInterface) {.base.} =
|
||||||
method isLoaded*(self: AccessInterface): bool {.base.} =
|
method isLoaded*(self: AccessInterface): bool {.base.} =
|
||||||
raise newException(ValueError, "No implementation available")
|
raise newException(ValueError, "No implementation available")
|
||||||
|
|
||||||
|
method getModuleAsVariant*(self: AccessInterface): QVariant {.base.} =
|
||||||
|
raise newException(ValueError, "No implementation available")
|
||||||
|
|
||||||
method changeLanguage*(self: AccessInterface, locale: string) {.base.} =
|
method changeLanguage*(self: AccessInterface, locale: string) {.base.} =
|
||||||
raise newException(ValueError, "No implementation available")
|
raise newException(ValueError, "No implementation available")
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ import ./io_interface, ./view, ./controller
|
||||||
import ../io_interface as delegate_interface
|
import ../io_interface as delegate_interface
|
||||||
import ../../../../global/global_singleton
|
import ../../../../global/global_singleton
|
||||||
|
|
||||||
import ../../../../../app_service/service/language/service as language_service
|
import ../../../../../app_service/service/language/service_interface as language_service
|
||||||
|
|
||||||
export io_interface
|
export io_interface
|
||||||
|
|
||||||
|
@ -24,8 +24,6 @@ proc newModule*(delegate: delegate_interface.AccessInterface, languageService: l
|
||||||
result.controller = controller.newController(result, languageService)
|
result.controller = controller.newController(result, languageService)
|
||||||
result.moduleLoaded = false
|
result.moduleLoaded = false
|
||||||
|
|
||||||
singletonInstance.engine.setRootContextProperty("languageModule", result.viewVariant)
|
|
||||||
|
|
||||||
method delete*(self: Module) =
|
method delete*(self: Module) =
|
||||||
self.view.delete
|
self.view.delete
|
||||||
|
|
||||||
|
@ -40,5 +38,8 @@ method viewDidLoad*(self: Module) =
|
||||||
self.moduleLoaded = true
|
self.moduleLoaded = true
|
||||||
self.delegate.languageModuleDidLoad()
|
self.delegate.languageModuleDidLoad()
|
||||||
|
|
||||||
|
method getModuleAsVariant*(self: Module): QVariant =
|
||||||
|
return self.viewVariant
|
||||||
|
|
||||||
method changeLanguage*(self: Module, locale: string) =
|
method changeLanguage*(self: Module, locale: string) =
|
||||||
self.controller.changeLanguage(locale)
|
self.controller.changeLanguage(locale)
|
||||||
|
|
|
@ -7,7 +7,7 @@ import ../../../../app_service/service/accounts/service as accounts_service
|
||||||
import ../../../../app_service/service/settings/service_interface as settings_service
|
import ../../../../app_service/service/settings/service_interface as settings_service
|
||||||
import ../../../../app_service/service/contacts/service as contacts_service
|
import ../../../../app_service/service/contacts/service as contacts_service
|
||||||
import ../../../../app_service/service/about/service as about_service
|
import ../../../../app_service/service/about/service as about_service
|
||||||
import ../../../../app_service/service/language/service as language_service
|
import ../../../../app_service/service/language/service_interface as language_service
|
||||||
import ../../../../app_service/service/mnemonic/service as mnemonic_service
|
import ../../../../app_service/service/mnemonic/service as mnemonic_service
|
||||||
import ../../../../app_service/service/privacy/service as privacy_service
|
import ../../../../app_service/service/privacy/service as privacy_service
|
||||||
import ../../../../app_service/service/node_configuration/service_interface as node_configuration_service
|
import ../../../../app_service/service/node_configuration/service_interface as node_configuration_service
|
||||||
|
@ -162,6 +162,9 @@ method contactsModuleDidLoad*[T](self: Module[T]) =
|
||||||
method languageModuleDidLoad*[T](self: Module[T]) =
|
method languageModuleDidLoad*[T](self: Module[T]) =
|
||||||
self.checkIfModuleDidLoad()
|
self.checkIfModuleDidLoad()
|
||||||
|
|
||||||
|
method getLanguageModule*[T](self: Module[T]): QVariant =
|
||||||
|
self.languageModule.getModuleAsVariant()
|
||||||
|
|
||||||
method mnemonicModuleDidLoad*[T](self: Module[T]) =
|
method mnemonicModuleDidLoad*[T](self: Module[T]) =
|
||||||
self.checkIfModuleDidLoad()
|
self.checkIfModuleDidLoad()
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,11 @@ QtObject:
|
||||||
proc load*(self: View) =
|
proc load*(self: View) =
|
||||||
self.delegate.viewDidLoad()
|
self.delegate.viewDidLoad()
|
||||||
|
|
||||||
|
proc getLanguageModule(self: View): QVariant {.slot.} =
|
||||||
|
return self.delegate.getLanguageModule()
|
||||||
|
QtProperty[QVariant] languageModule:
|
||||||
|
read = getLanguageModule
|
||||||
|
|
||||||
proc getAdvancedModule(self: View): QVariant {.slot.} =
|
proc getAdvancedModule(self: View): QVariant {.slot.} =
|
||||||
return self.delegate.getAdvancedModule()
|
return self.delegate.getAdvancedModule()
|
||||||
QtProperty[QVariant] advancedModule:
|
QtProperty[QVariant] advancedModule:
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import NimQml
|
import NimQml
|
||||||
import json, json_serialization, sequtils, chronicles, os, strformat
|
import json, json_serialization, sequtils, chronicles, os, strformat
|
||||||
import ./service_interface, ./dto
|
import ./service_interface
|
||||||
import ../../../app/global/global_singleton
|
import ../../../app/global/global_singleton
|
||||||
|
|
||||||
export service_interface
|
export service_interface
|
||||||
|
@ -10,14 +10,15 @@ logScope:
|
||||||
|
|
||||||
type
|
type
|
||||||
Service* = ref object of ServiceInterface
|
Service* = ref object of ServiceInterface
|
||||||
i18nPath*: string
|
i18nPath: string
|
||||||
currentLanguageCode*: string
|
shouldRetranslate: bool
|
||||||
|
|
||||||
method delete*(self: Service) =
|
method delete*(self: Service) =
|
||||||
discard
|
discard
|
||||||
|
|
||||||
proc newService*(): Service =
|
proc newService*(): Service =
|
||||||
result = Service()
|
result = Service()
|
||||||
|
result.shouldRetranslate = not defined(linux)
|
||||||
|
|
||||||
method init*(self: Service) =
|
method init*(self: Service) =
|
||||||
try:
|
try:
|
||||||
|
@ -31,15 +32,17 @@ method init*(self: Service) =
|
||||||
elif (defined(linux)):
|
elif (defined(linux)):
|
||||||
self.i18nPath = joinPath(getAppDir(), "../i18n")
|
self.i18nPath = joinPath(getAppDir(), "../i18n")
|
||||||
|
|
||||||
|
let locale = singletonInstance.localAppSettings.getLocale()
|
||||||
|
singletonInstance.engine.setTranslationPackage(joinPath(self.i18nPath, fmt"qml_{locale}.qm"), self.shouldRetranslate)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
let errDesription = e.msg
|
let errDesription = e.msg
|
||||||
error "error: ", errDesription
|
error "error: ", errDesription
|
||||||
return
|
return
|
||||||
|
|
||||||
method setLanguage*(self: Service, locale: string) =
|
method setLanguage*(self: Service, locale: string) =
|
||||||
if (locale == self.currentLanguageCode):
|
if (locale == singletonInstance.localAppSettings.getLocale()):
|
||||||
return
|
return
|
||||||
self.currentLanguageCode = locale
|
|
||||||
let shouldRetranslate = not defined(linux)
|
singletonInstance.localAppSettings.setLocale(locale)
|
||||||
singletonInstance.engine.setTranslationPackage(
|
singletonInstance.engine.setTranslationPackage(joinPath(self.i18nPath, fmt"qml_{locale}.qm"), self.shouldRetranslate)
|
||||||
joinPath(self.i18nPath, fmt"qml_{locale}.qm"), shouldRetranslate)
|
|
|
@ -1,7 +1,3 @@
|
||||||
import dto
|
|
||||||
|
|
||||||
export dto
|
|
||||||
|
|
||||||
type
|
type
|
||||||
ServiceInterface* {.pure inheritable.} = ref object of RootObj
|
ServiceInterface* {.pure inheritable.} = ref object of RootObj
|
||||||
## Abstract class for this service access.
|
## Abstract class for this service access.
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import json, sequtils
|
import json
|
||||||
|
|
||||||
include ../../common/json_utils
|
include ../../common/json_utils
|
||||||
|
|
||||||
|
|
|
@ -78,7 +78,7 @@ StatusAppTwoPanelLayout {
|
||||||
}
|
}
|
||||||
|
|
||||||
LanguageView {
|
LanguageView {
|
||||||
store: profileView.store
|
languageStore: profileView.store.languageStore
|
||||||
profileContentWidth: _internal.profileContentWidth
|
profileContentWidth: _internal.profileContentWidth
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ ModalPopup {
|
||||||
//% "Language"
|
//% "Language"
|
||||||
title: qsTrId("Language")
|
title: qsTrId("Language")
|
||||||
|
|
||||||
property var store
|
property var languageStore
|
||||||
|
|
||||||
onClosed: {
|
onClosed: {
|
||||||
destroy()
|
destroy()
|
||||||
|
@ -37,7 +37,7 @@ ModalPopup {
|
||||||
confirmButtonLabel: qsTr("Close the app now")
|
confirmButtonLabel: qsTr("Close the app now")
|
||||||
cancelButtonLabel: qsTr("I'll do that later")
|
cancelButtonLabel: qsTr("I'll do that later")
|
||||||
onConfirmButtonClicked: {
|
onConfirmButtonClicked: {
|
||||||
root.store.changeLocale(newLocale)
|
root.languageStore.changeLocale(newLocale)
|
||||||
Qt.quit();
|
Qt.quit();
|
||||||
}
|
}
|
||||||
onCancelButtonClicked: {
|
onCancelButtonClicked: {
|
||||||
|
@ -81,7 +81,7 @@ ModalPopup {
|
||||||
languageChangeConfirmationDialog.item.newLocale = modelData.locale
|
languageChangeConfirmationDialog.item.newLocale = modelData.locale
|
||||||
languageChangeConfirmationDialog.item.open()
|
languageChangeConfirmationDialog.item.open()
|
||||||
} else {
|
} else {
|
||||||
root.store.changeLocale(modelData.locale)
|
root.languageStore.changeLocale(modelData.locale)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
import QtQuick 2.13
|
||||||
|
import utils 1.0
|
||||||
|
|
||||||
|
QtObject {
|
||||||
|
id: root
|
||||||
|
|
||||||
|
property var languageModule
|
||||||
|
|
||||||
|
function changeLocale(locale) {
|
||||||
|
root.languageModule.changeLocale(locale)
|
||||||
|
}
|
||||||
|
}
|
|
@ -7,7 +7,6 @@ QtObject {
|
||||||
property var profile: profileModule.model
|
property var profile: profileModule.model
|
||||||
property var contactsModuleInst: contactsModule
|
property var contactsModuleInst: contactsModule
|
||||||
property var aboutModuleInst: aboutModule
|
property var aboutModuleInst: aboutModule
|
||||||
property var languageModuleInst: languageModule
|
|
||||||
property var mnemonicModuleInst: mnemonicModule
|
property var mnemonicModuleInst: mnemonicModule
|
||||||
|
|
||||||
property var profileModuleInst: profileSectionModule
|
property var profileModuleInst: profileSectionModule
|
||||||
|
@ -28,6 +27,10 @@ QtObject {
|
||||||
notificationsModule: profileModuleInst.notificationsModule
|
notificationsModule: profileModuleInst.notificationsModule
|
||||||
}
|
}
|
||||||
|
|
||||||
|
property LanguageStore languageStore: LanguageStore {
|
||||||
|
languageModule: profileModuleInst.languageModule
|
||||||
|
}
|
||||||
|
|
||||||
// Not Refactored Yet
|
// Not Refactored Yet
|
||||||
// property var chatsModelInst: chatsModel
|
// property var chatsModelInst: chatsModel
|
||||||
// Not Refactored Yet
|
// Not Refactored Yet
|
||||||
|
@ -307,11 +310,6 @@ QtObject {
|
||||||
// return utilsModelInst.getSNTBalance()
|
// return utilsModelInst.getSNTBalance()
|
||||||
}
|
}
|
||||||
|
|
||||||
function changeLocale(l) {
|
|
||||||
localAppSettings.locale = l
|
|
||||||
languageModuleInst.changeLocale(l)
|
|
||||||
}
|
|
||||||
|
|
||||||
function getNetworkName() {
|
function getNetworkName() {
|
||||||
// Not Refactored Yet
|
// Not Refactored Yet
|
||||||
// return utilsModelInst.getNetworkName()
|
// return utilsModelInst.getNetworkName()
|
||||||
|
|
|
@ -16,10 +16,10 @@ Item {
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
clip: true
|
clip: true
|
||||||
|
|
||||||
property var store
|
property var languageStore
|
||||||
property int profileContentWidth
|
property int profileContentWidth
|
||||||
property Component languagePopup: LanguageModal {
|
property Component languagePopup: LanguageModal {
|
||||||
store: languageContainer.store
|
languageStore: languageContainer.languageStore
|
||||||
}
|
}
|
||||||
|
|
||||||
Item {
|
Item {
|
||||||
|
|
Loading…
Reference in New Issue