commit eedf6aea7ade725bcc794fe59dcda1bca1c1d0b6 parent c1a24c21f7bd3766308281469eceeb23da8f58d3 Author: Marc Stibane <marc@taler.net> Date: Wed, 4 Dec 2024 06:58:09 +0100 L10N helper Diffstat:
10 files changed, 28 insertions(+), 25 deletions(-)
diff --git a/TalerWallet1/Controllers/PublicConstants.swift b/TalerWallet1/Controllers/PublicConstants.swift @@ -28,7 +28,10 @@ public let SEVENDAYS: UInt = 7 // 3..9 public let THIRTYDAYS: UInt = 30 // 10..30 public let EMPTYSTRING = "" // avoid automatic translation of empty "" textLiterals in Text() +public let SPACE = " " +public let SPACECHAR: Character = " " public let NONBREAKING: Character = "\u{00A0}" +public let LINEFEED = "\n" public let UNKNOWN = String(localized: "UNKNOWN", comment: "merchant didn't specify the currency, use ALL CAPS") public let BALANCES = "chart.bar.xaxis" // 2.0 (iOS 14) diff --git a/TalerWallet1/Helper/CallStack.swift b/TalerWallet1/Helper/CallStack.swift @@ -55,7 +55,7 @@ fileprivate func filePath2Name(_ file: String) -> String { extension CallStack { #if DEBUG - init(_ message: String = "", + init(_ message: String = EMPTYSTRING, funcName: String = #function, filePath: String = #file, line: UInt = #line) { @@ -63,13 +63,13 @@ extension CallStack { self.stack = [item] } #else - init(_ message: String = "") { + init(_ message: String = EMPTYSTRING) { let item = CallStackItem(message: message) self.stack = [item] } #endif #if DEBUG - public func push(_ message: String = "", + public func push(_ message: String = EMPTYSTRING, funcName: String = #function, filePath: String = #file, line: UInt = #line) -> CallStack { @@ -77,7 +77,7 @@ extension CallStack { return push(item: item) } #else - public func push(_ message: String = "") -> CallStack { + public func push(_ message: String = EMPTYSTRING) -> CallStack { let item = CallStackItem(message: message) return push(item: item) } @@ -86,7 +86,7 @@ extension CallStack { var result: String = EMPTYSTRING for (item) in stack { #if DEBUG - result += item.file + " " + item.function + "; " + result += item.file + SPACE + item.function + "; " #else result += item.message + "; " #endif diff --git a/TalerWallet1/Helper/CurrencySpecification.swift b/TalerWallet1/Helper/CurrencySpecification.swift @@ -171,8 +171,8 @@ public struct CurrencyInfo: Sendable { return symbolString.replacingOccurrences(of: formatter.currencyCode, with: aSymbol) } if let aName = altUnitName0 { - let spacedName = formatter.leadingCurrencySymbol ? aName + " " - : " " + aName + let spacedName = formatter.leadingCurrencySymbol ? aName + SPACE + : SPACE + aName let spacedString1 = aString.replacingOccurrences(of: formatter.currencySymbol, with: spacedName) let spacedString2 = spacedString1.replacingOccurrences(of: formatter.currencyCode, with: spacedName) let spacedString3 = spacedString2.replacingOccurrences(of: " ", with: " ") // ensure we have only 1 space @@ -181,8 +181,8 @@ public struct CurrencyInfo: Sendable { } let currency = formatter.currency if currency.count > 0 { - let spacedName = formatter.leadingCurrencySymbol ? currency + " " - : " " + currency + let spacedName = formatter.leadingCurrencySymbol ? currency + SPACE + : SPACE + currency let spacedString1 = aString.replacingOccurrences(of: formatter.currencySymbol, with: spacedName) let spacedString2 = spacedString1.replacingOccurrences(of: formatter.currencyCode, with: spacedName) let spacedString3 = spacedString2.replacingOccurrences(of: " ", with: " ") // ensure we have only 1 space @@ -294,7 +294,7 @@ public class CurrencyFormatter: NumberFormatter { static func formatter(currency: String, specs: CurrencySpecification) -> CurrencyFormatter { let formatter = CurrencyFormatter() if let altUnitNameZero = specs.altUnitNames?[0] { - if altUnitNameZero.hasPrefix(" ") { + if altUnitNameZero.hasPrefix(SPACE) { formatter.altUnitName0 = String(altUnitNameZero.dropFirst()) } else { formatter.altUnitSymbol = altUnitNameZero diff --git a/TalerWallet1/Helper/SuperScriptDigits.swift b/TalerWallet1/Helper/SuperScriptDigits.swift @@ -5,7 +5,7 @@ import Foundation func SuperScriptDigits(_ number: String) -> String { - var result = "" + var result = EMPTYSTRING for char in number { switch char { case "0": result = result + String("\u{2070}") diff --git a/TalerWallet1/Helper/TalerStrings.swift b/TalerWallet1/Helper/TalerStrings.swift @@ -48,10 +48,10 @@ extension Data { extension String { public var bytes: String { - var result: String = "" + var result: String = EMPTYSTRING for k in self.utf8 { result += String(k) - result += " " + result += SPACE } return result } @@ -78,19 +78,19 @@ extension String { var spaced: String { String(self.map { - $0 == NONBREAKING ? " " : $0 + $0 == NONBREAKING ? SPACECHAR : $0 }) } var nbs: String { String(self.map { - $0 == " " ? NONBREAKING : $0 + $0 == SPACECHAR ? NONBREAKING : $0 }) } func tabbed(oneLine: Bool) -> String { let fragments = self.components(separatedBy: "\t") if fragments.count > 1 { - let separator = oneLine ? " " : "\n" + let separator = oneLine ? SPACE : "\n" return fragments.joined(separator: separator) } return self diff --git a/TalerWallet1/Views/Actions/Peer2peer/P2PSubjectV.swift b/TalerWallet1/Views/Actions/Peer2peer/P2PSubjectV.swift @@ -99,9 +99,9 @@ struct P2PSubjectV: View { .focused($isFocused) .onChange(of: summary) { newValue in guard isFocused else { return } - guard newValue.contains("\n") else { return } + guard newValue.contains(LINEFEED) else { return } isFocused = false - summary = newValue.replacing("\n", with: "") + summary = newValue.replacing(LINEFEED, with: EMPTYSTRING) } } else { TextField("Subject", text: $summary) @@ -111,7 +111,7 @@ struct P2PSubjectV: View { guard isFocused else { return } guard newValue.contains("\n") else { return } isFocused = false - summary = newValue.replacingOccurrences(of: "\n", with: "") + summary = newValue.replacingOccurrences(of: LINEFEED, with: EMPTYSTRING) } } } // Group for iOS16+ & iOS15 .talerFont(.title2) diff --git a/TalerWallet1/Views/Balances/BalanceCellV.swift b/TalerWallet1/Views/Balances/BalanceCellV.swift @@ -79,7 +79,7 @@ struct BalanceCellV: View { balanceCell .accessibilityElement(children: .combine) .accessibilityHint(String(localized: "Will go to main transactions list.")) -// .accessibilityLabel(balanceTitleStr + " " + amountStr) // TODO: CurrencyFormatter! +// .accessibilityLabel(balanceTitleStr + SPACE + amountStr) // TODO: CurrencyFormatter! } } } diff --git a/TalerWallet1/Views/Settings/Exchange/ExchangeSectionView.swift b/TalerWallet1/Views/Settings/Exchange/ExchangeSectionView.swift @@ -131,7 +131,7 @@ struct ExchangeSectionView: View { .buttonStyle(TalerButtonStyle(type: .bordered, narrow: false, aligned: .center)) } .accessibilityElement(children: .combine) - .accessibilityLabel(bankingHint + " " + linkTitle) + .accessibilityLabel(bankingHint + SPACE + linkTitle) .padding(.top) .listRowSeparator(.hidden) } diff --git a/TalerWallet1/Views/Sheets/Payment/PayTemplateV.swift b/TalerWallet1/Views/Sheets/Payment/PayTemplateV.swift @@ -74,7 +74,7 @@ struct PayTemplateV: View { // if let result = await preparePayForTemplate(model: model, // url: url, // amount: amountToTransfer, -// summary: summaryIsEditable ? summary ?? " " +// summary: summaryIsEditable ? summary ?? SPACE // : nil, // announce: announce) // { @@ -109,7 +109,7 @@ struct PayTemplateV: View { // url: url, // amount: amountIsEditable ? prepAmount ?? zeroAmount // : nil, -// summary: summaryIsEditable ? prepSummary ?? " " +// summary: summaryIsEditable ? prepSummary ?? SPACE // : nil, // announce: announce) // { symLog.log("preparePayForTemplate finished") diff --git a/TalerWallet1/Views/Transactions/ManualDetailsV.swift b/TalerWallet1/Views/Transactions/ManualDetailsV.swift @@ -40,7 +40,7 @@ struct SegmentControl: View { let amount = detail.transferAmount let amountStr = amount?.formatted(specs: specs, isNegative: false, useISO: false) ?? EMPTYSTRING let bankName = detail.bankLabel - let a11yLabel = bankName != nil ? (bankName! + " " + amountStr) : amountStr + let a11yLabel = bankName != nil ? (bankName! + SPACE + amountStr) : amountStr // let _ = print(amountStr) VStack(spacing: 6) { Text(amountStr) @@ -191,7 +191,7 @@ struct ManualDetailsV: View { // payURL?.host() ?? String(localized: "unknown payment method") let receiverStr = (queryParameters["receiver-name"] ?? EMPTYSTRING) - .replacingOccurrences(of: "+", with: " ") + .replacingOccurrences(of: "+", with: SPACE) // let amountStr = queryParameters["amount"] ?? EMPTYSTRING // let messageStr = queryParameters["message"] ?? EMPTYSTRING // let senderStr = queryParameters["sender-name"] ?? EMPTYSTRING