-
Notifications
You must be signed in to change notification settings - Fork 332
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Depends on #3002. This is the new logic for finding the locale to use ```swift var localizedConfiguration: LocalizedConfiguration { let locales: [Locale] = [.current] + Locale.preferredLocales return locales .lazy .compactMap(self.config(for:)) .first ?? self.fallbackLocalizedConfiguration } ``` And note that `config(for:)` is a fuzzy-lookup (#2847).
- Loading branch information
Showing
12 changed files
with
63 additions
and
69 deletions.
There are no files selected for viewing
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
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
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,48 @@ | ||
// | ||
// 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 | ||
// | ||
// PaywallData+Localization.swift | ||
// | ||
// Created by Nacho Soto on 8/10/23. | ||
|
||
import Foundation | ||
|
||
public extension PaywallData { | ||
|
||
/// - Returns: the ``PaywallData/LocalizedConfiguration-swift.struct`` to be used | ||
/// based on `Locale.current` or `Locale.preferredLocales`. | ||
var localizedConfiguration: LocalizedConfiguration { | ||
let locales: [Locale] = [.current] + Locale.preferredLocales | ||
|
||
return locales | ||
.lazy | ||
.compactMap(self.config(for:)) | ||
.first ?? self.fallbackLocalizedConfiguration | ||
} | ||
|
||
private var fallbackLocalizedConfiguration: LocalizedConfiguration { | ||
// This can't happen because `localization` has `@EnsureNonEmptyCollectionDecodable`. | ||
guard let result = self.localization.first?.value else { | ||
fatalError("Corrupted data: localization is empty.") | ||
} | ||
|
||
return result | ||
} | ||
|
||
} | ||
|
||
// MARK: - | ||
|
||
private extension Locale { | ||
|
||
static var preferredLocales: [Self] { | ||
return Self.preferredLanguages.map(Locale.init(identifier:)) | ||
} | ||
|
||
} |
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
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
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
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
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
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
12 changes: 1 addition & 11 deletions
12
...a-missing_current_and_default_locale.json → ...res/PaywallData-missing_localization.json
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
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
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