mirror of
https://github.com/noctalia-dev/noctalia-shell.git
synced 2026-05-11 17:08:27 +08:00
Locale: factorized usage in I18n.
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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]
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user