diff --git a/Commons/I18n.qml b/Commons/I18n.qml index 59eeb9220..155dff24e 100644 --- a/Commons/I18n.qml +++ b/Commons/I18n.qml @@ -10,11 +10,13 @@ Singleton { property bool isLoaded: false property string langCode: "" + property var locale: Qt.locale() property string systemDetectedLangCode: "" property var availableLanguages: [] property var translations: ({}) property var fallbackTranslations: ({}) + // Signals for reactive updates signal languageChanged(string newLanguage) signal translationsLoaded @@ -198,6 +200,7 @@ Singleton { function setLanguage(newLangCode) { if (newLangCode !== langCode && availableLanguages.includes(newLangCode)) { langCode = newLangCode + locale = Qt.locale(langCode) Logger.i("I18n", `Language set to "${langCode}"`) languageChanged(langCode) loadTranslations() diff --git a/Modules/Bar/Calendar/CalendarPanel.qml b/Modules/Bar/Calendar/CalendarPanel.qml index 6266089be..ef84a7be0 100644 --- a/Modules/Bar/Calendar/CalendarPanel.qml +++ b/Modules/Bar/Calendar/CalendarPanel.qml @@ -11,7 +11,6 @@ import qs.Widgets NPanel { id: root - property var locale: I18n.langCode ? Qt.locale(I18n.langCode) : Qt.locale() property ShellScreen screen readonly property var now: Time.date @@ -41,7 +40,7 @@ NPanel { width: root.preferredWidth - Style.marginL * 2 spacing: Style.marginM - readonly property int firstDayOfWeek: Settings.data.location.firstDayOfWeek === -1 ? locale.firstDayOfWeek : Settings.data.location.firstDayOfWeek + readonly property int firstDayOfWeek: Settings.data.location.firstDayOfWeek === -1 ? I18n.locale.firstDayOfWeek : Settings.data.location.firstDayOfWeek property bool isCurrentMonth: true readonly property bool weatherReady: Settings.data.location.weatherEnabled && (LocationService.data.weather !== null) @@ -148,7 +147,7 @@ NPanel { spacing: Style.marginS NText { - text: locale.monthName(grid.month, Locale.LongFormat).toUpperCase() + text: I18n.locale.monthName(grid.month, Locale.LongFormat).toUpperCase() pointSize: Style.fontSizeXL * 1.1 font.weight: Style.fontWeightBold color: Color.mOnPrimary @@ -291,7 +290,7 @@ NPanel { anchors.centerIn: parent text: { let dayIndex = (content.firstDayOfWeek + index) % 7 - const dayName = locale.dayName(dayIndex, Locale.ShortFormat) + const dayName = I18n.locale.dayName(dayIndex, Locale.ShortFormat) return dayName.substring(0, 2).toUpperCase() } color: Color.mPrimary diff --git a/Modules/Bar/Calendar/DigitalClock.qml b/Modules/Bar/Calendar/DigitalClock.qml index f9dfa8d90..3d3739104 100644 --- a/Modules/Bar/Calendar/DigitalClock.qml +++ b/Modules/Bar/Calendar/DigitalClock.qml @@ -6,7 +6,6 @@ import Quickshell Item { - property var locale: I18n.langCode ? Qt.locale(I18n.langCode) : Qt.locale() property var now property color backgroundColor: Color.mPrimary property color clockColor: Color.mOnPrimary @@ -58,7 +57,7 @@ Item { NText { text: { - var t = Settings.data.location.use12hourFormat ? locale.toString(now, "hh AP") : locale.toString(now, "HH") + var t = Settings.data.location.use12hourFormat ? I18n.locale.toString(now, "hh AP") : I18n.locale.toString(now, "HH") return t.split(" ")[0] } diff --git a/Modules/Bar/Widgets/Clock.qml b/Modules/Bar/Widgets/Clock.qml index 258dbebb2..02e8b6d69 100644 --- a/Modules/Bar/Widgets/Clock.qml +++ b/Modules/Bar/Widgets/Clock.qml @@ -8,7 +8,6 @@ import qs.Widgets Rectangle { id: root - property var locale: I18n.langCode ? Qt.locale(I18n.langCode) : Qt.locale() property ShellScreen screen // Widget properties passed from Bar.qml for per-instance settings @@ -63,7 +62,7 @@ Rectangle { spacing: Settings.data.bar.showCapsule ? -4 : -2 Repeater { id: repeater - model: locale.toString(now, formatHorizontal.trim()).split("\\n") + model: I18n.locale.toString(now, formatHorizontal.trim()).split("\\n") NText { visible: text !== "" text: modelData @@ -96,7 +95,7 @@ Rectangle { anchors.centerIn: parent spacing: -2 Repeater { - model: locale.toString(now, formatVertical.trim()).split(" ") + model: I18n.locale.toString(now, formatVertical.trim()).split(" ") delegate: NText { visible: text !== "" text: modelData diff --git a/Modules/ControlCenter/Cards/WeatherCard.qml b/Modules/ControlCenter/Cards/WeatherCard.qml index e3b8b8624..6b4d5c22a 100644 --- a/Modules/ControlCenter/Cards/WeatherCard.qml +++ b/Modules/ControlCenter/Cards/WeatherCard.qml @@ -9,8 +9,6 @@ import qs.Widgets NBox { id: root - property var locale: I18n.langCode ? Qt.locale(I18n.langCode) : Qt.locale() - property int forecastDays: 7 readonly property bool weatherReady: Settings.data.location.weatherEnabled && (LocationService.data.weather !== null) @@ -104,7 +102,7 @@ NBox { Layout.alignment: Qt.AlignVCenter | Qt.AlignHCenter text: { var weatherDate = new Date(LocationService.data.weather.daily.time[index].replace(/-/g, "/")) - return locale.toString(weatherDate, "ddd") + return I18n.locale.toString(weatherDate, "ddd") } color: Color.mOnSurface } diff --git a/Modules/LockScreen/LockScreen.qml b/Modules/LockScreen/LockScreen.qml index f0211b462..7967f7804 100644 --- a/Modules/LockScreen/LockScreen.qml +++ b/Modules/LockScreen/LockScreen.qml @@ -18,8 +18,6 @@ Loader { id: lockScreen active: false - property var locale: I18n.langCode ? Qt.locale(I18n.langCode) : Qt.locale() - // Track if triggered via deprecated IPC call property bool triggeredViaDeprecatedCall: false @@ -344,7 +342,7 @@ Loader { // Date below NText { text: { - var lang = locale.name.split("_")[0] + var lang = I18n.locale.name.split("_")[0] var formats = { "de": "dddd, d. MMMM", "es": "dddd, d 'de' MMMM", @@ -352,7 +350,7 @@ Loader { "pt": "dddd, d 'de' MMMM", "zh": "yyyy年M月d日 dddd" } - return locale.toString(Time.date, formats[lang] || "dddd, MMMM d") + return I18n.locale.toString(Time.date, formats[lang] || "dddd, MMMM d") } pointSize: Style.fontSizeXL font.weight: Font.Medium @@ -768,7 +766,7 @@ Loader { NText { text: { var weatherDate = new Date(LocationService.data.weather.daily.time[index].replace(/-/g, "/")) - return Qt.locale().toString(weatherDate, "ddd") + return I18n.locale.toString(weatherDate, "ddd") } pointSize: Style.fontSizeM color: Color.mOnSurfaceVariant diff --git a/Modules/Settings/Bar/WidgetSettings/ClockSettings.qml b/Modules/Settings/Bar/WidgetSettings/ClockSettings.qml index 6d6388d6a..024592f1e 100644 --- a/Modules/Settings/Bar/WidgetSettings/ClockSettings.qml +++ b/Modules/Settings/Bar/WidgetSettings/ClockSettings.qml @@ -10,8 +10,6 @@ ColumnLayout { spacing: Style.marginM width: 700 - property var locale: I18n.langCode ? Qt.locale(I18n.langCode) : Qt.locale() - // Properties to receive data from parent property var widgetData: null property var widgetMetadata: null @@ -202,7 +200,7 @@ ColumnLayout { // Horizontal Repeater { Layout.topMargin: Style.marginM - model: locale.toString(now, valueFormatHorizontal.trim()).split("\\n") + model: I18n.locale.toString(now, valueFormatHorizontal.trim()).split("\\n") delegate: NText { visible: text !== "" text: modelData @@ -233,7 +231,7 @@ ColumnLayout { Repeater { Layout.topMargin: Style.marginM - model: locale.toString(now, valueFormatVertical.trim()).split(" ") + model: I18n.locale.toString(now, valueFormatVertical.trim()).split(" ") delegate: NText { visible: text !== "" text: modelData diff --git a/Modules/Settings/Tabs/LocationTab.qml b/Modules/Settings/Tabs/LocationTab.qml index 60da4f907..69f8c4fac 100644 --- a/Modules/Settings/Tabs/LocationTab.qml +++ b/Modules/Settings/Tabs/LocationTab.qml @@ -9,8 +9,6 @@ ColumnLayout { id: root spacing: Style.marginL - property var locale: I18n.langCode ? Qt.locale(I18n.langCode) : Qt.locale() - NHeader { label: I18n.tr("settings.location.location.section.label") description: I18n.tr("settings.location.location.section.description") @@ -137,15 +135,15 @@ ColumnLayout { "name": I18n.tr("settings.location.date-time.first-day-of-week.automatic") }, { "key": "6", - "name": locale.dayName(6, Locale.LongFormat) + "name": I18n.locale.dayName(6, Locale.LongFormat) }, // Saturday { "key": "0", - "name": locale.dayName(0, Locale.LongFormat) + "name": I18n.locale.dayName(0, Locale.LongFormat) }, // Sunday { "key": "1", - "name": locale.dayName(1, Locale.LongFormat) + "name": I18n.locale.dayName(1, Locale.LongFormat) } // Monday ] onSelected: key => Settings.data.location.firstDayOfWeek = parseInt(key) diff --git a/Widgets/NDateTimeTokens.qml b/Widgets/NDateTimeTokens.qml index bf5a53601..99bcb409d 100644 --- a/Widgets/NDateTimeTokens.qml +++ b/Widgets/NDateTimeTokens.qml @@ -6,7 +6,6 @@ import qs.Commons Rectangle { id: root - property var locale: I18n.langCode ? Qt.locale(I18n.langCode) : Qt.locale() property date sampleDate: new Date() // Dec 25, 2023, 2:30:45.123 PM signal tokenClicked(string token) @@ -313,7 +312,7 @@ Rectangle { NText { anchors.centerIn: parent - text: locale.toString(root.sampleDate, modelData.token) + text: I18n.locale.toString(root.sampleDate, modelData.token) color: tokenMouseArea.containsMouse ? Color.mOnPrimary : Color.mSurfaceVariant pointSize: Style.fontSizeS