Skip to content

Your Android phone and your Windows PC, working as one. Local-first, end-to-end encrypted, no account.

i18n(desktop): format decimal file sizes and speeds via Qt.locale()

Jochen Kirstätterb3f895c23520
diff --git a/desktop/app/qml/IslandWindow.qml b/desktop/app/qml/IslandWindow.qml
index 404fe14..efc54a1 100644
--- a/desktop/app/qml/IslandWindow.qml
+++ b/desktop/app/qml/IslandWindow.qml
@@ -158,8 +158,8 @@ Window {
const b = Number(bytesPerSec) || 0
if (b <= 0) return ""
if (b < 1024 * 1024)
- return (b / 1024).toFixed(0) + " KB/s"
- return (b / (1024 * 1024)).toFixed(1) + " MB/s"
+ return Math.round(b / 1024) + " KB/s"
+ return Qt.locale().toString(b / (1024 * 1024), "f", 1) + " MB/s"
}
readonly property bool hasMediaCandidate: mediaPlaying && mediaDeviceId !== "local" && mediaTitle.length > 0
diff --git a/desktop/app/qml/ShelfWindow.qml b/desktop/app/qml/ShelfWindow.qml
index 8ccdb1d..8bb14eb 100644
--- a/desktop/app/qml/ShelfWindow.qml
+++ b/desktop/app/qml/ShelfWindow.qml
@@ -131,13 +131,14 @@ Window {
function formatBytes(bytes) {
const b = Number(bytes) || 0
+ const locale = Qt.locale()
if (b < 1024)
return qsTr("%1 B").arg(b)
if (b < 1024 * 1024)
- return qsTr("%1 KB").arg((b / 1024).toFixed(1))
+ return qsTr("%1 KB").arg(locale.toString(b / 1024, "f", 1))
if (b < 1024 * 1024 * 1024)
- return qsTr("%1 MB").arg((b / (1024 * 1024)).toFixed(1))
- return qsTr("%1 GB").arg((b / (1024 * 1024 * 1024)).toFixed(2))
+ return qsTr("%1 MB").arg(locale.toString(b / (1024 * 1024), "f", 1))
+ return qsTr("%1 GB").arg(locale.toString(b / (1024 * 1024 * 1024), "f", 2))
}
Component.onCompleted: {
diff --git a/desktop/app/qml/components/CommandPalette.qml b/desktop/app/qml/components/CommandPalette.qml
index d6cc98e..7830e84 100644
--- a/desktop/app/qml/components/CommandPalette.qml
+++ b/desktop/app/qml/components/CommandPalette.qml
@@ -398,7 +398,7 @@ Item {
if (AppController.commandPaletteOpenMs <= 0)
return hk
const msText = AppController.commandPaletteOpenMs < 10
- ? AppController.commandPaletteOpenMs.toFixed(1)
+ ? Qt.locale().toString(AppController.commandPaletteOpenMs, "f", 1)
: String(Math.round(AppController.commandPaletteOpenMs))
return qsTr("%1 · %2 ms").arg(hk).arg(msText)
}
diff --git a/desktop/app/qml/components/TransferItem.qml b/desktop/app/qml/components/TransferItem.qml
index aeae28f..7dd681a 100644
--- a/desktop/app/qml/components/TransferItem.qml
+++ b/desktop/app/qml/components/TransferItem.qml
@@ -29,7 +29,7 @@ Item {
let value = bytes / 1024
let unit = 0
while (value >= 1024 && unit < units.length - 1) { value /= 1024; unit++ }
- return units[unit].arg(value < 10 ? value.toFixed(1) : Math.round(value))
+ return units[unit].arg(value < 10 ? Qt.locale().toString(value, "f", 1) : Math.round(value))
}
function detail() {
diff --git a/desktop/app/qml/pages/HomePage.qml b/desktop/app/qml/pages/HomePage.qml
index 1630fef..e7d0aa5 100644
--- a/desktop/app/qml/pages/HomePage.qml
+++ b/desktop/app/qml/pages/HomePage.qml
@@ -52,7 +52,7 @@ Item {
let value = bytes / 1024
let unit = 0
while (value >= 1024 && unit < units.length - 1) { value /= 1024; unit++ }
- return units[unit].arg(value < 10 ? value.toFixed(1) : Math.round(value))
+ return units[unit].arg(value < 10 ? Qt.locale().toString(value, "f", 1) : Math.round(value))
}
FileDialog {
diff --git a/desktop/app/qml/pages/PhotosPage.qml b/desktop/app/qml/pages/PhotosPage.qml
index 9ed3bfa..0493078 100644
--- a/desktop/app/qml/pages/PhotosPage.qml
+++ b/desktop/app/qml/pages/PhotosPage.qml
@@ -112,7 +112,7 @@ Item {
let value = bytes / 1024
let unit = 0
while (value >= 1024 && unit < units.length - 1) { value /= 1024; unit++ }
- return units[unit].arg(unit === 0 ? Math.round(value) : (value < 10 ? value.toFixed(1) : Math.round(value)))
+ return units[unit].arg(unit === 0 ? Math.round(value) : (value < 10 ? Qt.locale().toString(value, "f", 1) : Math.round(value)))
}
function isSelected(id) {
diff --git a/desktop/app/qml/pages/SettingsPage.qml b/desktop/app/qml/pages/SettingsPage.qml
index 1e4fc74..668af9d 100644
--- a/desktop/app/qml/pages/SettingsPage.qml
+++ b/desktop/app/qml/pages/SettingsPage.qml
@@ -136,6 +136,7 @@ Item {
function formatRetentionBytes(bytes) {
const b = Number(bytes || 0)
+ const locale = Qt.locale()
if (b <= 0)
return qsTr("%1 B").arg(0)
if (b < 1024)
@@ -143,10 +144,10 @@ Item {
if (b < 1024 * 1024)
return qsTr("%1 KB").arg(Math.max(1, Math.round(b / 1024)))
if (b < 1024 * 1024 * 1024)
- return qsTr("%1 MB").arg((b / (1024 * 1024)).toFixed(1))
+ return qsTr("%1 MB").arg(locale.toString(b / (1024 * 1024), "f", 1))
if (b < 1024 * 1024 * 1024 * 1024)
- return qsTr("%1 GB").arg((b / (1024 * 1024 * 1024)).toFixed(1))
- return qsTr("%1 TB").arg((b / (1024 * 1024 * 1024 * 1024)).toFixed(1))
+ return qsTr("%1 GB").arg(locale.toString(b / (1024 * 1024 * 1024), "f", 1))
+ return qsTr("%1 TB").arg(locale.toString(b / (1024 * 1024 * 1024 * 1024), "f", 1))
}
visible: active