feat(settigns): use nim provided language model

closes: #6416
This commit is contained in:
Patryk Osmaczko 2022-07-22 13:57:48 +02:00 committed by osmaczko
parent f3dd063e92
commit 0dfdcc727a
2 changed files with 41 additions and 46 deletions

View File

@ -5,50 +5,11 @@ QtObject {
id: root
property var languageModule
property string locale: localAppSettings.locale
property bool isDDMMYYDateFormat: localAccountSensitiveSettings.isDDMMYYDateFormat
property bool is24hTimeFormat: localAccountSensitiveSettings.is24hTimeFormat
// TODO: That definition should be moved to backend.
property ListModel languageModel: ListModel {
ListElement {key: "en"; shortName: "English"; name: "English"; category: ""; imageSource: "../../assets/twemoji/svg/1f1ec-1f1e7.svg"; selected: false}
ListElement {key: "zh"; shortName: "普通话"; name: "Chinese (Mainland China)"; imageSource: "../../assets/twemoji/svg/1f1e8-1f1f3.svg"; category: ""; selected: false}
ListElement {key: "ko"; shortName: "한국어"; name: "Korean"; category: ""; imageSource: "../../assets/twemoji/svg/1f1f0-1f1f7.svg"; selected: false}
ListElement {key: "pt_BR"; shortName: "Português"; name: "Portuguese (Brazil)"; category: ""; imageSource: "../../assets/twemoji/svg/1f1e7-1f1f7.svg"; selected: false}
ListElement {key: "ru"; shortName: "Русский Язык"; name: "Russian"; category: ""; imageSource: "../../assets/twemoji/svg/1f1f7-1f1fa.svg"; selected: false}
ListElement {key: "ar"; shortName: "اَلْعَرَبِيَّةُ"; name: "Arabic"; category: qsTr("Beta Languages"); imageSource: "../../assets/twemoji/svg/1f1f8-1f1e6.svg"; selected: false}
ListElement {key: "zh_TW"; shortName: "臺灣華語"; name: "Chinese (Taiwan)"; category: qsTr("Beta Languages"); imageSource: "../../assets/twemoji/svg/1f1f9-1f1fc.svg"; selected: false}
ListElement {key: "de"; shortName: "Nederlands"; name: "Dutch"; category: qsTr("Beta Languages"); imageSource: "../../assets/twemoji/svg/1f1f3-1f1f1.svg"; selected: false}
ListElement {key: "fil"; shortName: "Wikang Filipino"; name: "Filipino"; category: qsTr("Beta Languages"); imageSource: "../../assets/twemoji/svg/1f1f5-1f1ed.svg"; selected: false}
ListElement {key: "fr"; shortName: "Français"; name: "French"; category: qsTr("Beta Languages"); imageSource: "../../assets/twemoji/svg/1f1eb-1f1f7.svg"; selected: false}
ListElement {key: "id"; shortName: "Bahasa Indonesia"; name: "Indonesian"; category: qsTr("Beta Languages"); imageSource: "../../assets/twemoji/svg/1f1ee-1f1e9.svg"; selected: false}
ListElement {key: "it"; shortName: "Italiano"; name: "Italian"; category: qsTr("Beta Languages"); imageSource: "../../assets/twemoji/svg/1f1ee-1f1f9.svg"; selected: false}
ListElement {key: "es"; shortName: "Español"; name: "Spanish"; category: qsTr("Beta Languages"); imageSource: "../../assets/twemoji/svg/1f1ea-1f1f8.svg"; selected: false}
ListElement {key: "tr"; shortName: "Türkçe"; name: "Turkish"; category: qsTr("Beta Languages"); imageSource: "../../assets/twemoji/svg/1f1f9-1f1f7.svg"; selected: false}
ListElement {key: "ur"; shortName: "اُردُو"; name: "Urdu"; category: qsTr("Beta Languages"); imageSource: "../../assets/twemoji/svg/1f1f5-1f1f0.svg"; selected: false}
}
onLocaleChanged: {
initializeLanguageModel()
}
// TODO: That logic should be moved to backend.
function initializeLanguageModel() {
var isSelected = false
for(var i = 0; i < languageModel.count; i++) {
if(localAppSettings.locale === root.languageModel.get(i).key) {
isSelected = true
root.languageModel.get(i).selected = true
}
else {
root.languageModel.get(i).selected = false
}
}
// Set default:
if(!isSelected)
root.languageModel.get(0).selected = true
}
readonly property var languageModel: languageModule ? languageModule.model : null
readonly property string currentLocale: languageModule ? languageModule.currentLocale : null
readonly property bool isDDMMYYDateFormat: localAccountSensitiveSettings.isDDMMYYDateFormat
readonly property bool is24hTimeFormat: localAccountSensitiveSettings.is24hTimeFormat
function changeLocale(locale) {
root.languageModule.changeLocale(locale)

View File

@ -8,12 +8,15 @@ import shared.popups 1.0
import StatusQ.Core 0.1
import StatusQ.Core.Theme 0.1
import StatusQ.Core.Utils 0.1 as StatusQUtils
import StatusQ.Components 0.1
import StatusQ.Controls 0.1
import "../popups"
import "../stores"
import SortFilterProxyModel 0.2
SettingsContentBase {
id: root
@ -25,7 +28,6 @@ SettingsContentBase {
Component.onCompleted: {
root.currencyStore.updateCurrenciesModel()
root.languageStore.initializeLanguageModel()
}
function setViewIdleState() {
@ -111,16 +113,48 @@ SettingsContentBase {
}
}
inputList: SortFilterProxyModel {
id: languageModel
sourceModel: root.languageStore.languageModel
function imageSourceForEmoji(emoji) {
return StatusQUtils.Emoji.iconSource(emoji)
}
proxyRoles: [
ExpressionRole {
name: "key"
expression: model.locale
},
ExpressionRole {
name: "shortName"
expression: model.native
},
ExpressionRole {
name: "category"
expression: ""
},
ExpressionRole {
name: "selected"
expression: model.locale == root.languageStore.currentLocale
},
ExpressionRole {
name: "imageSource"
expression: languageModel.imageSourceForEmoji(model.flag)
}
]
}
z: root.z + 1
width: 104
height: parent.height
anchors.right: parent.right
inputList: root.languageStore.languageModel
placeholderSearchText: qsTr("Search Languages")
maxPickerHeight: 350
onItemPickerChanged: {
if(selected && localAppSettings.locale !== key) {
if(selected && root.languageStore.currentLocale !== 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