mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-04-04 04:42:05 -04:00
feat: add setting to change and hotreload locale (#1817)
* feat: add setting to change and hotreload locale * fix: typo in component id * feat: add persistent locale setting * feat: wrap useLocale in a settings set hook, enable locale hotreload when editing settings file * chore: update translation and settings file * feat: enable fuzzy search in locale setting * fix: regenerate translations with official plugins cloned * fix: revert back to system's locale for displaying certain time formats
This commit is contained in:
@@ -271,8 +271,8 @@ Item {
|
||||
|
||||
text: {
|
||||
if (SettingsData.clockDateFormat && SettingsData.clockDateFormat.length > 0)
|
||||
return systemClock.date?.toLocaleDateString(Qt.locale(), SettingsData.clockDateFormat) ?? "";
|
||||
return systemClock.date?.toLocaleDateString(Qt.locale(), "ddd, MMM d") ?? "";
|
||||
return systemClock.date?.toLocaleDateString(I18n.locale(), SettingsData.clockDateFormat) ?? "";
|
||||
return systemClock.date?.toLocaleDateString(I18n.locale(), "ddd, MMM d") ?? "";
|
||||
}
|
||||
font.pixelSize: Theme.fontSizeSmall
|
||||
color: root.accentColor
|
||||
@@ -324,8 +324,8 @@ Item {
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
text: {
|
||||
if (SettingsData.clockDateFormat && SettingsData.clockDateFormat.length > 0)
|
||||
return systemClock.date?.toLocaleDateString(Qt.locale(), SettingsData.clockDateFormat) ?? "";
|
||||
return systemClock.date?.toLocaleDateString(Qt.locale(), "ddd, MMM d") ?? "";
|
||||
return systemClock.date?.toLocaleDateString(I18n.locale(), SettingsData.clockDateFormat) ?? "";
|
||||
return systemClock.date?.toLocaleDateString(I18n.locale(), "ddd, MMM d") ?? "";
|
||||
}
|
||||
font.pixelSize: digitalRoot.smallSize
|
||||
color: Theme.withAlpha(root.accentColor, 0.7)
|
||||
@@ -528,7 +528,7 @@ Item {
|
||||
StyledText {
|
||||
visible: stackedRoot.hasDate
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
text: systemClock.date?.toLocaleDateString(Qt.locale(), "MMM dd") ?? ""
|
||||
text: systemClock.date?.toLocaleDateString(I18n.locale(), "MMM dd") ?? ""
|
||||
font.pixelSize: stackedRoot.smallSize * 0.7
|
||||
color: Theme.withAlpha(root.accentColor, 0.7)
|
||||
}
|
||||
|
||||
@@ -129,7 +129,7 @@ BasePill {
|
||||
|
||||
StyledText {
|
||||
text: {
|
||||
const locale = Qt.locale();
|
||||
const locale = I18n.locale();
|
||||
const dateFormatShort = locale.dateFormat(Locale.ShortFormat);
|
||||
const dayFirst = dateFormatShort.indexOf('d') < dateFormatShort.indexOf('M');
|
||||
const value = dayFirst ? String(systemClock?.date?.getDate()).padStart(2, '0') : String(systemClock?.date?.getMonth() + 1).padStart(2, '0');
|
||||
@@ -144,7 +144,7 @@ BasePill {
|
||||
|
||||
StyledText {
|
||||
text: {
|
||||
const locale = Qt.locale();
|
||||
const locale = I18n.locale();
|
||||
const dateFormatShort = locale.dateFormat(Locale.ShortFormat);
|
||||
const dayFirst = dateFormatShort.indexOf('d') < dateFormatShort.indexOf('M');
|
||||
const value = dayFirst ? String(systemClock?.date?.getDate()).padStart(2, '0') : String(systemClock?.date?.getMonth() + 1).padStart(2, '0');
|
||||
@@ -165,7 +165,7 @@ BasePill {
|
||||
|
||||
StyledText {
|
||||
text: {
|
||||
const locale = Qt.locale();
|
||||
const locale = I18n.locale();
|
||||
const dateFormatShort = locale.dateFormat(Locale.ShortFormat);
|
||||
const dayFirst = dateFormatShort.indexOf('d') < dateFormatShort.indexOf('M');
|
||||
const value = dayFirst ? String(systemClock?.date?.getMonth() + 1).padStart(2, '0') : String(systemClock?.date?.getDate()).padStart(2, '0');
|
||||
@@ -180,7 +180,7 @@ BasePill {
|
||||
|
||||
StyledText {
|
||||
text: {
|
||||
const locale = Qt.locale();
|
||||
const locale = I18n.locale();
|
||||
const dateFormatShort = locale.dateFormat(Locale.ShortFormat);
|
||||
const dayFirst = dateFormatShort.indexOf('d') < dateFormatShort.indexOf('M');
|
||||
const value = dayFirst ? String(systemClock?.date?.getMonth() + 1).padStart(2, '0') : String(systemClock?.date?.getDate()).padStart(2, '0');
|
||||
@@ -311,9 +311,9 @@ BasePill {
|
||||
id: dateText
|
||||
text: {
|
||||
if (SettingsData.clockDateFormat && SettingsData.clockDateFormat.length > 0) {
|
||||
return systemClock?.date?.toLocaleDateString(Qt.locale(), SettingsData.clockDateFormat);
|
||||
return systemClock?.date?.toLocaleDateString(I18n.locale(), SettingsData.clockDateFormat);
|
||||
}
|
||||
return systemClock?.date?.toLocaleDateString(Qt.locale(), "ddd d");
|
||||
return systemClock?.date?.toLocaleDateString(I18n.locale(), "ddd d");
|
||||
}
|
||||
font.pixelSize: clockRow.fontSize
|
||||
color: Theme.widgetTextColor
|
||||
|
||||
@@ -179,7 +179,7 @@ Rectangle {
|
||||
StyledText {
|
||||
width: parent.width - 56
|
||||
height: 28
|
||||
text: calendarGrid.displayDate.toLocaleDateString(Qt.locale(), "MMMM yyyy")
|
||||
text: calendarGrid.displayDate.toLocaleDateString(I18n.locale(), "MMMM yyyy")
|
||||
font.pixelSize: Theme.fontSizeMedium
|
||||
color: Theme.surfaceText
|
||||
font.weight: Font.Medium
|
||||
@@ -223,11 +223,10 @@ Rectangle {
|
||||
Repeater {
|
||||
model: {
|
||||
const days = [];
|
||||
const loc = Qt.locale();
|
||||
const qtFirst = loc.firstDayOfWeek;
|
||||
const qtFirst = Qt.locale().firstDayOfWeek;
|
||||
for (let i = 0; i < 7; ++i) {
|
||||
const qtDay = ((qtFirst - 1 + i) % 7) + 1;
|
||||
days.push(loc.dayName(qtDay, Locale.ShortFormat));
|
||||
days.push(I18n.locale().dayName(qtDay, Locale.ShortFormat));
|
||||
}
|
||||
return days;
|
||||
}
|
||||
|
||||
@@ -99,7 +99,7 @@ Card {
|
||||
}
|
||||
|
||||
StyledText {
|
||||
text: systemClock?.date?.toLocaleDateString(Qt.locale(), "MMM dd")
|
||||
text: systemClock?.date?.toLocaleDateString(I18n.locale(), "MMM dd")
|
||||
font.pixelSize: Theme.fontSizeSmall
|
||||
color: Qt.rgba(Theme.surfaceText.r, Theme.surfaceText.g, Theme.surfaceText.b, 0.7)
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
|
||||
@@ -218,7 +218,7 @@ Item {
|
||||
|
||||
property string fullTimeStr: {
|
||||
const format = GreetdSettings.getEffectiveTimeFormat();
|
||||
return systemClock.date.toLocaleTimeString(Qt.locale(), format);
|
||||
return systemClock.date.toLocaleTimeString(I18n.locale(), format);
|
||||
}
|
||||
property var timeParts: fullTimeStr.split(':')
|
||||
property string hours: timeParts[0] || ""
|
||||
@@ -328,9 +328,9 @@ Item {
|
||||
anchors.topMargin: 4
|
||||
text: {
|
||||
if (GreetdSettings.lockDateFormat && GreetdSettings.lockDateFormat.length > 0) {
|
||||
return systemClock.date.toLocaleDateString(Qt.locale(), GreetdSettings.lockDateFormat);
|
||||
return systemClock.date.toLocaleDateString(I18n.locale(), GreetdSettings.lockDateFormat);
|
||||
}
|
||||
return systemClock.date.toLocaleDateString(Qt.locale(), Locale.LongFormat);
|
||||
return systemClock.date.toLocaleDateString(I18n.locale(), Locale.LongFormat);
|
||||
}
|
||||
font.pixelSize: Theme.fontSizeXLarge
|
||||
color: "white"
|
||||
|
||||
@@ -333,9 +333,9 @@ Item {
|
||||
visible: SettingsData.lockScreenShowDate
|
||||
text: {
|
||||
if (SettingsData.lockDateFormat && SettingsData.lockDateFormat.length > 0) {
|
||||
return systemClock.date.toLocaleDateString(Qt.locale(), SettingsData.lockDateFormat);
|
||||
return systemClock.date.toLocaleDateString(I18n.locale(), SettingsData.lockDateFormat);
|
||||
}
|
||||
return systemClock.date.toLocaleDateString(Qt.locale(), Locale.LongFormat);
|
||||
return systemClock.date.toLocaleDateString(I18n.locale(), Locale.LongFormat);
|
||||
}
|
||||
font.pixelSize: Theme.fontSizeXLarge
|
||||
color: "white"
|
||||
|
||||
63
quickshell/Modules/Settings/LocaleTab.qml
Normal file
63
quickshell/Modules/Settings/LocaleTab.qml
Normal file
@@ -0,0 +1,63 @@
|
||||
import QtQuick
|
||||
import qs.Common
|
||||
import qs.Services
|
||||
import qs.Widgets
|
||||
import qs.Modules.Settings.Widgets
|
||||
|
||||
Item {
|
||||
id: root
|
||||
|
||||
function capitalizeNativeLanguageName(localeCode) {
|
||||
if (I18n.presentLocales[localeCode] == undefined) {
|
||||
return;
|
||||
}
|
||||
const nativeName = I18n.presentLocales[localeCode].nativeLanguageName;
|
||||
return nativeName[0].toUpperCase() + nativeName.slice(1);
|
||||
}
|
||||
|
||||
DankFlickable {
|
||||
anchors.fill: parent
|
||||
clip: true
|
||||
contentHeight: mainColumn.height + Theme.spacingXL
|
||||
contentWidth: width
|
||||
|
||||
Column {
|
||||
id: mainColumn
|
||||
topPadding: 4
|
||||
width: Math.min(550, parent.width - Theme.spacingL * 2)
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
spacing: Theme.spacingXL
|
||||
|
||||
SettingsCard {
|
||||
tab: "locale"
|
||||
tags: ["locale", "language", "country"]
|
||||
title: I18n.tr("Locale Settings")
|
||||
iconName: "language"
|
||||
|
||||
SettingsDropdownRow {
|
||||
id: localeDropdown
|
||||
tab: "locale"
|
||||
tags: ["locale", "language", "country"]
|
||||
settingKey: "locale"
|
||||
text: I18n.tr("Current Locale")
|
||||
description: I18n.tr("Change the locale used by the DMS interface.")
|
||||
options: Object.keys(I18n.presentLocales).map(root.capitalizeNativeLanguageName)
|
||||
enableFuzzySearch: true
|
||||
|
||||
Component.onCompleted: {
|
||||
currentValue = root.capitalizeNativeLanguageName(SettingsData.locale);
|
||||
}
|
||||
|
||||
onValueChanged: value => {
|
||||
for (let code of Object.keys(I18n.presentLocales)) {
|
||||
if (root.capitalizeNativeLanguageName(code) === value) {
|
||||
SettingsData.set("locale", code);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -74,7 +74,7 @@ Item {
|
||||
tags: ["date", "format", "topbar"]
|
||||
settingKey: "clockDateFormat"
|
||||
text: I18n.tr("Top Bar Format")
|
||||
description: "Preview: " + (SettingsData.clockDateFormat ? new Date().toLocaleDateString(Qt.locale(), SettingsData.clockDateFormat) : new Date().toLocaleDateString(Qt.locale(), "ddd d"))
|
||||
description: "Preview: " + (SettingsData.clockDateFormat ? new Date().toLocaleDateString(I18n.locale(), SettingsData.clockDateFormat) : new Date().toLocaleDateString(I18n.locale(), "ddd d"))
|
||||
options: [I18n.tr("System Default", "date format option"), I18n.tr("Day Date", "date format option"), I18n.tr("Day Month Date", "date format option"), I18n.tr("Month Date", "date format option"), I18n.tr("Numeric (M/D)", "date format option"), I18n.tr("Numeric (D/M)", "date format option"), I18n.tr("Full with Year", "date format option"), I18n.tr("ISO Date", "date format option"), I18n.tr("Full Day & Month", "date format option"), I18n.tr("Custom...", "date format option")]
|
||||
currentValue: {
|
||||
if (!SettingsData.clockDateFormat || SettingsData.clockDateFormat.length === 0)
|
||||
@@ -161,7 +161,7 @@ Item {
|
||||
tags: ["date", "format", "lock", "screen"]
|
||||
settingKey: "lockDateFormat"
|
||||
text: I18n.tr("Lock Screen Format")
|
||||
description: "Preview: " + (SettingsData.lockDateFormat ? new Date().toLocaleDateString(Qt.locale(), SettingsData.lockDateFormat) : new Date().toLocaleDateString(Qt.locale(), Locale.LongFormat))
|
||||
description: "Preview: " + (SettingsData.lockDateFormat ? new Date().toLocaleDateString(I18n.locale(), SettingsData.lockDateFormat) : new Date().toLocaleDateString(I18n.locale(), Locale.LongFormat))
|
||||
options: [I18n.tr("System Default", "date format option"), I18n.tr("Day Date", "date format option"), I18n.tr("Day Month Date", "date format option"), I18n.tr("Month Date", "date format option"), I18n.tr("Numeric (M/D)", "date format option"), I18n.tr("Numeric (D/M)", "date format option"), I18n.tr("Full with Year", "date format option"), I18n.tr("ISO Date", "date format option"), I18n.tr("Full Day & Month", "date format option"), I18n.tr("Custom...", "date format option")]
|
||||
currentValue: {
|
||||
if (!SettingsData.lockDateFormat || SettingsData.lockDateFormat.length === 0)
|
||||
|
||||
Reference in New Issue
Block a user