diff options
Diffstat (limited to 'Framework')
| -rw-r--r-- | Framework/MASLocalization.m | 29 | 
1 files changed, 25 insertions, 4 deletions
| diff --git a/Framework/MASLocalization.m b/Framework/MASLocalization.m index d5f0c8a..e0627db 100644 --- a/Framework/MASLocalization.m +++ b/Framework/MASLocalization.m @@ -1,6 +1,9 @@  #import "MASLocalization.h"  #import "MASShortcut.h" +static NSString *const MASLocalizationTableName = @"Localizable"; +static NSString *const MASPlaceholderLocalizationString = @"XXX"; +  // The CocoaPods trickery here is needed because when the code  // is built as a part of CocoaPods, it won’t make a separate framework  // and the Localized.strings file won’t be bundled correctly. @@ -9,10 +12,28 @@ NSString *MASLocalizedString(NSString *key, NSString *comment) {      static NSBundle *localizationBundle = nil;      static dispatch_once_t onceToken;      dispatch_once(&onceToken, ^{ +        NSBundle *frameworkBundle = [NSBundle bundleForClass:[MASShortcut class]];          NSURL *cocoaPodsBundleURL = [[NSBundle mainBundle] URLForResource:@"MASShortcut" withExtension:@"bundle"]; -        localizationBundle = cocoaPodsBundleURL ? -            [NSBundle bundleWithURL:cocoaPodsBundleURL] : -            [NSBundle bundleForClass:[MASShortcut class]]; +        if (cocoaPodsBundleURL) { +            NSBundle *cocoaPodsBundle = [NSBundle bundleWithURL:cocoaPodsBundleURL]; +            NSString *testingString = [cocoaPodsBundle +                localizedStringForKey:@"Cancel" +                value:MASPlaceholderLocalizationString +                table:MASLocalizationTableName]; +            if (![testingString isEqualToString:MASPlaceholderLocalizationString]) { +                // We have a CocoaPods bundle and it works, use it. +                localizationBundle = cocoaPodsBundle; +            } else { +                // We have a CocoaPods bundle, but it doesn’t contain +                // the localization files. Let’s use the framework bundle instead. +                localizationBundle = frameworkBundle; +            } +        } else { +            // CocoaPods bundle not present, use the framework bundle. +            localizationBundle = frameworkBundle; +        }      }); -    return [localizationBundle localizedStringForKey:key value:@"XXX" table:@"Localizable"]; +    return [localizationBundle localizedStringForKey:key +        value:MASPlaceholderLocalizationString +        table:MASLocalizationTableName];  } | 
