Created
September 6, 2023 00:55
-
-
Save hdmdhr/445b4fb01a370c511b817858b92cdde7 to your computer and use it in GitHub Desktop.
Find bundle for a given language code, aka a String
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
import Foundation | |
typealias LanguageCode = String | |
extension LanguageCode { | |
var bundle: Bundle { | |
let path = Bundle.main.path(forResource: self, ofType: "lproj") ?? | |
Bundle.main.path(forResource: "Base", ofType: "lproj") | |
return path.map { Bundle(path: $0) ?? .main } ?? .main | |
} | |
} | |
extension Optional where Wrapped == LanguageCode { | |
var bundle: Bundle { (self ?? "Base").bundle } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment