Skip to content

Commit 8c670a6

Browse files
committed
feat(i18n): add localization support using NSLocalizedString for previously hardcoded strings
1 parent 30c8202 commit 8c670a6

6 files changed

Lines changed: 14 additions & 14 deletions

File tree

Platform/Shared/BusyOverlay.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ struct BusyOverlay: View {
3030
.alert(item: $data.alertItem) { item in
3131
switch item {
3232
case .downloadUrl(let url):
33-
return Alert(title: Text("Download VM"), message: Text("Do you want to download '\(url)'?"), primaryButton: .cancel(), secondaryButton: .default(Text("Download")) {
33+
return Alert(title: Text(NSLocalizedString("Download VM", comment: "BusyOverlay")), message: Text(String.localizedStringWithFormat(NSLocalizedString("Do you want to download '%@'?", comment: "BusyOverlay"), url.absoluteString)), primaryButton: .cancel(), secondaryButton: .default(Text(NSLocalizedString("Download", comment: "BusyOverlay"))) {
3434
data.downloadUTMZip(from: url)
3535
})
3636
case .message(let message):

Platform/Shared/UTMTips.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ struct UTMTipDonate: Tip {
3030
}
3131

3232
var actions: [Action] {
33-
Action(id: "donate", title: "Donate")
34-
Action(id: "no-thanks", title: "No Thanks")
33+
Action(id: "donate", title: NSLocalizedString("Donate", comment: "UTMTips"))
34+
Action(id: "no-thanks", title: NSLocalizedString("No Thanks", comment: "UTMTips"))
3535
}
3636

3737
var rules: [Rule] {

Platform/Shared/VMConfigDriveDetailsView.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,11 @@ struct VMConfigDriveDetailsView: View {
143143
}.alert(item: $confirmAlert) { item in
144144
switch item {
145145
case .reclaim(let imageURL):
146-
return Alert(title: Text("Would you like to re-convert this disk image to reclaim unused space? Note this will require enough temporary space to perform the conversion. You are strongly encouraged to back-up this VM before proceeding."), primaryButton: .destructive(Text("Reclaim")) { reclaimSpace(for: imageURL, withCompression: false) }, secondaryButton: .cancel())
146+
return Alert(title: Text(NSLocalizedString("Would you like to re-convert this disk image to reclaim unused space? Note this will require enough temporary space to perform the conversion. You are strongly encouraged to back-up this VM before proceeding.", comment: "VMConfigDriveDetailsView")), primaryButton: .destructive(Text("Reclaim")) { reclaimSpace(for: imageURL, withCompression: false) }, secondaryButton: .cancel())
147147
case .compress(let imageURL):
148-
return Alert(title: Text("Would you like to re-convert this disk image to reclaim unused space and apply compression? Note this will require enough temporary space to perform the conversion. Compression only applies to existing data and new data will still be written uncompressed. You are strongly encouraged to back-up this VM before proceeding."), primaryButton: .destructive(Text("Reclaim")) { reclaimSpace(for: imageURL, withCompression: true) }, secondaryButton: .cancel())
148+
return Alert(title: Text(NSLocalizedString("Would you like to re-convert this disk image to reclaim unused space and apply compression? Note this will require enough temporary space to perform the conversion. Compression only applies to existing data and new data will still be written uncompressed. You are strongly encouraged to back-up this VM before proceeding.", comment: "VMConfigDriveDetailsView")), primaryButton: .destructive(Text("Reclaim")) { reclaimSpace(for: imageURL, withCompression: true) }, secondaryButton: .cancel())
149149
case .resize(let imageURL):
150-
return Alert(title: Text("Resizing is experimental and could result in data loss. You are strongly encouraged to back-up this VM before proceeding. Would you like to resize to \(proposedSizeMib / mibInGib) GiB?"), primaryButton: .destructive(Text("Resize")) {
150+
return Alert(title: Text(String.localizedStringWithFormat(NSLocalizedString("Resizing is experimental and could result in data loss. You are strongly encouraged to back-up this VM before proceeding. Would you like to resize to %lld GiB?", comment: "VMConfigDriveDetailsView"), proposedSizeMib / mibInGib)), primaryButton: .destructive(Text("Resize")) {
151151
resizeDrive(for: imageURL, sizeInMib: proposedSizeMib)
152152
}, secondaryButton: .cancel())
153153
}

Platform/Shared/VMConfigNetworkView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ struct VMConfigNetworkView: View {
4747
}
4848
}
4949
if config.mode == .host {
50-
Picker("Host Network", selection: $config.hostNetUuid) {
50+
Picker(NSLocalizedString("Host Network", comment: "VMConfigNetworkView"), selection: $config.hostNetUuid) {
5151
Text("Default (private)")
5252
.tag(nil as String?)
5353
ForEach(hostNetworks) { interface in

Platform/Shared/VMDetailsView.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -375,14 +375,14 @@ struct Details: View {
375375
}
376376
ForEach(network.currentIpAddresses) { guestIP in
377377
HStack {
378-
plainLabel("Guest IP", systemImage: "network.badge.shield.half.filled")
378+
plainLabel(LocalizedStringKey(NSLocalizedString("Guest IP", comment: "VMDetailsView")), systemImage: "network.badge.shield.half.filled")
379379
Spacer()
380380
OptionalSelectableText(guestIP)
381381
}
382382
}
383383
if network.mode == .bridged, let interface = network.bridgeInterface {
384384
HStack {
385-
plainLabel("Bridge Interface", systemImage: "arrow.triangle.branch")
385+
plainLabel(LocalizedStringKey(NSLocalizedString("Bridge Interface", comment: "VMDetailsView")), systemImage: "arrow.triangle.branch")
386386
Spacer()
387387
Text(interface)
388388
.foregroundColor(.secondary)
@@ -405,7 +405,7 @@ struct Details: View {
405405
ForEach(appleConfig.serials) { serial in
406406
if serial.mode == .ptty {
407407
HStack {
408-
plainLabel("Serial (TTY)", systemImage: "phone.connection")
408+
plainLabel(LocalizedStringKey(NSLocalizedString("Serial (TTY)", comment: "VMDetailsView")), systemImage: "phone.connection")
409409
Spacer()
410410
OptionalSelectableText(serial.interface?.name)
411411
}
@@ -417,14 +417,14 @@ struct Details: View {
417417
ForEach(qemuConfig.serials) { serial in
418418
if serial.mode == .tcpClient {
419419
HStack {
420-
plainLabel("Serial (Client)", systemImage: "network")
420+
plainLabel(LocalizedStringKey(NSLocalizedString("Serial (Client)", comment: "VMDetailsView")), systemImage: "network")
421421
Spacer()
422422
let address = "\(serial.tcpHostAddress ?? "example.com"):\(serial.tcpPort ?? 1234)"
423423
OptionalSelectableText(vm.state == .started ? address : nil)
424424
}
425425
} else if serial.mode == .tcpServer {
426426
HStack {
427-
plainLabel("Serial (Server)", systemImage: "network")
427+
plainLabel(LocalizedStringKey(NSLocalizedString("Serial (Server)", comment: "VMDetailsView")), systemImage: "network")
428428
Spacer()
429429
let address = "\(serial.tcpPort ?? 1234)"
430430
OptionalSelectableText(vm.state == .started ? address : nil)
@@ -433,7 +433,7 @@ struct Details: View {
433433
#if os(macOS)
434434
if serial.mode == .ptty {
435435
HStack {
436-
plainLabel("Serial (TTY)", systemImage: "phone.connection")
436+
plainLabel(LocalizedStringKey(NSLocalizedString("Serial (TTY)", comment: "VMDetailsView")), systemImage: "phone.connection")
437437
Spacer()
438438
OptionalSelectableText(serial.pttyDevice?.path)
439439
}

Platform/iOS/UTMDonateView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ private struct StoreView: View {
9292
if store.consumables.isEmpty && store.subscriptions.isEmpty {
9393
Link("GitHub Sponsors", destination: URL(string: "https://github.com/sponsors/utmapp")!)
9494
} else if !store.subscriptions.isEmpty {
95-
Button("Restore Purchases") {
95+
Button(NSLocalizedString("Restore Purchases", comment: "UTMDonateView")) {
9696
Task {
9797
try? await AppStore.sync()
9898
}

0 commit comments

Comments
 (0)