diff options
| author | Tomáš Znamenáček | 2015-11-04 14:59:32 +0100 |
|---|---|---|
| committer | Tomáš Znamenáček | 2015-11-04 15:02:55 +0100 |
| commit | e83732400bde19b8707ffbee7a858ff1c6aaf87b (patch) | |
| tree | 6f7e35294a233dcf702ea19c716545902d8b4436 /Framework | |
| parent | 273068384885bed12616acff8e5ed15400d3973f (diff) | |
| download | MASShortcut-e83732400bde19b8707ffbee7a858ff1c6aaf87b.tar.bz2 | |
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.
Diffstat (limited to 'Framework')
| -rw-r--r-- | Framework/MASLocalization.m | 17 |
1 files 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"]; } |
