i18n: Refactor string formatting to use arg() method for translations

This commit is contained in:
月月
2025-07-16 21:11:27 +08:00
parent b98e843a9d
commit 2ad60a40a8
11 changed files with 85 additions and 72 deletions
@@ -377,7 +377,7 @@ Inline w/ backslash and round brackets \\(e^{i\\pi} + 1 = 0\\)
Layout.fillWidth: true
padding: 10
color: activeFocus ? Appearance.m3colors.m3onSurface : Appearance.m3colors.m3onSurfaceVariant
placeholderText: StringUtils.format(Translation.tr('Message the model... "{0}" for commands'), root.commandPrefix)
placeholderText: Translation.tr('Message the model... "%1" for commands').arg(root.commandPrefix)
background: null
@@ -577,8 +577,9 @@ Inline w/ backslash and round brackets \\(e^{i\\pi} + 1 = 0\\)
id: toolTip
extraVisibleCondition: false
alternativeVisibleCondition: mouseArea.containsMouse // Show tooltip when hovered
content: StringUtils.format(Translation.tr("Current model: {0}\nSet it with {1}model MODEL"),
Ai.getModel().name, root.commandPrefix)
content: Translation.tr("Current model: %1\nSet it with %2model MODEL")
.arg(Ai.getModel().name)
.arg(root.commandPrefix)
}
MouseArea {
@@ -242,7 +242,7 @@ Item {
font.pixelSize: Appearance.font.pixelSize.smaller
color: Appearance.m3colors.m3inverseOnSurface
wrapMode: Text.Wrap
text: StringUtils.format(Translation.tr("{0} queries pending"), Booru.runningRequests)
text: Translation.tr("%1 queries pending").arg(Booru.runningRequests)
}
}
}
@@ -354,7 +354,7 @@ Item {
padding: 10
color: activeFocus ? Appearance.m3colors.m3onSurface : Appearance.m3colors.m3onSurfaceVariant
renderType: Text.NativeRendering
placeholderText: StringUtils.format(Translation.tr('Enter tags, or "{0}" for commands'), root.commandPrefix)
placeholderText: Translation.tr('Enter tags, or "%1" for commands').arg(root.commandPrefix)
background: null
@@ -518,8 +518,9 @@ Item {
extraVisibleCondition: false
alternativeVisibleCondition: mouseArea.containsMouse // Show tooltip when hovered
// content: Translation.tr("The current API used. Endpoint: ") + Booru.providers[Booru.currentProvider].url + Translation.tr("\nSet with /mode PROVIDER")
content: StringUtils.format(Translation.tr("Current API endpoint: {0}\nSet it with {1}mode PROVIDER"),
Booru.providers[Booru.currentProvider].url, root.commandPrefix)
content: Translation.tr("Current API endpoint: %1\nSet it with %2mode PROVIDER")
.arg(Booru.providers[Booru.currentProvider].url)
.arg(root.commandPrefix)
}
MouseArea {
@@ -165,7 +165,7 @@ Button {
id: sourceButton
visible: root.imageData.source && root.imageData.source.length > 0
Layout.fillWidth: true
buttonText: StringUtils.format(Translation.tr("Go to source ({0})"), StringUtils.getDomain(root.imageData.source))
buttonText: Translation.tr("Go to source (%1)").arg(StringUtils.getDomain(root.imageData.source))
enabled: root.imageData.source && root.imageData.source.length > 0
onClicked: {
root.showActions = false
@@ -95,7 +95,7 @@ Rectangle {
font.pixelSize: Appearance.font.pixelSize.smaller
color: Appearance.colors.colOnLayer2
// text: `Page ${root.responseData.page}`
text: StringUtils.format(Translation.tr("Page {0}"), root.responseData.page)
text: Translation.tr("Page %1").arg(root.responseData.page)
}
}
}
@@ -124,7 +124,7 @@ Scope {
StyledText {
font.pixelSize: Appearance.font.pixelSize.normal
color: Appearance.colors.colOnLayer0
text: StringUtils.format(Translation.tr("Uptime: {0}"), DateTime.uptime)
text: Translation.tr("Uptime: %1").arg(DateTime.uptime)
textFormat: Text.MarkdownText
}
@@ -29,7 +29,7 @@ QuickToggleButton {
}
}
StyledToolTip {
content: StringUtils.format(Translation.tr("{0} | Right-click to configure"),
content: Translation.tr("%1 | Right-click to configure").arg(
(Bluetooth.bluetoothEnabled && Bluetooth.bluetoothDeviceName.length > 0) ?
Bluetooth.bluetoothDeviceName : Translation.tr("Bluetooth"))
@@ -29,6 +29,6 @@ QuickToggleButton {
}
}
StyledToolTip {
content: StringUtils.format(Translation.tr("{0} | Right-click to configure"), Network.networkName)
content: Translation.tr("%1 | Right-click to configure").arg(Network.networkName)
}
}