summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
Diffstat (limited to 'chrome')
-rw-r--r--chrome/app/nibs/BookmarkBar.xib18
-rw-r--r--chrome/app/nibs/BookmarkEditor.xib10
-rw-r--r--chrome/app/nibs/BookmarkNameFolder.xib14
-rw-r--r--chrome/app/nibs/TabView.xib10
-rw-r--r--chrome/app/nibs/Toolbar.xib37
-rw-r--r--chrome/browser/app_controller_mac.mm6
-rw-r--r--chrome/browser/cocoa/ui_localizer.h20
-rw-r--r--chrome/browser/cocoa/ui_localizer.mm98
-rw-r--r--chrome/chrome.gyp97
9 files changed, 127 insertions, 183 deletions
diff --git a/chrome/app/nibs/BookmarkBar.xib b/chrome/app/nibs/BookmarkBar.xib
index b8da664..2dc0c3d 100644
--- a/chrome/app/nibs/BookmarkBar.xib
+++ b/chrome/app/nibs/BookmarkBar.xib
@@ -8,9 +8,9 @@
<string key="IBDocument.HIToolboxVersion">353.00</string>
<object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
<bool key="EncodedWithXMLCoder">YES</bool>
+ <integer value="1"/>
<integer value="18"/>
<integer value="4"/>
- <integer value="1"/>
</object>
<object class="NSArray" key="IBDocument.PluginDependencies">
<bool key="EncodedWithXMLCoder">YES</bool>
@@ -303,7 +303,7 @@
</object>
</object>
<object class="NSCustomObject" id="849863465">
- <string key="NSClassName">BookmarkBarLocalizer</string>
+ <string key="NSClassName">ChromeUILocalizer</string>
</object>
</object>
<object class="IBObjectContainer" key="IBDocument.Objects">
@@ -901,15 +901,17 @@
<bool key="EncodedWithXMLCoder">YES</bool>
<string>buttonContextMenu_</string>
<string>buttonView_</string>
- <string>delegate_</string>
<string>offTheSideButton_</string>
+ <string>resizeDelegate_</string>
+ <string>urlDelegate_</string>
</object>
<object class="NSMutableArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>NSMenu</string>
<string>NSView</string>
- <string>id</string>
<string>NSButton</string>
+ <string>id</string>
+ <string>id</string>
</object>
</object>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
@@ -918,14 +920,6 @@
</object>
</object>
<object class="IBPartialClassDescription">
- <string key="className">BookmarkBarLocalizer</string>
- <string key="superclassName">ChromeUILocalizer</string>
- <object class="IBClassDescriptionSource" key="sourceIdentifier">
- <string key="majorKey">IBProjectSource</string>
- <string key="minorKey">../xcodebuild/chrome.build/DerivedSources/Debug/xib_localizers/bookmark_bar_localizer.h</string>
- </object>
- </object>
- <object class="IBPartialClassDescription">
<string key="className">ChromeUILocalizer</string>
<string key="superclassName">GTMUILocalizer</string>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
diff --git a/chrome/app/nibs/BookmarkEditor.xib b/chrome/app/nibs/BookmarkEditor.xib
index 0d03abc..85d005e 100644
--- a/chrome/app/nibs/BookmarkEditor.xib
+++ b/chrome/app/nibs/BookmarkEditor.xib
@@ -301,7 +301,7 @@
<string key="NSMaxSize">{3.40282e+38, 3.40282e+38}</string>
</object>
<object class="NSCustomObject" id="764065517">
- <string key="NSClassName">BookmarkEditorLocalizer</string>
+ <string key="NSClassName">ChromeUILocalizer</string>
</object>
<object class="NSCustomObject" id="12470901">
<string key="NSClassName">GTMUILocalizerAndLayoutTweaker</string>
@@ -764,14 +764,6 @@
</object>
</object>
<object class="IBPartialClassDescription">
- <string key="className">BookmarkEditorLocalizer</string>
- <string key="superclassName">ChromeUILocalizer</string>
- <object class="IBClassDescriptionSource" key="sourceIdentifier">
- <string key="majorKey">IBProjectSource</string>
- <string key="minorKey">../xcodebuild/chrome.build/DerivedSources/Debug/xib_localizers/bookmark_editor_localizer.h</string>
- </object>
- </object>
- <object class="IBPartialClassDescription">
<string key="className">ChromeUILocalizer</string>
<string key="superclassName">GTMUILocalizer</string>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
diff --git a/chrome/app/nibs/BookmarkNameFolder.xib b/chrome/app/nibs/BookmarkNameFolder.xib
index 82b8da5..7271553 100644
--- a/chrome/app/nibs/BookmarkNameFolder.xib
+++ b/chrome/app/nibs/BookmarkNameFolder.xib
@@ -162,7 +162,7 @@
<string key="NSMaxSize">{3.40282e+38, 3.40282e+38}</string>
</object>
<object class="NSCustomObject" id="352865609">
- <string key="NSClassName">BookmarkNameFolderLocalizer</string>
+ <string key="NSClassName">ChromeUILocalizer</string>
</object>
</object>
<object class="IBObjectContainer" key="IBDocument.Objects">
@@ -352,9 +352,9 @@
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
- <string>{{816, 841}, {480, 102}}</string>
+ <string>{{688, 841}, {480, 102}}</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
- <string>{{816, 841}, {480, 102}}</string>
+ <string>{{688, 841}, {480, 102}}</string>
<boolean value="NO"/>
<string>{196, 240}</string>
<string>{{357, 418}, {480, 270}}</string>
@@ -421,14 +421,6 @@
</object>
</object>
<object class="IBPartialClassDescription">
- <string key="className">BookmarkNameFolderLocalizer</string>
- <string key="superclassName">ChromeUILocalizer</string>
- <object class="IBClassDescriptionSource" key="sourceIdentifier">
- <string key="majorKey">IBProjectSource</string>
- <string key="minorKey">../xcodebuild/chrome.build/DerivedSources/Debug/xib_localizers/bookmark_name_folder_localizer.h</string>
- </object>
- </object>
- <object class="IBPartialClassDescription">
<string key="className">ChromeUILocalizer</string>
<string key="superclassName">GTMUILocalizer</string>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
diff --git a/chrome/app/nibs/TabView.xib b/chrome/app/nibs/TabView.xib
index 0a80d73..e7e0950 100644
--- a/chrome/app/nibs/TabView.xib
+++ b/chrome/app/nibs/TabView.xib
@@ -271,7 +271,7 @@
</object>
</object>
<object class="NSCustomObject" id="208901833">
- <string key="NSClassName">TabViewLocalizer</string>
+ <string key="NSClassName">ChromeUILocalizer</string>
</object>
</object>
<object class="IBObjectContainer" key="IBDocument.Objects">
@@ -848,14 +848,6 @@
<string key="minorKey">browser/cocoa/tab_view.h</string>
</object>
</object>
- <object class="IBPartialClassDescription">
- <string key="className">TabViewLocalizer</string>
- <string key="superclassName">ChromeUILocalizer</string>
- <object class="IBClassDescriptionSource" key="sourceIdentifier">
- <string key="majorKey">IBProjectSource</string>
- <string key="minorKey">../xcodebuild/chrome.build/DerivedSources/Debug/xib_localizers/tab_view_localizer.h</string>
- </object>
- </object>
</object>
</object>
<int key="IBDocument.localizationMode">0</int>
diff --git a/chrome/app/nibs/Toolbar.xib b/chrome/app/nibs/Toolbar.xib
index ad59b58..190add7 100644
--- a/chrome/app/nibs/Toolbar.xib
+++ b/chrome/app/nibs/Toolbar.xib
@@ -8,8 +8,8 @@
<string key="IBDocument.HIToolboxVersion">353.00</string>
<object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
<bool key="EncodedWithXMLCoder">YES</bool>
- <integer value="88"/>
<integer value="4"/>
+ <integer value="88"/>
<integer value="102"/>
</object>
<object class="NSArray" key="IBDocument.PluginDependencies">
@@ -673,7 +673,7 @@
</object>
</object>
<object class="NSCustomObject" id="1044322163">
- <string key="NSClassName">ToolbarLocalizer</string>
+ <string key="NSClassName">ChromeUILocalizer</string>
</object>
</object>
<object class="IBObjectContainer" key="IBDocument.Objects">
@@ -1667,7 +1667,7 @@
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
- <string>{{984, 816}, {306, 263}}</string>
+ <string>{{862, 816}, {306, 263}}</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
@@ -1796,6 +1796,14 @@
</object>
</object>
<object class="IBPartialClassDescription">
+ <string key="className">ChromeUILocalizer</string>
+ <string key="superclassName">GTMUILocalizer</string>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBProjectSource</string>
+ <string key="minorKey">browser/cocoa/ui_localizer.h</string>
+ </object>
+ </object>
+ <object class="IBPartialClassDescription">
<string key="className">ClickHoldButtonCell</string>
<string key="superclassName">GradientButtonCell</string>
<object class="NSMutableDictionary" key="outlets">
@@ -1828,6 +1836,29 @@
</object>
</object>
<object class="IBPartialClassDescription">
+ <string key="className">GTMUILocalizer</string>
+ <string key="superclassName">NSObject</string>
+ <object class="NSMutableDictionary" key="outlets">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="NSMutableArray" key="dict.sortedKeys">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <string>otherObjectToLocalize_</string>
+ <string>owner_</string>
+ <string>yetAnotherObjectToLocalize_</string>
+ </object>
+ <object class="NSMutableArray" key="dict.values">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <string>id</string>
+ <string>id</string>
+ <string>id</string>
+ </object>
+ </object>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBProjectSource</string>
+ <string key="minorKey">../third_party/GTM/AppKit/GTMUILocalizer.h</string>
+ </object>
+ </object>
+ <object class="IBPartialClassDescription">
<string key="className">GradientButtonCell</string>
<string key="superclassName">NSButtonCell</string>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
diff --git a/chrome/browser/app_controller_mac.mm b/chrome/browser/app_controller_mac.mm
index 0cdee36..d7f4a97 100644
--- a/chrome/browser/app_controller_mac.mm
+++ b/chrome/browser/app_controller_mac.mm
@@ -24,6 +24,7 @@
#import "chrome/browser/cocoa/preferences_window_controller.h"
#import "chrome/browser/cocoa/tab_strip_controller.h"
#import "chrome/browser/cocoa/tab_window_controller.h"
+#import "chrome/browser/cocoa/ui_localizer.h"
#include "chrome/browser/command_updater.h"
#include "chrome/browser/download/download_manager.h"
#include "chrome/browser/sessions/tab_restore_service.h"
@@ -32,7 +33,6 @@
#include "chrome/browser/profile_manager.h"
#include "chrome/common/temp_scaffolding_stubs.h"
#include "grit/generated_resources.h"
-#import "xib_localizers/main_menu_localizer.h"
@interface AppController(PRIVATE)
- (void)initMenuState;
@@ -228,8 +228,8 @@
// because it's too early. Do it before we create any bookmark menus as well,
// just in case one has a title that matches any of our strings (unlikely,
// but technically possible).
- scoped_nsobject<MainMenuLocalizer> localizer(
- [[MainMenuLocalizer alloc] initWithBundle:nil]);
+ scoped_nsobject<ChromeUILocalizer> localizer(
+ [[ChromeUILocalizer alloc] initWithBundle:nil]);
[localizer localizeObject:[NSApplication sharedApplication]
recursively:YES];
diff --git a/chrome/browser/cocoa/ui_localizer.h b/chrome/browser/cocoa/ui_localizer.h
index 50c480a..fc7b57b 100644
--- a/chrome/browser/cocoa/ui_localizer.h
+++ b/chrome/browser/cocoa/ui_localizer.h
@@ -5,30 +5,14 @@
#ifndef CHROME_BROWSER_COCOA_UI_LOCALIZER_H_
#define CHROME_BROWSER_COCOA_UI_LOCALIZER_H_
-#include "base/basictypes.h"
-#include "base/string16.h"
#import "third_party/GTM/AppKit/GTMUILocalizer.h"
@class NSString;
-namespace ui_localizer {
-
-struct ResourceMap {
- const char* const name;
- unsigned int label_id;
- unsigned int label_arg_id;
-};
-
-NSString* LocalizedStringForKeyFromMapList(NSString* key,
- const ResourceMap* map_list,
- size_t map_list_len);
-
-} // 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.
+// To use this, include your xib file in the list generate_localizer scans (see
+// chrome.gyp). Then add an instance of ChromeUILocalizer 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
diff --git a/chrome/browser/cocoa/ui_localizer.mm b/chrome/browser/cocoa/ui_localizer.mm
index 7fd4d44..77e9154 100644
--- a/chrome/browser/cocoa/ui_localizer.mm
+++ b/chrome/browser/cocoa/ui_localizer.mm
@@ -6,53 +6,33 @@
#import <Foundation/Foundation.h>
+#include <stdlib.h>
#include "app/l10n_util_mac.h"
#include "base/sys_string_conversions.h"
#include "base/logging.h"
+#include "grit/app_strings.h"
+#include "grit/chromium_strings.h"
+#include "grit/generated_resources.h"
-namespace ui_localizer {
+struct UILocalizerResourceMap {
+ const char* const name;
+ unsigned int label_id;
+ unsigned int label_arg_id;
+};
-NSString* LocalizedStringForKeyFromMapList(NSString* key,
- const ResourceMap* map_list,
- size_t map_list_len) {
- DCHECK(key != nil);
- DCHECK(map_list != NULL);
- // Look up the string for the resource id to fetch.
- const char* utf8_key = [key UTF8String];
- if (utf8_key) {
- // If we end up with enough string constants in here, look at using bsearch
- // to speed up the searching.
- for (size_t i = 0; i < map_list_len; ++i) {
- int strcmp_result = strcmp(utf8_key, map_list[i].name);
- if (strcmp_result == 0) {
- // Do we need to build the string, or just fetch it?
- if (map_list[i].label_arg_id != 0) {
- const string16 label_arg(
- l10n_util::GetStringUTF16(map_list[i].label_arg_id));
- return l10n_util::GetNSStringFWithFixup(map_list[i].label_id,
- label_arg);
- }
-
- return l10n_util::GetNSStringWithFixup(map_list[i].label_id);
- }
-
- // If we've passed where the string would be, give up.
- if (strcmp_result < 0)
- break;
- }
- }
+namespace {
- // Sanity check, there shouldn't be any strings with this id that aren't
- // in our map.
- DLOG_IF(WARNING, [key hasPrefix:@"^ID"]) << "Key '" << utf8_key
- << "' wasn't in the resource map?";
-
- // If we didn't find anything, this string doesn't need localizing.
- return nil;
+// Utility function for bsearch on a ResourceMap table
+int ResourceMapCompare(const void* utf8Void,
+ const void* resourceMapVoid) {
+ const char* utf8_key = reinterpret_cast<const char*>(utf8Void);
+ const UILocalizerResourceMap* res_map =
+ reinterpret_cast<const UILocalizerResourceMap*> (resourceMapVoid);
+ return strcmp(utf8_key, res_map->name);
}
-} // namespace ui_localizer
+} // namespace
@interface GTMUILocalizer (PrivateAdditions)
- (void)localizedObjects;
@@ -69,17 +49,49 @@ NSString* LocalizedStringForKeyFromMapList(NSString* key,
@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.";
+
+ // Include the table here so it is a local static. This header provides
+ // kUIResources and kUIResourcesSize.
+#include "ui_localizer_table.h"
+
+ // Look up the string for the resource id to fetch.
+ const char* utf8_key = [string UTF8String];
+ if (utf8_key) {
+ const void* valVoid = bsearch(utf8_key,
+ kUIResources,
+ kUIResourcesSize,
+ sizeof(UILocalizerResourceMap),
+ ResourceMapCompare);
+ const UILocalizerResourceMap* val =
+ reinterpret_cast<const UILocalizerResourceMap*>(valVoid);
+ if (val) {
+ // Do we need to build the string, or just fetch it?
+ if (val->label_arg_id != 0) {
+ const string16 label_arg(l10n_util::GetStringUTF16(val->label_arg_id));
+ return l10n_util::GetNSStringFWithFixup(val->label_id,
+ label_arg);
+ }
+
+ return l10n_util::GetNSStringWithFixup(val->label_id);
+ }
+
+ // Sanity check, there shouldn't be any strings with this id that aren't
+ // in our map.
+ DLOG_IF(WARNING, [string hasPrefix:@"^ID"]) << "Key '" << utf8_key
+ << "' wasn't in the resource map?";
+ }
+
+ // If we didn't find anything, this string doesn't need localizing.
+ return nil;
}
-#endif
+
@end
diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp
index c963157..d84fa80 100644
--- a/chrome/chrome.gyp
+++ b/chrome/chrome.gyp
@@ -20,8 +20,6 @@
'../webkit/webkit.gyp:inspector_resources',
],
'grit_out_dir': '<(SHARED_INTERMEDIATE_DIR)/chrome',
- 'mac_xib_localizer_tool_path': '<(DEPTH)/build/mac/generate_localizer',
- 'mac_xib_localizers_dir': '<(INTERMEDIATE_DIR)/xib_localizers',
# TODO(mmoss) This might need to go somewhere more general, then we can use
# it to also rewrite app/locales/locales.gyp with a helper script.
'locales': [
@@ -2091,87 +2089,36 @@
],
},
'actions': [
- # This block of actions are used to extract the localization data
- # from xib files and generate a localizer out of it.
{
+ # This action is used to extract the localization data from xib
+ # files and generate table for the ui localizer from it.
+ 'variables': {
+ 'xib_localizer_tool_path':
+ '<(DEPTH)/build/mac/generate_localizer',
+ 'xib_files_to_scan': [
+ # The xib that need localization
+ 'app/nibs/BookmarkBar.xib',
+ 'app/nibs/BookmarkEditor.xib',
+ 'app/nibs/BookmarkNameFolder.xib',
+ 'app/nibs/MainMenu.xib',
+ 'app/nibs/TabView.xib',
+ 'app/nibs/Toolbar.xib',
+ # TODO(tvl): add other xibs as needed
+ ],
+ },
'action_name': 'process_bookmark_bar_xib',
'process_outputs_as_sources': 1,
'inputs': [
- '<(mac_xib_localizer_tool_path)',
- 'app/nibs/BookmarkBar.xib'
- ],
- 'outputs': [
- '<(mac_xib_localizers_dir)/bookmark_bar_localizer.h',
- '<(mac_xib_localizers_dir)/bookmark_bar_localizer.mm',
- ],
- 'action': ['<@(_inputs)', '<@(_outputs)'],
- },
- {
- 'action_name': 'process_bookmark_editor_xib',
- 'process_outputs_as_sources': 1,
- 'inputs': [
- '<(mac_xib_localizer_tool_path)',
- 'app/nibs/BookmarkEditor.xib'
- ],
- 'outputs': [
- '<(mac_xib_localizers_dir)/bookmark_editor_localizer.h',
- '<(mac_xib_localizers_dir)/bookmark_editor_localizer.mm',
- ],
- 'action': ['<@(_inputs)', '<@(_outputs)'],
- },
- {
- 'action_name': 'process_bookmark_name_folder_xib',
- 'process_outputs_as_sources': 1,
- 'inputs': [
- '<(mac_xib_localizer_tool_path)',
- 'app/nibs/BookmarkNameFolder.xib'
- ],
- 'outputs': [
- '<(mac_xib_localizers_dir)/bookmark_name_folder_localizer.h',
- '<(mac_xib_localizers_dir)/bookmark_name_folder_localizer.mm',
- ],
- 'action': ['<@(_inputs)', '<@(_outputs)'],
- },
- {
- 'action_name': 'process_mainmenu_xib',
- 'process_outputs_as_sources': 1,
- 'inputs': [
- '<(mac_xib_localizer_tool_path)',
- 'app/nibs/MainMenu.xib'
- ],
- 'outputs': [
- '<(mac_xib_localizers_dir)/main_menu_localizer.h',
- '<(mac_xib_localizers_dir)/main_menu_localizer.mm',
- ],
- 'action': ['<@(_inputs)', '<@(_outputs)'],
- },
- {
- 'action_name': 'process_tab_view_xib',
- 'process_outputs_as_sources': 1,
- 'inputs': [
- '<(mac_xib_localizer_tool_path)',
- 'app/nibs/TabView.xib'
- ],
- 'outputs': [
- '<(mac_xib_localizers_dir)/tab_view_localizer.h',
- '<(mac_xib_localizers_dir)/tab_view_localizer.mm',
- ],
- 'action': ['<@(_inputs)', '<@(_outputs)'],
- },
- {
- 'action_name': 'process_toolbar_xib',
- 'process_outputs_as_sources': 1,
- 'inputs': [
- '<(mac_xib_localizer_tool_path)',
- 'app/nibs/Toolbar.xib'
+ '<(xib_localizer_tool_path)',
+ '<@(xib_files_to_scan)',
],
'outputs': [
- '<(mac_xib_localizers_dir)/toolbar_localizer.h',
- '<(mac_xib_localizers_dir)/toolbar_localizer.mm',
+ '<(INTERMEDIATE_DIR)/ui_localizer_table.h',
],
- 'action': ['<@(_inputs)', '<@(_outputs)'],
+ 'action': ['<(xib_localizer_tool_path)',
+ '<@(_outputs)',
+ '<@(xib_files_to_scan)'],
},
- # TODO(tvl): add other xibs
],
}],
['OS=="win"', {