refactor(@desktop/settings-language): language settings added

This commit is contained in:
Sale Djenic 2021-12-29 10:53:56 +01:00
parent 46869afa5f
commit b4df87b7a6
18 changed files with 62 additions and 68 deletions

View File

@ -1,4 +1,4 @@
import NimQml, os, strformat
import NimQml
import ../../app_service/common/utils
@ -39,28 +39,6 @@ import ../global/global_singleton
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
AppController* = ref object of RootObj
statusFoundation: StatusFoundation
@ -230,6 +208,7 @@ proc delete*(self: AppController) =
self.startupModule.delete
self.mainModule.delete
self.ethService.delete
self.languageService.delete
self.localAppSettingsVariant.delete
self.localAccountSettingsVariant.delete
@ -261,9 +240,8 @@ proc startupDidLoad*(self: AppController) =
singletonInstance.engine.setRootContextProperty("localAccountSettings", self.localAccountSettingsVariant)
singletonInstance.engine.load(newQUrl("qrc:///main.qml"))
# We need to set a language once qml is loaded
let locale = singletonInstance.localAppSettings.getLocale()
setLanguage(locale)
# We need to init a language service once qml is loaded
self.languageService.init()
proc mainDidLoad*(self: AppController) =
self.statusFoundation.onLoggedIn()
@ -289,7 +267,6 @@ proc load(self: AppController) =
self.providerService.init()
self.walletAccountService.init()
self.transactionService.init()
self.languageService.init()
self.stickersService.init()
self.networkService.init()
self.activityCenterService.init()

View File

@ -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/contacts/service as contacts_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/privacy/service as privacy_service
import ../../../app_service/service/stickers/service as stickers_service

View File

@ -29,6 +29,9 @@ method contactsModuleDidLoad*(self: AccessInterface) {.base.} =
method languageModuleDidLoad*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")
method getLanguageModule*(self: AccessInterface): QVariant {.base.} =
raise newException(ValueError, "No implementation available")
method mnemonicModuleDidLoad*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available")

View File

@ -1,8 +1,6 @@
import ./controller_interface
import io_interface
import ../../../../../app_service/service/language/service as language_service
# import ./item as item
import ../../../../../app_service/service/language/service_interface as language_service
export controller_interface

View File

@ -1,5 +1,3 @@
import ../../../../../app_service/service/language/service as language_service
type
AccessInterface* {.pure inheritable.} = ref object of RootObj
## Abstract class for any input/interaction with this module.
@ -12,8 +10,3 @@ method init*(self: AccessInterface) {.base.} =
method changeLanguage*(self: AccessInterface, locale: string) {.base.} =
raise newException(ValueError, "No implementation available")
type
## Abstract class (concept) which must be implemented by object/s used in this
## module.
DelegateInterface* = concept c

View File

@ -1,3 +1,5 @@
import NimQml
type
AccessInterface* {.pure inheritable.} = ref object of RootObj
## Abstract class for any input/interaction with this module.
@ -11,6 +13,9 @@ method load*(self: AccessInterface) {.base.} =
method isLoaded*(self: AccessInterface): bool {.base.} =
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.} =
raise newException(ValueError, "No implementation available")

View File

@ -4,7 +4,7 @@ import ./io_interface, ./view, ./controller
import ../io_interface as delegate_interface
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
@ -24,8 +24,6 @@ proc newModule*(delegate: delegate_interface.AccessInterface, languageService: l
result.controller = controller.newController(result, languageService)
result.moduleLoaded = false
singletonInstance.engine.setRootContextProperty("languageModule", result.viewVariant)
method delete*(self: Module) =
self.view.delete
@ -40,5 +38,8 @@ method viewDidLoad*(self: Module) =
self.moduleLoaded = true
self.delegate.languageModuleDidLoad()
method getModuleAsVariant*(self: Module): QVariant =
return self.viewVariant
method changeLanguage*(self: Module, locale: string) =
self.controller.changeLanguage(locale)

View File

@ -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/contacts/service as contacts_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/privacy/service as privacy_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]) =
self.checkIfModuleDidLoad()
method getLanguageModule*[T](self: Module[T]): QVariant =
self.languageModule.getModuleAsVariant()
method mnemonicModuleDidLoad*[T](self: Module[T]) =
self.checkIfModuleDidLoad()

View File

