SPB Git

Repository Public

Localization.swift 1.4 KB 26 lines swift

1import Foundation23/// String lookup shared by the targets of the feature (each target has its own catalog: English keys, fr-CA translations).4public enum AnalysisLocalization {5    /// Development override: `ORIX_ANALYSIS_LANG=fr-CA` forces a language in the previews and tests. A bare executable6    /// has no localized main bundle, so the system would otherwise always pick the development language there.7    public static let override: String? = ProcessInfo.processInfo.environment["ORIX_ANALYSIS_LANG"]89    public static func string(_ key: String, bundle: Bundle) -> String {10        if let override, let b = localized(bundle, override) { return b.localizedString(forKey: key, value: key, table: nil) }11        return NSLocalizedString(key, bundle: bundle, comment: "")12    }1314    /// The `.lproj` sub-bundle of a language (nil when the catalog has no such localization).15    public static func localized(_ bundle: Bundle, _ language: String) -> Bundle? {16        bundle.path(forResource: language, ofType: "lproj").flatMap { Bundle(path: $0) }17    }18}1920/// Localized string from the AnalysisKit catalog.21func L(_ key: String) -> String { AnalysisLocalization.string(key, bundle: .module) }22func L(_ key: String, _ args: CVarArg...) -> String { String(format: AnalysisLocalization.string(key, bundle: .module), arguments: args) }2324/// The resource bundle of AnalysisKit (for tests).25public let kitBundle = Bundle.module26
Files main
Menu

Theme