From e85f4894297ac328105d332a34e0b200ead7263c Mon Sep 17 00:00:00 2001 From: loner <2788892716@qq.com> Date: Sat, 18 Oct 2025 22:49:36 +0800 Subject: [PATCH] feat: Implement language selection feature --- Assets/Translations/en.json | 12 ++++++++++- Assets/settings-default.json | 5 +++-- Commons/I18n.qml | 7 +++++++ Commons/Settings.qml | 1 + Modules/Settings/Tabs/GeneralTab.qml | 31 +++++++++++++++++++++++++++- 5 files changed, 52 insertions(+), 4 deletions(-) diff --git a/Assets/Translations/en.json b/Assets/Translations/en.json index e8ee372b..5c0b9e5d 100644 --- a/Assets/Translations/en.json +++ b/Assets/Translations/en.json @@ -68,6 +68,16 @@ "description": "Increase or decrease the size of the monospaced text." } } + }, + "language": { + "section": { + "label": "Language", + "description": "Choose your preferred language for the application." + }, + "select": { + "label": "Application Language", + "description": "Select the language used in the application's interface." + } } }, "audio": { @@ -1197,7 +1207,7 @@ "scan-again": "Scan again" } }, - + "tooltips": { "refresh": "Refresh", "close": "Close", diff --git a/Assets/settings-default.json b/Assets/settings-default.json index 27f2b735..850fc6f8 100644 --- a/Assets/settings-default.json +++ b/Assets/settings-default.json @@ -66,7 +66,8 @@ "animationSpeed": 1, "animationDisabled": false, "compactLockScreen": false, - "lockOnSuspend": true + "lockOnSuspend": true, + "language": "en" }, "location": { "name": "Tokyo", @@ -255,4 +256,4 @@ "battery": { "chargingMode": 0 } -} \ No newline at end of file +} diff --git a/Commons/I18n.qml b/Commons/I18n.qml index 6f49f097..fe2ab0a6 100644 --- a/Commons/I18n.qml +++ b/Commons/I18n.qml @@ -168,6 +168,13 @@ Singleton { } } + // Check for user-defined language setting + if (Settings.data.general.language !== "" && availableLanguages.includes(Settings.data.general.language)) { + Logger.d("I18n", `User-defined language found: "${Settings.data.general.language}"`) + setLanguage(Settings.data.general.language) + return + } + // Detect user's favorite locale - languages for (var i = 0; i < Qt.locale().uiLanguages.length; i++) { const fullUserLang = Qt.locale().uiLanguages[i] diff --git a/Commons/Settings.qml b/Commons/Settings.qml index a0306c13..6799dc8e 100644 --- a/Commons/Settings.qml +++ b/Commons/Settings.qml @@ -192,6 +192,7 @@ Singleton { property bool animationDisabled: false property bool compactLockScreen: false property bool lockOnSuspend: true + property string language: "en" } // location diff --git a/Modules/Settings/Tabs/GeneralTab.qml b/Modules/Settings/Tabs/GeneralTab.qml index 0a63a7fd..3bd5de54 100644 --- a/Modules/Settings/Tabs/GeneralTab.qml +++ b/Modules/Settings/Tabs/GeneralTab.qml @@ -190,7 +190,36 @@ ColumnLayout { Layout.bottomMargin: Style.marginXL } - // Lock Screen + // Language selection + ColumnLayout { + spacing: Style.marginL + Layout.fillWidth: true + + NHeader { + label: I18n.tr("settings.general.language.section.label") + description: I18n.tr("settings.general.language.section.description") + } + + NComboBox { + Layout.fillWidth: true + label: I18n.tr("settings.general.language.select.label") + description: I18n.tr("settings.general.language.select.description") + model: I18n.availableLanguages.map(function(langCode) { + return { "key": langCode, "name": langCode } + }) + currentKey: Settings.data.general.language !== "" ? Settings.data.general.language : I18n.langCode + onSelected: key => { + Settings.data.general.language = key + I18n.setLanguage(key) + } + } + } + + NDivider { + Layout.fillWidth: true + Layout.topMargin: Style.marginXL + Layout.bottomMargin: Style.marginXL + } ColumnLayout { spacing: Style.marginL Layout.fillWidth: true