@ -21,6 +21,11 @@ QtObject:
proc load*(self: View) =
self.delegate.viewDidLoad()
proc getLanguageModule(self: View): QVariant {.slot.} =
return self.delegate.getLanguageModule()
QtProperty[QVariant] languageModule:
read = getLanguageModule
proc getAdvancedModule(self: View): QVariant {.slot.} =
return self.delegate.getAdvancedModule()
QtProperty[QVariant] advancedModule:

View File

@ -1,6 +1,6 @@
import NimQml
import json, json_serialization, sequtils, chronicles, os, strformat
import ./service_interface, ./dto
import ./service_interface
import ../../../app/global/global_singleton
export service_interface
@ -10,14 +10,15 @@ logScope:
type
Service* = ref object of ServiceInterface
i18nPath*: string
currentLanguageCode*: string
i18nPath: string
shouldRetranslate: bool
method delete*(self: Service) =
discard
proc newService*(): Service =
result = Service()
result.shouldRetranslate = not defined(linux)
method init*(self: Service) =
try:
@ -31,15 +32,17 @@ method init*(self: Service) =
elif (defined(linux)):
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:
let errDesription = e.msg
error "error: ", errDesription
return
method setLanguage*(self: Service, locale: string) =
if (locale == self.currentLanguageCode):
if (locale == singletonInstance.localAppSettings.getLocale()):
return
self.currentLanguageCode = locale
let shouldRetranslate = not defined(linux)
singletonInstance.engine.setTranslationPackage(
joinPath(self.i18nPath, fmt"qml_{locale}.qm"), shouldRetranslate)
singletonInstance.localAppSettings.setLocale(locale)
singletonInstance.engine.setTranslationPackage(joinPath(self.i18nPath, fmt"qml_{locale}.qm"), self.shouldRetranslate)

View File

@ -1,7 +1,3 @@
import dto
export dto
type
ServiceInterface* {.pure inheritable.} = ref object of RootObj
## Abstract class for this service access.

View File

@ -1,4 +1,4 @@
import json, sequtils
import json
include ../../common/json_utils

View File

@ -78,7 +78,7 @@ StatusAppTwoPanelLayout {
}
LanguageView {
store: profileView.store
languageStore: profileView.store.languageStore
profileContentWidth: _internal.profileContentWidth
}

View File

@ -13,7 +13,7 @@ ModalPopup {
//% "Language"
title: qsTrId("Language")
property var store
property var languageStore
onClosed: {
destroy()
@ -37,7 +37,7 @@ ModalPopup {
confirmButtonLabel: qsTr("Close the app now")
cancelButtonLabel: qsTr("I'll do that later")
onConfirmButtonClicked: {
root.store.changeLocale(newLocale)
root.languageStore.changeLocale(newLocale)
Qt.quit();
}
onCancelButtonClicked: {
@ -81,7 +81,7 @@ ModalPopup {
languageChangeConfirmationDialog.item.newLocale = modelData.locale
languageChangeConfirmationDialog.item.open()
} else {
root.store.changeLocale(modelData.locale)
root.languageStore.changeLocale(modelData.locale)
}
}
}

View File

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

View File

@ -7,7 +7,6 @@ QtObject {
property var profile: profileModule.model
property var contactsModuleInst: contactsModule
property var aboutModuleInst: aboutModule
property var languageModuleInst: languageModule
property var mnemonicModuleInst: mnemonicModule
property var profileModuleInst: profileSectionModule
@ -28,6 +27,10 @@ QtObject {
notificationsModule: profileModuleInst.notificationsModule
}
property LanguageStore languageStore: LanguageStore {
languageModule: profileModuleInst.languageModule
}
// Not Refactored Yet
// property var chatsModelInst: chatsModel
// Not Refactored Yet
@ -307,11 +310,6 @@ QtObject {
// return utilsModelInst.getSNTBalance()
}
function changeLocale(l) {
localAppSettings.locale = l
languageModuleInst.changeLocale(l)
}
function getNetworkName() {
// Not Refactored Yet
// return utilsModelInst.getNetworkName()

View File

@ -16,10 +16,10 @@ Item {
Layout.fillWidth: true
clip: true
property var store
property var languageStore
property int profileContentWidth
property Component languagePopup: LanguageModal {
store: languageContainer.store
languageStore: languageContainer.languageStore
}
Item {