Skip to content

Commit 1fe6e1f

Browse files
parkeraCharles Hu
authored andcommitted
rdar://106898040 (Fix currency text field)
1 parent 4400b9d commit 1fe6e1f

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

Sources/FoundationInternationalization/Locale/Locale.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,20 @@ public struct Locale : Hashable, Equatable, Sendable {
321321
}
322322
}
323323

324+
/// This exists in `NSLocale` via the `displayName` API, using the currency *symbol* key instead of *code*.
325+
internal func localizedString(forCurrencySymbol currencySymbol: String) -> String? {
326+
switch kind {
327+
case .fixed(let l):
328+
return l.currencySymbolDisplayName(for: currencySymbol)
329+
#if FOUNDATION_FRAMEWORK
330+
case .bridged(let l):
331+
return l.currencySymbolDisplayName(for: currencySymbol)
332+
#endif
333+
case .autoupdating:
334+
return LocaleCache.cache.current.currencySymbolDisplayName(for: currencySymbol)
335+
}
336+
}
337+
324338
/// Returns a localized string for a specified ICU collation identifier.
325339
///
326340
/// For example, in the "en" locale, the result for `"phonebook"` is `"Phonebook Sort Order"`.

Sources/FoundationInternationalization/Locale/Locale_Wrappers.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,10 @@ internal final class _NSLocaleSwiftWrapper: @unchecked Sendable, Hashable, Custo
265265
func currencyCodeDisplayName(for currencyCode: String) -> String? {
266266
return _wrapped.displayName(forKey: .currencyCode, value: currencyCode)
267267
}
268+
269+
func currencySymbolDisplayName(for currencySymbol: String) -> String? {
270+
return _wrapped.displayName(forKey: .currencySymbol, value: currencySymbol)
271+
}
268272

269273
func collationIdentifierDisplayName(for collationIdentifier: String) -> String? {
270274
return _wrapped.displayName(forKey: .collationIdentifier, value: collationIdentifier)
@@ -502,7 +506,7 @@ internal class _NSSwiftLocale: _NSLocaleBridge {
502506
case .measurementSystem: return nil
503507
case .decimalSeparator: return nil
504508
case .groupingSeparator: return nil
505-
case .currencySymbol: return self.localizedString(forCurrencyCode: value)
509+
case .currencySymbol: return self.localizedString(forCurrencySymbol: value)
506510
case .currencyCode: return self.localizedString(forCurrencyCode: value)
507511
case .collatorIdentifier: return self.localizedString(forCollatorIdentifier: value)
508512
case .quotationBeginDelimiterKey: return nil
@@ -640,6 +644,10 @@ internal class _NSSwiftLocale: _NSLocaleBridge {
640644
locale.localizedString(forCurrencyCode: currencyCode)
641645
}
642646

647+
override func localizedString(forCurrencySymbol currencySymbol: String) -> String? {
648+
locale.localizedString(forCurrencySymbol: currencySymbol)
649+
}
650+
643651
override func localizedString(forCollatorIdentifier collatorIdentifier: String) -> String? {
644652
locale.localizedString(forCollatorIdentifier: collatorIdentifier)
645653
}

0 commit comments

Comments
 (0)