mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-02 12:07:55 +00:00
Cache lproj bundles so that so we stop recreating them every time we request a localizable string
This commit is contained in:
committed by
Stefan Ceriu
parent
a9c24abcdf
commit
9cc876eb0c
@@ -17,12 +17,24 @@
|
||||
import Foundation
|
||||
|
||||
public extension Bundle {
|
||||
private static var cachedLocalizationBundles = [String: Bundle]()
|
||||
|
||||
/// Get an lproj language bundle from the receiver bundle.
|
||||
/// - Parameter language: The language to try to load.
|
||||
/// - Returns: The lproj bundle if found otherwise nil.
|
||||
func lprojBundle(for language: String) -> Bundle? {
|
||||
guard let lprojURL = url(forResource: language, withExtension: "lproj") else { return nil }
|
||||
return Bundle(url: lprojURL)
|
||||
if let bundle = Self.cachedLocalizationBundles[language] {
|
||||
return bundle
|
||||
}
|
||||
|
||||
guard let lprojURL = url(forResource: language, withExtension: "lproj") else {
|
||||
return nil
|
||||
}
|
||||
|
||||
let bundle = Bundle(url: lprojURL)
|
||||
Self.cachedLocalizationBundles[language] = bundle
|
||||
|
||||
return bundle
|
||||
}
|
||||
|
||||
/// Preferred app language for translations. Takes the highest priority in translations. The priority list for translations:
|
||||
|
||||
Reference in New Issue
Block a user