Explorar el Código

Units and abbreviations now localized. (#78)

Units in info panel and View/Header can now be localized.
Abbreviations in View/Header can now be localized.
Jon B Mårtensson hace 4 años
padre
commit
1b9e36d989

+ 12 - 3
FreeAPS/Sources/Modules/Bolus/View/BolusRootView.swift

@@ -25,7 +25,11 @@ extension Bolus {
                         HStack {
                             Text("Insulin required").foregroundColor(.secondary)
                             Spacer()
-                            Text(formatter.string(from: viewModel.inslinRequired as NSNumber)! + " U").foregroundColor(.secondary)
+                            Text(
+                                formatter
+                                    .string(from: viewModel.inslinRequired as NSNumber)! +
+                                    NSLocalizedString(" U", comment: "Insulin unit")
+                            ).foregroundColor(.secondary)
                         }.contentShape(Rectangle())
                             .onTapGesture {
                                 viewModel.amount = viewModel.inslinRecommended
@@ -33,7 +37,11 @@ extension Bolus {
                         HStack {
                             Text("Insulin recommended")
                             Spacer()
-                            Text(formatter.string(from: viewModel.inslinRecommended as NSNumber)! + " U")
+                            Text(
+                                formatter
+                                    .string(from: viewModel.inslinRequired as NSNumber)! +
+                                    NSLocalizedString(" U", comment: "Insulin unit")
+                            ).foregroundColor(.secondary)
                         }.contentShape(Rectangle())
                             .onTapGesture {
                                 viewModel.amount = viewModel.inslinRecommended
@@ -76,7 +84,8 @@ extension Bolus {
                 }
             }
             .alert(isPresented: $isAddInsulinAlertPresented) {
-                let amount = formatter.string(from: viewModel.amount as NSNumber)! + " U"
+                let amount = formatter
+                    .string(from: viewModel.amount as NSNumber)! + NSLocalizedString(" U", comment: "Insulin unit")
                 return Alert(
                     title: Text("Are you sure?"),
                     message: Text("Add \(amount) without bolusing"),

+ 4 - 3
FreeAPS/Sources/Modules/DataTable/DataTableDataFlow.swift

@@ -77,11 +77,12 @@ enum DataTable {
 
             switch type {
             case .carbs:
-                return numberFormater.string(from: amount as NSNumber)! + " g"
+                return numberFormater.string(from: amount as NSNumber)! + NSLocalizedString(" g", comment: "gram of carbs")
             case .bolus:
-                return numberFormater.string(from: amount as NSNumber)! + " U"
+                return numberFormater.string(from: amount as NSNumber)! + NSLocalizedString(" U", comment: "Insulin unit")
             case .tempBasal:
-                return numberFormater.string(from: amount as NSNumber)! + " U/hr"
+                return numberFormater
+                    .string(from: amount as NSNumber)! + NSLocalizedString(" U/hr", comment: "Unit insulin per hour")
             case .tempTarget:
                 var converted = amount
                 if units == .mmolL {

+ 6 - 5
FreeAPS/Sources/Modules/Home/View/Header/PumpView.swift

@@ -30,9 +30,9 @@ struct PumpView: View {
                         .frame(height: 8)
                         .foregroundColor(reservoirColor)
                     if reservoir == 0xDEAD_BEEF {
-                        Text("50+ U").font(.system(size: 12, weight: .bold))
+                        Text("50+ " + NSLocalizedString("U", comment: "Insulin unit")).font(.system(size: 12, weight: .bold))
                     } else {
-                        Text(reservoirFormatter.string(from: reservoir as NSNumber)! + " U")
+                        Text(reservoirFormatter.string(from: reservoir as NSNumber)! + NSLocalizedString(" U", comment: "Insulin unit"))
                             .font(.system(size: 12, weight: .bold))
                     }
                 }
@@ -74,14 +74,15 @@ struct PumpView: View {
         let minutes = Int(time / 1.minutes.timeInterval)
 
         if days >= 1 {
-            return "\(days)d \(hours)h"
+            return "\(days)" + NSLocalizedString("d", comment: "abbreviation for days") + " \(hours)" +
+            NSLocalizedString("h", comment: "abbreviation for hours")
         }
 
         if hours >= 1 {
-            return "\(hours)h"
+            return "\(hours)" + NSLocalizedString("h", comment: "abbreviation for hours")
         }
 
-        return "\(minutes)m"
+        return "\(minutes)" + NSLocalizedString("m", comment: "abbreviation for minutes")
     }
 
     private var batteryColor: Color {

+ 16 - 7
FreeAPS/Sources/Modules/Home/View/HomeRootView.swift

@@ -32,13 +32,19 @@ extension Home {
                 VStack(alignment: .leading, spacing: 12) {
                     HStack {
                         Text("IOB").font(.caption2).foregroundColor(.secondary)
-                        Text((numberFormatter.string(from: (viewModel.suggestion?.iob ?? 0) as NSNumber) ?? "0") + " U")
-                            .font(.system(size: 12, weight: .bold))
+                        Text(
+                            (numberFormatter.string(from: (viewModel.suggestion?.iob ?? 0) as NSNumber) ?? "0") +
+                                NSLocalizedString(" U", comment: "Insulin unit")
+                        )
+                        .font(.system(size: 12, weight: .bold))
                     }
                     HStack {
                         Text("COB").font(.caption2).foregroundColor(.secondary)
-                        Text((numberFormatter.string(from: (viewModel.suggestion?.cob ?? 0) as NSNumber) ?? "0") + " g")
-                            .font(.system(size: 12, weight: .bold))
+                        Text(
+                            (numberFormatter.string(from: (viewModel.suggestion?.cob ?? 0) as NSNumber) ?? "0") +
+                                NSLocalizedString(" g", comment: "gram of carbs")
+                        )
+                        .font(.system(size: 12, weight: .bold))
                     }
                 }
                 Spacer()
@@ -91,9 +97,12 @@ extension Home {
                         .font(.system(size: 12, weight: .bold)).foregroundColor(.loopGray)
                         .padding(.leading, 8)
                 } else if let tempRate = viewModel.tempRate {
-                    Text((numberFormatter.string(from: tempRate as NSNumber) ?? "0") + " U/hr")
-                        .font(.system(size: 12, weight: .bold)).foregroundColor(.insulin)
-                        .padding(.leading, 8)
+                    Text(
+                        (numberFormatter.string(from: tempRate as NSNumber) ?? "0") +
+                            NSLocalizedString(" U/hr", comment: "Unit per hour with space")
+                    )
+                    .font(.system(size: 12, weight: .bold)).foregroundColor(.insulin)
+                    .padding(.leading, 8)
                 }
 
                 if let tempTarget = viewModel.tempTarget {