Revision: 6509
http://skim-app.svn.sourceforge.net/skim-app/?rev=6509&view=rev
Author: hofman
Date: 2010-04-30 17:31:32 +0000 (Fri, 30 Apr 2010)
Log Message:
-----------
use macros with actual properties rather than KVC for localizing properties so
we get compiler checking to see whether properties exist
Modified Paths:
--------------
trunk/SKLocalization.m
Modified: trunk/SKLocalization.m
===================================================================
--- trunk/SKLocalization.m 2010-04-30 17:00:41 UTC (rev 6508)
+++ trunk/SKLocalization.m 2010-04-30 17:31:32 UTC (rev 6509)
@@ -38,13 +38,6 @@
#import "SKLocalization.h"
-#define TITLE_KEY @"title"
-#define ALTERNATETITLE_KEY @"alternateTitle"
-#define STRINGVALUE_KEY @"stringValue"
-#define PLACEHOLDERSTRING_KEY @"placeholderString"
-#define LABEL_KEY @"label"
-#define TOOLTIP_KEY @"toolTip"
-
static NSString *localizedStringFromTable(NSString *string, NSString *table) {
if ([string length] == 0)
return nil;
@@ -52,12 +45,19 @@
return [[NSBundle mainBundle] localizedStringForKey:string value:string
table:table];
}
-static void localizeStringForObjectFromTable(id object, NSString *key,
NSString *table) {
- NSString *value = localizedStringFromTable([object valueForKey:key],
table);
- if (value)
- [object setValue:value forKey:key];
-}
+#define LOCALIZE_STRING_FOR_OBJECT_FROM_TABLE(object, table, property) \
+do { \
+ NSString *value = localizedStringFromTable(object.property, table); \
+ if (value) object.property = value; \
+} while (0)
+#define localizeTitleForObjectFromTable(object, table)
LOCALIZE_STRING_FOR_OBJECT_FROM_TABLE(object, table, title)
+#define localizeAlternateTitleForObjectFromTable(object, table)
LOCALIZE_STRING_FOR_OBJECT_FROM_TABLE(object, table, alternateTitle)
+#define localizeStringValueForObjectFromTable(object, table)
LOCALIZE_STRING_FOR_OBJECT_FROM_TABLE(object, table, stringValue)
+#define localizePlaceholderStringForObjectFromTable(object, table)
LOCALIZE_STRING_FOR_OBJECT_FROM_TABLE(object, table, placeholderString)
+#define localizeLabelForObjectFromTable(object, table)
LOCALIZE_STRING_FOR_OBJECT_FROM_TABLE(object, table, label)
+#define localizeToolTipForObjectFromTable(object, table)
LOCALIZE_STRING_FOR_OBJECT_FROM_TABLE(object, table, toolTip)
+
@implementation NSObject (SKLocalization)
- (void)localizeStringsFromTable:(NSString *)table {}
@@ -79,8 +79,8 @@
- (void)localizeStringsFromTable:(NSString *)table {
[super localizeStringsFromTable:table];
if ([self imagePosition] != NSImageOnly && [self
isKindOfClass:[NSPopUpButtonCell class]] == NO) {
- localizeStringForObjectFromTable(self, TITLE_KEY, table);
- localizeStringForObjectFromTable(self, ALTERNATETITLE_KEY, table);
+ localizeTitleForObjectFromTable(self, table);
+ localizeAlternateTitleForObjectFromTable(self, table);
}
}
@@ -119,8 +119,8 @@
- (void)localizeStringsFromTable:(NSString *)table {
[super localizeStringsFromTable:table];
- localizeStringForObjectFromTable(self, STRINGVALUE_KEY, table);
- localizeStringForObjectFromTable(self, PLACEHOLDERSTRING_KEY, table);
+ localizeStringValueForObjectFromTable(self, table);
+ localizePlaceholderStringForObjectFromTable(self, table);
}
@end
@@ -129,7 +129,7 @@
@implementation NSView (SKLocalization)
- (void)localizeStringsFromTable:(NSString *)table {
- localizeStringForObjectFromTable(self, TOOLTIP_KEY, table);
+ localizeToolTipForObjectFromTable(self, table);
[[self subviews] localizeStringsFromTable:table];
}
@@ -140,7 +140,7 @@
- (void)localizeStringsFromTable:(NSString *)table {
[super localizeStringsFromTable:table];
- localizeStringForObjectFromTable(self, TITLE_KEY, table);
+ localizeTitleForObjectFromTable(self, table);
}
@end
@@ -185,7 +185,7 @@
@implementation NSTabViewItem (SKLocalization)
- (void)localizeStringsFromTable:(NSString *)table {
- localizeStringForObjectFromTable(self, LABEL_KEY, table);
+ localizeLabelForObjectFromTable(self, table);
[[self view] localizeStringsFromTable:table];
}
@@ -216,7 +216,7 @@
@implementation NSMenu (SKLocalization)
- (void)localizeStringsFromTable:(NSString *)table {
- localizeStringForObjectFromTable(self, TITLE_KEY, table);
+ localizeTitleForObjectFromTable(self, table);
[[self itemArray] localizeStringsFromTable:table];
}
@@ -226,7 +226,7 @@
@implementation NSMenuItem (SKLocalization)
- (void)localizeStringsFromTable:(NSString *)table {
- localizeStringForObjectFromTable(self, TITLE_KEY, table);
+ localizeTitleForObjectFromTable(self, table);
[[self submenu] localizeStringsFromTable:table];
}
@@ -236,7 +236,7 @@
@implementation NSWindow (SKLocalization)
- (void)localizeStringsFromTable:(NSString *)table {
- localizeStringForObjectFromTable(self, TITLE_KEY, table);
+ localizeTitleForObjectFromTable(self, table);
[[self contentView] localizeStringsFromTable:table];
}
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit