From e83732400bde19b8707ffbee7a858ff1c6aaf87b Mon Sep 17 00:00:00 2001 From: Tomáš Znamenáček Date: Wed, 4 Nov 2015 14:59:32 +0100 Subject: Trying a fix for the CocoaPods localization bundle problem (#74). This change simply doesn’t try to detect which bundle we should use and tries both bundles, the CocoaPods one first. The chosen bundle is then cached to avoid the overhead on subsequent requests. --- Framework/MASLocalization.m | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/Framework/MASLocalization.m b/Framework/MASLocalization.m index 9561470..d5f0c8a 100644 --- a/Framework/MASLocalization.m +++ b/Framework/MASLocalization.m @@ -6,12 +6,13 @@ // and the Localized.strings file won’t be bundled correctly. // See https://github.com/shpakovski/MASShortcut/issues/74 NSString *MASLocalizedString(NSString *key, NSString *comment) { - NSBundle *frameworkBundle = nil; -#ifdef COCOAPODS - NSURL *bundleURL = [[NSBundle mainBundle] URLForResource:@"MASShortcut" withExtension:@"bundle"]; - frameworkBundle = [NSBundle bundleWithURL:bundleURL]; -#else - frameworkBundle = [NSBundle bundleForClass:[MASShortcut class]]; -#endif - return [frameworkBundle localizedStringForKey:key value:@"XXX" table:@"Localizable"]; + static NSBundle *localizationBundle = nil; + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + NSURL *cocoaPodsBundleURL = [[NSBundle mainBundle] URLForResource:@"MASShortcut" withExtension:@"bundle"]; + localizationBundle = cocoaPodsBundleURL ? + [NSBundle bundleWithURL:cocoaPodsBundleURL] : + [NSBundle bundleForClass:[MASShortcut class]]; + }); + return [localizationBundle localizedStringForKey:key value:@"XXX" table:@"Localizable"]; } -- cgit v1.2.3