summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorthomasvl@chromium.org <thomasvl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-22 16:47:54 +0000
committerthomasvl@chromium.org <thomasvl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-22 16:47:54 +0000
commit3466f7dc1725b6275933164b4807c7caecd58106 (patch)
tree83492292a92959d38bbf7b965451cc559516f4b8
parentd73053211c5db825ad997b7900e69b2dd05f8b0c (diff)
downloadchromium_src-3466f7dc1725b6275933164b4807c7caecd58106.zip
chromium_src-3466f7dc1725b6275933164b4807c7caecd58106.tar.gz
chromium_src-3466f7dc1725b6275933164b4807c7caecd58106.tar.bz2
Add a custom subclass of GTMUILocalizer that skips the bundle work so we can directly use these from nib files without some extra overhead.
Updated the generator to make things based off this subclass. TEST=none BUG=16764 Review URL: http://codereview.chromium.org/159197 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@21280 0039d316-1c4b-4281-b951-d872f2087c98
-rwxr-xr-xbuild/mac/generate_localizer8
-rw-r--r--chrome/browser/cocoa/ui_localizer.h23
-rw-r--r--chrome/browser/cocoa/ui_localizer.mm30
3 files changed, 56 insertions, 5 deletions
diff --git a/build/mac/generate_localizer b/build/mac/generate_localizer
index 4620b99..28f7658 100755
--- a/build/mac/generate_localizer
+++ b/build/mac/generate_localizer
@@ -27,13 +27,12 @@ localizer_template_h = \
#ifndef %(class_name)s_LOCALIZER_H_
#define %(class_name)s_LOCALIZER_H_
-#import "third_party/GTM/AppKit/GTMUILocalizer.h"
+#import "chrome/browser/cocoa/ui_localizer.h"
-// A subclass of GTMUILocalizer that handles localizes based on resource
+// A subclass of ChromeUILocalizer that handles localization based on resource
// constants.
-@interface %(class_name)sLocalizer : GTMUILocalizer {
-}
+@interface %(class_name)sLocalizer : ChromeUILocalizer
@end
#endif // %(class_name)s_LOCALIZER_H_
@@ -49,7 +48,6 @@ localizer_template_mm = \
#import "%(header_name)s"
-#import "chrome/browser/cocoa/ui_localizer.h"
#include "grit/chromium_strings.h"
#include "grit/generated_resources.h"
diff --git a/chrome/browser/cocoa/ui_localizer.h b/chrome/browser/cocoa/ui_localizer.h
index b4702ad..36efc59 100644
--- a/chrome/browser/cocoa/ui_localizer.h
+++ b/chrome/browser/cocoa/ui_localizer.h
@@ -7,6 +7,7 @@
#include "base/basictypes.h"
#include "base/string16.h"
+#import "third_party/GTM/AppKit/GTMUILocalizer.h"
@class NSString;
@@ -28,4 +29,26 @@ NSString* LocalizedStringForKeyFromMapList(NSString* key,
} // namespace ui_localizer
+// A base class for generated localizers.
+//
+// To use this, have the build run generate_localizer on your xib file (see
+// chrome.gyp). Then add an instance of the generated subclass to the xib.
+// Connect the owner_ outlet of the instance to the "File's Owner" of the xib.
+// It expects the owner_ outlet to be an instance or subclass of
+// NSWindowController or NSViewController. It will then localize any items in
+// the NSWindowController's window and subviews, or the NSViewController's view
+// and subviews, when awakeFromNib is called on the instance. You can
+// optionally hook up otherObjectToLocalize_ and yetAnotherObjectToLocalize_ and
+// those will also be localized. Strings in the xib that you want localized must
+// start with ^IDS. The value must be a valid resource constant.
+// Things that will be localized are:
+// - Titles and altTitles (for menus, buttons, windows, menuitems, -tabViewItem)
+// - -stringValue (for labels)
+// - tooltips
+// - accessibility help
+// - accessibility descriptions
+// - menus
+@interface ChromeUILocalizer : GTMUILocalizer
+@end
+
#endif // CHROME_BROWSER_COCOA_UI_LOCALIZER_H_
diff --git a/chrome/browser/cocoa/ui_localizer.mm b/chrome/browser/cocoa/ui_localizer.mm
index e9be6dc..5467203 100644
--- a/chrome/browser/cocoa/ui_localizer.mm
+++ b/chrome/browser/cocoa/ui_localizer.mm
@@ -78,3 +78,33 @@ NSString* LocalizedStringForKeyFromMapList(NSString* key,
}
} // namespace ui_localizer
+
+@interface GTMUILocalizer (PrivateAdditions)
+- (void)localizedObjects;
+@end
+
+@implementation GTMUILocalizer (PrivateAdditions)
+- (void)localizedObjects {
+ // The ivars are private, so this method lets us trigger the localization
+ // from -[ChromeUILocalizer awakeFromNib].
+ [self localizeObject:owner_ recursively:YES];
+ [self localizeObject:otherObjectToLocalize_ recursively:YES];
+ [self localizeObject:yetAnotherObjectToLocalize_ recursively:YES];
+}
+ @end
+
+@implementation ChromeUILocalizer
+- (void)awakeFromNib {
+ // The GTM base is bundle based, since don't need the bundle, use this
+ // override to bypass the bundle lookup and directly do the localization
+ // calls.
+ [self localizedObjects];
+}
+#ifndef NDEBUG
+// Catch anyone that uses this directly.
+- (NSString *)localizedStringForString:(NSString *)string {
+ LOG(FATAL) << "Don't use ChromeUILocalizer directly.";
+ return @"Don't use ChromeUILocalizer directly.";
+}
+#endif
+@end