chore(settings): fix naming: locale->language
This commit is contained in:
parent
0dfdcc727a
commit
5b51a7ce81
|
@ -3,7 +3,7 @@ import NimQml, os
|
|||
import ../../constants
|
||||
|
||||
# Local App Settings keys:
|
||||
const LAS_KEY_LOCALE* = "global/locale"
|
||||
const LAS_KEY_LANGUAGE* = "global/language"
|
||||
const DEFAULT_LOCALE = "en"
|
||||
const LAS_KEY_THEME* = "global/theme"
|
||||
const DEFAULT_THEME = 2 #system theme, from qml
|
||||
|
@ -30,17 +30,17 @@ QtObject:
|
|||
result.settings = newQSettings(filePath, QSettingsFormat.IniFormat)
|
||||
|
||||
|
||||
proc localeChanged*(self: LocalAppSettings) {.signal.}
|
||||
proc getLocale*(self: LocalAppSettings): string {.slot.} =
|
||||
self.settings.value(LAS_KEY_LOCALE, newQVariant(DEFAULT_LOCALE)).stringVal
|
||||
proc setLocale*(self: LocalAppSettings, value: string) {.slot.} =
|
||||
self.settings.setValue(LAS_KEY_LOCALE, newQVariant(value))
|
||||
self.localeChanged()
|
||||
proc languageChanged*(self: LocalAppSettings) {.signal.}
|
||||
proc getLanguage*(self: LocalAppSettings): string {.slot.} =
|
||||
self.settings.value(LAS_KEY_LANGUAGE, newQVariant(DEFAULT_LOCALE)).stringVal
|
||||
proc setLanguage*(self: LocalAppSettings, value: string) {.slot.} =
|
||||
self.settings.setValue(LAS_KEY_LANGUAGE, newQVariant(value))
|
||||
self.languageChanged()
|
||||
|
||||
QtProperty[string] locale:
|
||||
read = getLocale
|
||||
write = setLocale
|
||||
notify = localeChanged
|
||||
QtProperty[string] language:
|
||||
read = getLanguage
|
||||
write = setLanguage
|
||||
notify = languageChanged
|
||||
|
||||
|
||||
proc themeChanged*(self: LocalAppSettings) {.signal.}
|
||||
|
@ -89,7 +89,7 @@ QtObject:
|
|||
self.settings.remove(key)
|
||||
|
||||
case key:
|
||||
of LAS_KEY_LOCALE: self.localeChanged()
|
||||
of LAS_KEY_LANGUAGE: self.languageChanged()
|
||||
of LAS_KEY_THEME: self.themeChanged()
|
||||
of LAS_KEY_GEOMETRY: self.geometryChanged()
|
||||
of LAS_KEY_VISIBILITY: self.visibilityChanged()
|
||||
of LAS_KEY_VISIBILITY: self.visibilityChanged()
|
||||
|
|
|
@ -9,9 +9,9 @@ type
|
|||
languageService: language_service.Service
|
||||
|
||||
proc init*(self: Controller) =
|
||||
self.events.on(SIGNAL_LOCALE_UPDATE) do(e: Args):
|
||||
let args = LocaleUpdatedArgs(e)
|
||||
self.delegate.onCurrentLocaleChanged(args.locale)
|
||||
self.events.on(SIGNAL_LANGUAGE_UPDATE) do(e: Args):
|
||||
let args = LanguageUpdatedArgs(e)
|
||||
self.delegate.onCurrentLanguageChanged(args.language)
|
||||
|
||||
proc newController*(delegate: io_interface.AccessInterface,
|
||||
events: EventEmitter, languageService: language_service.Service):
|
||||
|
@ -24,11 +24,11 @@ proc newController*(delegate: io_interface.AccessInterface,
|
|||
proc delete*(self: Controller) =
|
||||
discard
|
||||
|
||||
proc changeLocale*(self: Controller, locale: string) =
|
||||
self.languageService.setLanguage(locale)
|
||||
proc changeLanguage*(self: Controller, language: string) =
|
||||
self.languageService.setLanguage(language)
|
||||
|
||||
proc getLocales*(self: Controller): seq[string] =
|
||||
self.languageService.locales()
|
||||
proc getLanguages*(self: Controller): seq[string] =
|
||||
self.languageService.languages()
|
||||
|
||||
proc getCurrentLocale*(self: Controller): string =
|
||||
language_service.currentLocale()
|
||||
proc getCurrentLanguage*(self: Controller): string =
|
||||
language_service.currentLanguage()
|
||||
|
|
|
@ -16,7 +16,7 @@ method isLoaded*(self: AccessInterface): bool {.base.} =
|
|||
method getModuleAsVariant*(self: AccessInterface): QVariant {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
method changeLocale*(self: AccessInterface, locale: string) {.base.} =
|
||||
method changeLanguage*(self: AccessInterface, language: string) {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
method setIsDDMMYYDateFormat*(self: AccessInterface, isDDMMYYDateFormat: bool) {.slot.} =
|
||||
|
@ -25,7 +25,7 @@ method setIsDDMMYYDateFormat*(self: AccessInterface, isDDMMYYDateFormat: bool) {
|
|||
method setIs24hTimeFormat*(self: AccessInterface, is24hTimeFormat: bool) {.slot.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
method onCurrentLocaleChanged*(self: AccessInterface, locale: string) {.base.} =
|
||||
method onCurrentLanguageChanged*(self: AccessInterface, language: string) {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ proc newModule*(delegate: delegate_interface.AccessInterface,
|
|||
proc populateLanguageModel(self: Module) =
|
||||
var items: seq[Item]
|
||||
|
||||
for locale in self.controller.getLocales():
|
||||
for locale in self.controller.getLanguages():
|
||||
if localeDescriptionTable.contains(locale):
|
||||
let localeDescr = localeDescriptionTable[locale]
|
||||
items.add(initItem(
|
||||
|
@ -55,7 +55,7 @@ method isLoaded*(self: Module): bool =
|
|||
|
||||
method viewDidLoad*(self: Module) =
|
||||
self.populateLanguageModel()
|
||||
self.view.setLocale(self.controller.getCurrentLocale())
|
||||
self.view.setLanguage(self.controller.getCurrentLanguage())
|
||||
|
||||
self.moduleLoaded = true
|
||||
self.delegate.languageModuleDidLoad()
|
||||
|
@ -63,11 +63,11 @@ method viewDidLoad*(self: Module) =
|
|||
method getModuleAsVariant*(self: Module): QVariant =
|
||||
return self.viewVariant
|
||||
|
||||
method changeLocale*(self: Module, locale: string) =
|
||||
self.controller.changeLocale(locale)
|
||||
method changeLanguage*(self: Module, language: string) =
|
||||
self.controller.changeLanguage(language)
|
||||
|
||||
method onCurrentLocaleChanged*(self: Module, locale: string) =
|
||||
self.view.setLocale(locale)
|
||||
method onCurrentLanguageChanged*(self: Module, language: string) =
|
||||
self.view.setLanguage(language)
|
||||
|
||||
method setIsDDMMYYDateFormat*(self: Module, isDDMMYYDateFormat: bool) =
|
||||
if(isDDMMYYDateFormat != singletonInstance.localAccountSensitiveSettings.getIsDDMMYYDateFormat()):
|
||||
|
|
|
@ -8,7 +8,7 @@ QtObject:
|
|||
delegate: io_interface.AccessInterface
|
||||
model: Model
|
||||
modelVariant: QVariant
|
||||
currentLocale: string
|
||||
currentLanguage: string
|
||||
|
||||
proc delete*(self: View) =
|
||||
self.QObject.delete
|
||||
|
@ -40,19 +40,19 @@ QtObject:
|
|||
proc setIs24hTimeFormat*(self: View, is24hTimeFormat: bool) {.slot.} =
|
||||
self.delegate.setIs24hTimeFormat(is24hTimeFormat)
|
||||
|
||||
proc changeLocale*(self: View, locale: string) {.slot.} =
|
||||
self.delegate.changeLocale(locale)
|
||||
proc changeLanguage*(self: View, language: string) {.slot.} =
|
||||
self.delegate.changeLanguage(language)
|
||||
|
||||
proc getLocale*(self: View): string {.slot.} =
|
||||
self.currentLocale
|
||||
proc getLanguage*(self: View): string {.slot.} =
|
||||
self.currentLanguage
|
||||
|
||||
proc localeChanged*(self: View) {.signal.}
|
||||
proc languageChanged*(self: View) {.signal.}
|
||||
|
||||
QtProperty[string] currentLocale:
|
||||
read = getLocale
|
||||
notify = localeChanged
|
||||
QtProperty[string] currentLanguage:
|
||||
read = getLanguage
|
||||
notify = languageChanged
|
||||
|
||||
proc setLocale*(self: View, locale: string) =
|
||||
if locale != self.currentLocale:
|
||||
self.currentLocale = locale
|
||||
self.localeChanged()
|
||||
proc setLanguage*(self: View, language: string) =
|
||||
if language != self.currentLanguage:
|
||||
self.currentLanguage = language
|
||||
self.languageChanged()
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import NimQml
|
||||
import json, json_serialization, sequtils, chronicles, os, strformat, re
|
||||
import json_serialization, chronicles, os, strformat, re
|
||||
import ../../../app/global/global_singleton
|
||||
import ../../../app/core/eventemitter
|
||||
import ../../../app/core/signals/types
|
||||
|
@ -7,18 +7,18 @@ import ../../../app/core/signals/types
|
|||
logScope:
|
||||
topics = "language-service"
|
||||
|
||||
const SIGNAL_LOCALE_UPDATE* = "localeUpdated"
|
||||
const SIGNAL_LANGUAGE_UPDATE* = "languageUpdated"
|
||||
|
||||
type
|
||||
LocaleUpdatedArgs* = ref object of Args
|
||||
locale*: string
|
||||
LanguageUpdatedArgs* = ref object of Args
|
||||
language*: string
|
||||
|
||||
type
|
||||
Service* = ref object of RootObj
|
||||
events: EventEmitter
|
||||
i18nPath: string
|
||||
shouldRetranslate: bool
|
||||
locales: seq[string]
|
||||
languages: seq[string] # list of locale names for translation purposes
|
||||
|
||||
proc delete*(self: Service) =
|
||||
discard
|
||||
|
@ -28,17 +28,17 @@ proc newService*(events: EventEmitter): Service =
|
|||
result.events = events
|
||||
result.shouldRetranslate = not defined(linux)
|
||||
|
||||
proc obtainLocales(dir: string): seq[string] =
|
||||
proc obtainLanguages(dir: string): seq[string] =
|
||||
let localeRe = re".*qml_(.*).qm"
|
||||
for file in walkFiles dir & "/*.qm":
|
||||
if file =~ localeRe:
|
||||
result.add(matches[0])
|
||||
|
||||
proc currentLocale*(): string =
|
||||
singletonInstance.localAppSettings.getLocale()
|
||||
proc currentLanguage*(): string =
|
||||
singletonInstance.localAppSettings.getLanguage()
|
||||
|
||||
proc locales*(self: Service): seq[string] =
|
||||
self.locales
|
||||
proc languages*(self: Service): seq[string] =
|
||||
self.languages
|
||||
|
||||
proc init*(self: Service) =
|
||||
try:
|
||||
|
@ -52,21 +52,21 @@ proc init*(self: Service) =
|
|||
elif (defined(linux)):
|
||||
self.i18nPath = joinPath(getAppDir(), "../i18n")
|
||||
|
||||
self.locales = obtainLocales(self.i18nPath)
|
||||
self.languages = obtainLanguages(self.i18nPath)
|
||||
|
||||
let locale = currentLocale()
|
||||
singletonInstance.engine.setTranslationPackage(joinPath(self.i18nPath, fmt"qml_{locale}.qm"), self.shouldRetranslate)
|
||||
let language = currentLanguage()
|
||||
singletonInstance.engine.setTranslationPackage(joinPath(self.i18nPath, fmt"qml_{language}.qm"), self.shouldRetranslate)
|
||||
|
||||
except Exception as e:
|
||||
let errDesription = e.msg
|
||||
error "error: ", errDesription
|
||||
return
|
||||
|
||||
proc setLanguage*(self: Service, locale: string) =
|
||||
if (locale == singletonInstance.localAppSettings.getLocale()):
|
||||
proc setLanguage*(self: Service, language: string) =
|
||||
if (language == singletonInstance.localAppSettings.getLanguage()):
|
||||
return
|
||||
|
||||
singletonInstance.localAppSettings.setLocale(locale)
|
||||
singletonInstance.engine.setTranslationPackage(joinPath(self.i18nPath, fmt"qml_{locale}.qm"), self.shouldRetranslate)
|
||||
singletonInstance.localAppSettings.setLanguage(language)
|
||||
singletonInstance.engine.setTranslationPackage(joinPath(self.i18nPath, fmt"qml_{language}.qm"), self.shouldRetranslate)
|
||||
|
||||
self.events.emit(SIGNAL_LOCALE_UPDATE, LocaleUpdatedArgs(locale: locale))
|
||||
self.events.emit(SIGNAL_LANGUAGE_UPDATE, LanguageUpdatedArgs(language: language))
|
||||
|
|
|
@ -6,7 +6,7 @@ import StatusQ.Core.Utils 0.1 as StatusQUtils
|
|||
QtObject {
|
||||
id: root
|
||||
|
||||
property string locale: localAppSettings.locale
|
||||
property string locale: localAppSettings.language
|
||||
|
||||
property var contactsStore
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ QtObject {
|
|||
|
||||
property var communitiesModuleInst: communitiesModule
|
||||
property var curatedCommunitiesModel: root.communitiesModuleInst.curatedCommunities
|
||||
property var locale: localAppSettings.locale
|
||||
property var locale: localAppSettings.language
|
||||
property var advancedModule: profileSectionModule.advancedModule
|
||||
property bool isCommunityHistoryArchiveSupportEnabled: advancedModule? advancedModule.isCommunityHistoryArchiveSupportEnabled : false
|
||||
|
||||
|
|
|
@ -7,12 +7,12 @@ QtObject {
|
|||
property var languageModule
|
||||
|
||||
readonly property var languageModel: languageModule ? languageModule.model : null
|
||||
readonly property string currentLocale: languageModule ? languageModule.currentLocale : null
|
||||
readonly property string currentLanguage: languageModule ? languageModule.currentLanguage : null
|
||||
readonly property bool isDDMMYYDateFormat: localAccountSensitiveSettings.isDDMMYYDateFormat
|
||||
readonly property bool is24hTimeFormat: localAccountSensitiveSettings.is24hTimeFormat
|
||||
|
||||
function changeLocale(locale) {
|
||||
root.languageModule.changeLocale(locale)
|
||||
function changeLanguage(locale) {
|
||||
root.languageModule.changeLanguage(locale)
|
||||
}
|
||||
|
||||
function setIsDDMMYYDateFormat(isDDMMYYDateFormat) {
|
||||
|
|
|
@ -108,8 +108,8 @@ SettingsContentBase {
|
|||
id: languagePause
|
||||
interval: 100
|
||||
onTriggered: {
|
||||
// changeLocale function operation blocks a little bit the UI so getting around it with a small pause (timer) in order to get the desired visual behavior
|
||||
root.languageStore.changeLocale(languagePicker.newKey)
|
||||
// changeLanguage function operation blocks a little bit the UI so getting around it with a small pause (timer) in order to get the desired visual behavior
|
||||
root.languageStore.changeLanguage(languagePicker.newKey)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -137,7 +137,7 @@ SettingsContentBase {
|
|||
},
|
||||
ExpressionRole {
|
||||
name: "selected"
|
||||
expression: model.locale == root.languageStore.currentLocale
|
||||
expression: model.locale == root.languageStore.currentLanguage
|
||||
},
|
||||
ExpressionRole {
|
||||
name: "imageSource"
|
||||
|
@ -154,7 +154,7 @@ SettingsContentBase {
|
|||
maxPickerHeight: 350
|
||||
|
||||
onItemPickerChanged: {
|
||||
if(selected && root.languageStore.currentLocale !== key) {
|
||||
if(selected && root.languageStore.currentLanguage !== key) {
|
||||
// TEMPORARY: It should be removed as it is only used in Linux OS but it must be investigated how to change language in execution time, as well, in Linux (will be addressed in another task)
|
||||
if (Qt.platform.os === Constants.linux) {
|
||||
linuxConfirmationDialog.active = true
|
||||
|
@ -253,7 +253,7 @@ SettingsContentBase {
|
|||
confirmationText: qsTr("Display language has been changed. You must restart the application for changes to take effect.")
|
||||
confirmButtonLabel: qsTr("Close the app now")
|
||||
onConfirmButtonClicked: {
|
||||
root.languageStore.changeLocale(newLocale)
|
||||
root.languageStore.changeLanguage(newLocale)
|
||||
loader.active = false
|
||||
Qt.quit()
|
||||
}
|
||||
|
|
|
@ -58,7 +58,7 @@ Rectangle {
|
|||
id: walletAmountValue
|
||||
color: Style.current.textColor
|
||||
text: {
|
||||
Utils.toLocaleString(parseFloat(RootStore.totalCurrencyBalance).toFixed(2), localAppSettings.locale, {"currency": true}) + " " + RootStore.currentCurrency.toUpperCase()
|
||||
Utils.toLocaleString(parseFloat(RootStore.totalCurrencyBalance).toFixed(2), localAppSettings.language, {"currency": true}) + " " + RootStore.currentCurrency.toUpperCase()
|
||||
}
|
||||
selectByMouse: true
|
||||
cursorVisible: true
|
||||
|
@ -138,4 +138,4 @@ Rectangle {
|
|||
onClicked: showSavedAddresses(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ import "../Profile/stores"
|
|||
QtObject {
|
||||
id: root
|
||||
|
||||
property string locale: localAppSettings.locale
|
||||
property string locale: localAppSettings.language
|
||||
|
||||
property var mainModuleInst: mainModule
|
||||
property var aboutModuleInst: aboutModule
|
||||
|
|
Loading…
Reference in New Issue