2026-07-09 23:00:55 +00:00
import Foundation
/// A backend that resolves localized strings for an explicit locale and reports the languages it serves.
///
2026-07-30 06:33:57 +00:00
/// This is the seam that decouples ``Localize`` and ``LanguageList`` from *how* localizations are stored and resolved. The shipping implementation,
/// ``StringCatalog``, reads a raw `.xcstrings` catalog so it behaves identically on Darwin and Linux. A future backend — for example one built on
/// `String(localized:)` for a native Apple app that needs plural and device variations — can conform without changing any caller.
2026-07-09 23:00:55 +00:00
///
2026-07-30 06:33:57 +00:00
/// Resolution never fails: an implementation returns the key itself when it has no localization for it, mirroring Foundation's `String(localized:)`.
/// This is the contract both a dictionary lookup and the native API can honour, since the native API cannot distinguish a missing key from a translation that
2026-07-09 23:00:55 +00:00
/// happens to equal the key.
protocol CatalogResolving : Sendable {
// MARK: Properties
2026-07-30 06:33:57 +00:00
/// The source (development) language, used as the final fallback when a locale has no localization and as the default language a ``LanguageList``
/// serves.
2026-07-09 23:00:55 +00:00
var sourceLanguage : String { get }
2026-07-28 23:37:33 +00:00
/// The outcome of reading the backing catalog, for consumers to surface at startup.
var state : CatalogState { get }
2026-07-09 23:00:55 +00:00
/// Every language the backend can resolve strings for, including the source language.
var languages : Set < String > { get }
// MARK: Methods
/// Resolves a catalog key in the given locale.
/// - Parameters:
/// - key: the catalog key to look up.
/// - locale: the locale to resolve the key in.
/// - Returns: the localized string, falling back to the source language, then to the key itself.
func string (
for key : String ,
in locale : Locale
) -> String
}