-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c3eac1d
commit 59707da
Showing
2 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
Sources/OversizeCore/Extensions/Locale/Currency+Extension.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// | ||
// Copyright © 2023 Alexander Romanov | ||
// CurrencyExtension.swift, created on 15.07.2023 | ||
// | ||
|
||
import Foundation | ||
|
||
@available(macOS 13, iOS 16, tvOS 16, watchOS 9, *) | ||
public extension Locale.Currency { | ||
var dispalyName: String? { | ||
Locale.current.localizedString(forCurrencyCode: identifier) | ||
} | ||
|
||
var dispalyLocalizedSymbol: String? { | ||
Locale.current.localizedCurrencySymbol(forCurrencyCode: identifier) | ||
} | ||
|
||
var dispalySymbol: String? { | ||
let allLocalCurrencies = Locale.availableIdentifiers.compactMap { Locale(identifier: $0) } | ||
return allLocalCurrencies.first { $0.currency == self }?.currencySymbol | ||
} | ||
|
||
var locale: Locale? { | ||
let allLocalCurrencies = Locale.availableIdentifiers.compactMap { Locale(identifier: $0) } | ||
return allLocalCurrencies.first { $0.currency == self } | ||
} | ||
|
||
static var countryCurrencies: [Locale.Currency] { | ||
Locale.availableIdentifiers | ||
.compactMap { Locale(identifier: $0).currency } | ||
.removeDuplicates() | ||
.sorted { $0.dispalyName ?? "" < $1.dispalyName ?? "" } | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
Sources/OversizeCore/Extensions/Locale/Locale+Extension.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// | ||
// Copyright © 2023 Alexander Romanov | ||
// LocaleExtension.swift, created on 15.07.2023 | ||
// | ||
|
||
import Foundation | ||
|
||
@available(macOS 13, iOS 16, tvOS 16, watchOS 9, *) | ||
extension Locale { | ||
func localizedCurrencySymbol(forCurrencyCode currencyCode: String) -> String? { | ||
guard | ||
let languageCode = language.languageCode?.identifier, | ||
let regionCode = language.region?.identifier | ||
else { return nil } | ||
let components: [String: String] = [ | ||
NSLocale.Key.languageCode.rawValue: languageCode, | ||
NSLocale.Key.countryCode.rawValue: regionCode, | ||
NSLocale.Key.currencyCode.rawValue: currencyCode, | ||
] | ||
let identifier = Locale.identifier(fromComponents: components) | ||
return Locale(identifier: identifier).currencySymbol | ||
} | ||
} |