mirror of
https://github.com/RevenueCat/purchases-ios
synced 2026-11-11 22:55:55 +05:45
* Passing price currencyCode to the TestStore product to use when formatting a price string * Use the same locale for formatting localizedPriceString as well as other price strings for Test Store product * Fixed test compilation + ensuring backwards compatibility in TestStoreProduct initializer * Added unit tests * Fixed swiftlint warnings * Deprecated old TestProduct initializer and updated all tests to pass currencyCode and locale for proper price formatting * Added API test for new initializer * Fixed test compilation + updated remaining uses of TestStoreProduct * Reusing Locale extension across packages * Fixed import * Fixed test imports * Implemented PR feedback * Updated doc + fixed test compilation * Fixed test compilation
60 lines
1.7 KiB
Swift
60 lines
1.7 KiB
Swift
//
|
|
// Copyright RevenueCat Inc. All Rights Reserved.
|
|
//
|
|
// Licensed under the MIT License (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// https://opensource.org/licenses/MIT
|
|
//
|
|
// Locale+Extensions.swift
|
|
//
|
|
// Created by Nacho Soto on 6/21/23.
|
|
|
|
import Foundation
|
|
|
|
@_spi(Internal)
|
|
public extension Locale {
|
|
|
|
/// Returns true if the language component of the Locale is equal to the one of self
|
|
func matchesLanguage(_ rhs: Locale) -> Bool {
|
|
self.removingRegion == rhs.removingRegion
|
|
}
|
|
|
|
// swiftlint:disable identifier_name
|
|
/// The code of the currency used by the locale.
|
|
var rc_currencyCode: String? {
|
|
#if swift(>=5.9)
|
|
// `Locale.currencyCode` is deprecated
|
|
if #available(macOS 13, iOS 16, tvOS 16, watchOS 9, visionOS 1.0, *) {
|
|
return self.currency?.identifier
|
|
} else {
|
|
return self.currencyCode
|
|
}
|
|
#else
|
|
return self.currencyCode
|
|
#endif
|
|
}
|
|
|
|
/// The language code that identifies the locale's language.
|
|
var rc_languageCode: String? {
|
|
#if swift(>=5.9)
|
|
// `Locale.languageCode` is deprecated
|
|
if #available(macOS 13, iOS 16, tvOS 16, watchOS 9, visionOS 1.0, *) {
|
|
return self.language.languageCode?.identifier
|
|
} else {
|
|
return self.languageCode
|
|
}
|
|
#else
|
|
return self.languageCode
|
|
#endif
|
|
}
|
|
// swiftlint:enable identifier_name
|
|
|
|
/// - Returns: the same locale as `self` but removing its region.
|
|
var removingRegion: Self? {
|
|
return self.rc_languageCode.map(Locale.init(identifier:))
|
|
}
|
|
|
|
}
|