diff options
| author | Nikita Ivanchikov | 2015-11-20 19:16:39 +0200 |
|---|---|---|
| committer | Tomáš Znamenáček | 2016-01-09 15:43:05 +0100 |
| commit | d32fc188ca8132ce75670b7e000a040599117673 (patch) | |
| tree | b06c1598826397f64ed6056010cfd7af5a205e16 /Framework/MASLocalization.m | |
| parent | 2b2fb80556369e7495d87e88de7d8671af3467b5 (diff) | |
| download | MASShortcut-d32fc188ca8132ce75670b7e000a040599117673.tar.bz2 | |
Another approach to try a fix for the CocoaPods localization bundle problem (#74).
Checking if resources bundle was copied inside framework bundle, then falling back to old search methods
Diffstat (limited to 'Framework/MASLocalization.m')
| -rw-r--r-- | Framework/MASLocalization.m | 33 |
1 files changed, 14 insertions, 19 deletions
diff --git a/Framework/MASLocalization.m b/Framework/MASLocalization.m index e0627db..70434ea 100644 --- a/Framework/MASLocalization.m +++ b/Framework/MASLocalization.m @@ -13,25 +13,20 @@ NSString *MASLocalizedString(NSString *key, NSString *comment) { static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ NSBundle *frameworkBundle = [NSBundle bundleForClass:[MASShortcut class]]; - NSURL *cocoaPodsBundleURL = [[NSBundle mainBundle] URLForResource:@"MASShortcut" withExtension:@"bundle"]; - 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; - } + // first we'll check if resources bundle was copied to MASShortcut framework bundle when !use_frameworks option is active + NSURL *cocoaPodsBundleURL = [frameworkBundle URLForResource:@"MASShortcut" withExtension:@"bundle"]; + if (cocoaPodsBundleURL) { + localizationBundle = [NSBundle bundleWithURL: cocoaPodsBundleURL]; + } else { + // trying to fetch cocoapods bundle from main bundle + cocoaPodsBundleURL = [[NSBundle mainBundle] URLForResource: @"MASShortcut" withExtension:@"bundle"]; + if (cocoaPodsBundleURL) { + localizationBundle = [NSBundle bundleWithURL: cocoaPodsBundleURL]; + } else { + // fallback to framework bundle + localizationBundle = frameworkBundle; + } + } }); return [localizationBundle localizedStringForKey:key value:MASPlaceholderLocalizationString |
