aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomáš Znamenáček2015-11-06 08:59:52 +0100
committerTomáš Znamenáček2015-11-06 08:59:52 +0100
commit5a18ccc5e100a43d98ccaf4bdf0ad4f8e49bc76f (patch)
tree006eec02cf01644969420d4437a7e6dd1ac2d2af
parente83732400bde19b8707ffbee7a858ff1c6aaf87b (diff)
downloadMASShortcut-5a18ccc5e100a43d98ccaf4bdf0ad4f8e49bc76f.tar.bz2
Even more elaborate workaround for the CocoaPods localization problem (#74).
Just testing if the CocoaPods bundle is present didn’t work, so now we even try to load a localized string from the bundle.
-rw-r--r--Framework/MASLocalization.m29
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];
}