aboutsummaryrefslogtreecommitdiffstats
path: root/Source/DMLocalizedNibBundle.m
diff options
context:
space:
mode:
Diffstat (limited to 'Source/DMLocalizedNibBundle.m')
-rw-r--r--Source/DMLocalizedNibBundle.m51
1 files changed, 45 insertions, 6 deletions
diff --git a/Source/DMLocalizedNibBundle.m b/Source/DMLocalizedNibBundle.m
index 2c25cea4..90fc4264 100644
--- a/Source/DMLocalizedNibBundle.m
+++ b/Source/DMLocalizedNibBundle.m
@@ -10,8 +10,17 @@
#import <Cocoa/Cocoa.h>
#import <objc/runtime.h>
+#import <Availability.h>
+
+//Backwards compatibility
+#ifndef __MAC_10_8
+#define __MAC_10_8 1080
+#endif
@interface NSBundle (DMLocalizedNibBundle)
+#if __MAC_OS_X_VERSION_MAX_ALLOWED >= __MAC_10_8
+- (BOOL)deliciousLocalizingLoadNibNamed:(NSString *)fileName owner:(id)owner topLevelObjects:(NSArray **)topLevelObjects;
+#endif
+ (BOOL)deliciousLocalizingLoadNibFile:(NSString *)fileName externalNameTable:(NSDictionary *)context withZone:(NSZone *)zone;
@end
@@ -33,11 +42,19 @@ static NSMutableArray *deliciousBindingKeys = nil;
#pragma mark NSObject
-+ (void)load;
++ (void)load
{
NSAutoreleasePool *autoreleasePool = [[NSAutoreleasePool alloc] init];
if (self == [NSBundle class]) {
- method_exchangeImplementations(class_getClassMethod(self, @selector(loadNibFile:externalNameTable:withZone:)), class_getClassMethod(self, @selector(deliciousLocalizingLoadNibFile:externalNameTable:withZone:)));
+ Method oldM,newM;
+#if __MAC_OS_X_VERSION_MAX_ALLOWED >= __MAC_10_8
+ oldM = class_getInstanceMethod(self, @selector(loadNibNamed:owner:topLevelObjects:));
+ newM = class_getInstanceMethod(self, @selector(deliciousLocalizingLoadNibNamed:owner:topLevelObjects:));
+ method_exchangeImplementations(oldM, newM);
+#endif
+ oldM = class_getClassMethod(self, @selector(loadNibFile:externalNameTable:withZone:));
+ newM = class_getClassMethod(self, @selector(deliciousLocalizingLoadNibFile:externalNameTable:withZone:));
+ method_exchangeImplementations(oldM, newM);
deliciousBindingKeys = [[NSMutableArray alloc] initWithObjects:
NSMultipleValuesPlaceholderBindingOption,
NSNoSelectionPlaceholderBindingOption,
@@ -50,7 +67,29 @@ static NSMutableArray *deliciousBindingKeys = nil;
#pragma mark API
-+ (BOOL)deliciousLocalizingLoadNibFile:(NSString *)fileName externalNameTable:(NSDictionary *)context withZone:(NSZone *)zone;
+#if __MAC_OS_X_VERSION_MAX_ALLOWED >= __MAC_10_8
+- (BOOL)deliciousLocalizingLoadNibNamed:(NSString *)fileName owner:(id)owner topLevelObjects:(NSArray **)topLevelObjects
+{
+ fileName = [self pathForResource:fileName ofType:@"nib"];
+ NSString *localizedStringsTableName = [[fileName lastPathComponent] stringByDeletingPathExtension];
+ NSString *localizedStringsTablePath = [[NSBundle mainBundle] pathForResource:localizedStringsTableName ofType:@"strings"];
+ if (localizedStringsTablePath && ![[[localizedStringsTablePath stringByDeletingLastPathComponent] lastPathComponent] isEqualToString:@"English.lproj"]) {
+
+ NSNib *nib = [[NSNib alloc] initWithContentsOfURL:[NSURL fileURLWithPath:fileName]];
+ BOOL success = [nib instantiateWithOwner:owner topLevelObjects:topLevelObjects];
+ NSMutableArray *topLevelObjectsArray = [NSMutableArray arrayWithArray:*topLevelObjects];
+ [[self class] _localizeStringsInObject:topLevelObjectsArray table:localizedStringsTableName];
+
+ [nib release];
+ return success;
+
+ } else {
+ return [self deliciousLocalizingLoadNibNamed:localizedStringsTableName owner:owner topLevelObjects:topLevelObjects];
+ }
+}
+#endif
+
++ (BOOL)deliciousLocalizingLoadNibFile:(NSString *)fileName externalNameTable:(NSDictionary *)context withZone:(NSZone *)zone
{
NSString *localizedStringsTableName = [[fileName lastPathComponent] stringByDeletingPathExtension];
NSString *localizedStringsTablePath = [[NSBundle mainBundle] pathForResource:localizedStringsTableName ofType:@"strings"];
@@ -80,7 +119,7 @@ static NSMutableArray *deliciousBindingKeys = nil;
@implementation NSBundle (DMLocalizedNibBundle_Private_API)
-+ (void)_localizeStringsInObject:(id)object table:(NSString *)table;
++ (void)_localizeStringsInObject:(id)object table:(NSString *)table
{
if ([object isKindOfClass:[NSArray class]]) {
NSArray *array = object;
@@ -167,7 +206,7 @@ static NSMutableArray *deliciousBindingKeys = nil;
} else if ([view isKindOfClass:[NSSegmentedControl class]]) {
NSSegmentedControl *segmentedControl = (NSSegmentedControl *)control;
- NSUInteger segmentIndex, segmentCount = [segmentedControl segmentCount];
+ NSInteger segmentIndex, segmentCount = [segmentedControl segmentCount];
for (segmentIndex = 0; segmentIndex < segmentCount; segmentIndex++) {
NSString *localizedSegmentLabel = [self _localizedStringForString:[segmentedControl labelForSegment:segmentIndex] table:table];
if (localizedSegmentLabel)
@@ -225,7 +264,7 @@ static NSMutableArray *deliciousBindingKeys = nil;
}
}
-+ (NSString *)_localizedStringForString:(NSString *)string table:(NSString *)table;
++ (NSString *)_localizedStringForString:(NSString *)string table:(NSString *)table
{
if (![string length])
return nil;