mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 06:55:59 +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
|
import Foundation
|
||||||
|
|
||||||
public extension Bundle {
|
public extension Bundle {
|
||||||
|
private static var cachedLocalizationBundles = [String: Bundle]()
|
||||||
|
|
||||||
/// Get an lproj language bundle from the receiver bundle.
|
/// Get an lproj language bundle from the receiver bundle.
|
||||||
/// - Parameter language: The language to try to load.
|
/// - Parameter language: The language to try to load.
|
||||||
/// - Returns: The lproj bundle if found otherwise nil.
|
/// - Returns: The lproj bundle if found otherwise nil.
|
||||||
func lprojBundle(for language: String) -> Bundle? {
|
func lprojBundle(for language: String) -> Bundle? {
|
||||||
guard let lprojURL = url(forResource: language, withExtension: "lproj") else { return nil }
|
if let bundle = Self.cachedLocalizationBundles[language] {
|
||||||
return Bundle(url: lprojURL)
|
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:
|
/// Preferred app language for translations. Takes the highest priority in translations. The priority list for translations:
|
||||||
|
|||||||
Reference in New Issue
Block a user