summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorthomasvl@chromium.org <thomasvl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-12 20:33:05 +0000
committerthomasvl@chromium.org <thomasvl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-12 20:33:05 +0000
commit885b72726cd788273b305da33d04c65cfa130d09 (patch)
treebb23ed9f0f54655773ec102b10eb234c69090f0e
parente56861937b3bdea9ecafc082f6dd29c52bd16bee (diff)
downloadchromium_src-885b72726cd788273b305da33d04c65cfa130d09.zip
chromium_src-885b72726cd788273b305da33d04c65cfa130d09.tar.gz
chromium_src-885b72726cd788273b305da33d04c65cfa130d09.tar.bz2
Move the menu bar l10n into the xib file.
Localize the menu bar titles. Have the browser platform delegate startup the resource bundle system so we can fetch localization data. Make l10n_util::GetApplicationLocale return what cocoa says for the language so we match what the UI is using. TEST=everything still works. BUG=17380 Review URL: http://codereview.chromium.org/164413 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@23215 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--app/l10n_util.cc15
-rw-r--r--app/l10n_util_mac.mm7
-rw-r--r--chrome/app/nibs/MainMenu.xib93
-rw-r--r--chrome/browser/app_controller_mac.mm12
-rw-r--r--chrome/browser/browser_main.cc21
-rw-r--r--chrome/browser/browser_main_mac.mm13
6 files changed, 111 insertions, 50 deletions
diff --git a/app/l10n_util.cc b/app/l10n_util.cc
index 751a41c..1330263 100644
--- a/app/l10n_util.cc
+++ b/app/l10n_util.cc
@@ -220,15 +220,12 @@ namespace l10n_util {
// Represents the locale-specific text direction.
static TextDirection g_text_direction = UNKNOWN_DIRECTION;
+// On the Mac, we don't want to test preferences or ICU for the language,
+// we want to use whatever Cocoa is using when it loaded the main nib file.
+// It handles all the mapping and fallbacks for us, we just need to ask.
+// See l10n_util_mac for that implementation.
+#if !defined(OS_MACOSX)
std::string GetApplicationLocale(const std::wstring& pref_locale) {
-#if defined(OS_MACOSX)
- // On the mac, we don't want to test preferences or ICU for the language,
- // we want to use whatever Cocoa is using when it loaded the main nib file.
- // It handles all the mapping and fallbacks for us, we just need to ask
- // Cocoa.
- // TODO(pinkerton): break this out into a .mm and ask Cocoa.
- return "en";
-#else
FilePath locale_path;
PathService::Get(app::DIR_LOCALES, &locale_path);
std::string resolved_locale;
@@ -269,8 +266,8 @@ std::string GetApplicationLocale(const std::wstring& pref_locale) {
NOTREACHED();
return std::string();
-#endif
}
+#endif // !defined(OS_MACOSX)
string16 GetDisplayNameForLocale(const std::string& locale_code,
const std::string& display_locale,
diff --git a/app/l10n_util_mac.mm b/app/l10n_util_mac.mm
index a664eb3..fe09826 100644
--- a/app/l10n_util_mac.mm
+++ b/app/l10n_util_mac.mm
@@ -8,6 +8,13 @@
namespace l10n_util {
+std::string GetApplicationLocale(const std::wstring& pref_locale) {
+ // NOTE: The Win/Linux version of this calls out to CheckAndResolveLocale
+ // to do some remapping. Since Mac is using real locales that Cocoa has
+ // to be able to load, that shouldn't be needed.
+ return [[[NSLocale currentLocale] localeIdentifier] UTF8String];
+}
+
// Remove the Windows-style accelerator marker and change "..." into an
// ellipsis. Returns the result in an autoreleased NSString.
NSString* FixUpWindowsStyleLabel(const string16& label) {
diff --git a/chrome/app/nibs/MainMenu.xib b/chrome/app/nibs/MainMenu.xib
index 1b2e29e..49e79a6 100644
--- a/chrome/app/nibs/MainMenu.xib
+++ b/chrome/app/nibs/MainMenu.xib
@@ -2,13 +2,13 @@
<archive type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="7.03">
<data>
<int key="IBDocument.SystemTarget">1050</int>
- <string key="IBDocument.SystemVersion">9J61</string>
+ <string key="IBDocument.SystemVersion">9L30</string>
<string key="IBDocument.InterfaceBuilderVersion">677</string>
- <string key="IBDocument.AppKitVersion">949.46</string>
+ <string key="IBDocument.AppKitVersion">949.54</string>
<string key="IBDocument.HIToolboxVersion">353.00</string>
<object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
<bool key="EncodedWithXMLCoder">YES</bool>
- <integer value="29"/>
+ <integer value="19"/>
</object>
<object class="NSArray" key="IBDocument.PluginDependencies">
<bool key="EncodedWithXMLCoder">YES</bool>
@@ -192,14 +192,14 @@
</object>
<object class="NSMenuItem" id="379814623">
<reference key="NSMenu" ref="649796088"/>
- <string key="NSTitle">File</string>
+ <string key="NSTitle">^IDS_FILE_MENU_MAC</string>
<string key="NSKeyEquiv"/>
<int key="NSMnemonicLoc">2147483647</int>
<reference key="NSOnImage" ref="353210768"/>
<reference key="NSMixedImage" ref="549394948"/>
<string key="NSAction">submenuAction:</string>
<object class="NSMenu" key="NSSubmenu" id="720053764">
- <string key="NSTitle">File</string>
+ <string key="NSTitle">^IDS_FILE_MENU_MAC</string>
<object class="NSMutableArray" key="NSMenuItems">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="NSMenuItem" id="603924433">
@@ -394,14 +394,14 @@
</object>
<object class="NSMenuItem" id="952259628">
<reference key="NSMenu" ref="649796088"/>
- <string key="NSTitle">Edit</string>
+ <string key="NSTitle">^IDS_EDIT_MENU_MAC</string>
<string key="NSKeyEquiv"/>
<int key="NSMnemonicLoc">2147483647</int>
<reference key="NSOnImage" ref="353210768"/>
<reference key="NSMixedImage" ref="549394948"/>
<string key="NSAction">submenuAction:</string>
<object class="NSMenu" key="NSSubmenu" id="789758025">
- <string key="NSTitle">Edit</string>
+ <string key="NSTitle">^IDS_EDIT_MENU_MAC</string>
<object class="NSMutableArray" key="NSMenuItems">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="NSMenuItem" id="1058277027">
@@ -686,7 +686,7 @@
</object>
<object class="NSMenuItem" id="586577488">
<reference key="NSMenu" ref="649796088"/>
- <string key="NSTitle">View</string>
+ <string key="NSTitle">^IDS_VIEW_MENU_MAC</string>
<string key="NSKeyEquiv"/>
<int key="NSMnemonicLoc">2147483647</int>
<reference key="NSOnImage" ref="353210768"/>
@@ -694,7 +694,7 @@
<string key="NSAction">submenuAction:</string>
<int key="NSTag">44000</int>
<object class="NSMenu" key="NSSubmenu" id="466310130">
- <string key="NSTitle">View</string>
+ <string key="NSTitle">^IDS_VIEW_MENU_MAC</string>
<object class="NSMutableArray" key="NSMenuItems">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="NSMenuItem" id="102151532">
@@ -862,7 +862,7 @@
</object>
<object class="NSMenuItem" id="445514911">
<reference key="NSMenu" ref="649796088"/>
- <string key="NSTitle">History</string>
+ <string key="NSTitle">^IDS_HISTORY_MENU_MAC</string>
<string key="NSKeyEquiv"/>
<int key="NSMnemonicLoc">2147483647</int>
<reference key="NSOnImage" ref="353210768"/>
@@ -870,7 +870,7 @@
<string key="NSAction">submenuAction:</string>
<int key="NSTag">46000</int>
<object class="NSMenu" key="NSSubmenu" id="436720301">
- <string key="NSTitle">History</string>
+ <string key="NSTitle">^IDS_HISTORY_MENU_MAC</string>
<object class="NSMutableArray" key="NSMenuItems">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="NSMenuItem" id="64100325">
@@ -967,7 +967,7 @@
</object>
<object class="NSMenuItem" id="299901009">
<reference key="NSMenu" ref="649796088"/>
- <string key="NSTitle">Bookmarks</string>
+ <string key="NSTitle">^IDS_BOOKMARKS_MENU_MAC</string>
<string key="NSKeyEquiv"/>
<int key="NSMnemonicLoc">2147483647</int>
<reference key="NSOnImage" ref="353210768"/>
@@ -975,7 +975,7 @@
<string key="NSAction">submenuAction:</string>
<int key="NSTag">43000</int>
<object class="NSMenu" key="NSSubmenu" id="891828782">
- <string key="NSTitle">Bookmarks</string>
+ <string key="NSTitle">^IDS_BOOKMARKS_MENU_MAC</string>
<object class="NSMutableArray" key="NSMenuItems">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="NSMenuItem" id="399860348">
@@ -1004,14 +1004,14 @@
</object>
<object class="NSMenuItem" id="713487014">
<reference key="NSMenu" ref="649796088"/>
- <string key="NSTitle">Window</string>
+ <string key="NSTitle">^IDS_WINDOW_MENU_MAC</string>
<string key="NSKeyEquiv"/>
<int key="NSMnemonicLoc">2147483647</int>
<reference key="NSOnImage" ref="353210768"/>
<reference key="NSMixedImage" ref="549394948"/>
<string key="NSAction">submenuAction:</string>
<object class="NSMenu" key="NSSubmenu" id="835318025">
- <string key="NSTitle">Window</string>
+ <string key="NSTitle">^IDS_WINDOW_MENU_MAC</string>
<object class="NSMutableArray" key="NSMenuItems">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="NSMenuItem" id="1011231497">
@@ -1115,14 +1115,14 @@
</object>
<object class="NSMenuItem" id="391199113">
<reference key="NSMenu" ref="649796088"/>
- <string key="NSTitle">Help</string>
+ <string key="NSTitle">^IDS_HELP_MENU_MAC</string>
<string key="NSKeyEquiv"/>
<int key="NSMnemonicLoc">2147483647</int>
<reference key="NSOnImage" ref="353210768"/>
<reference key="NSMixedImage" ref="549394948"/>
<string key="NSAction">submenuAction:</string>
<object class="NSMenu" key="NSSubmenu" id="374024848">
- <string key="NSTitle">Help</string>
+ <string key="NSTitle">^IDS_HELP_MENU_MAC</string>
<object class="NSMutableArray" key="NSMenuItems">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="NSMenuItem" id="238773614">
@@ -1143,6 +1143,9 @@
<object class="NSCustomObject" id="168151378">
<string key="NSClassName">AppController</string>
</object>
+ <object class="NSCustomObject" id="979722531">
+ <string key="NSClassName">ChromeUILocalizer</string>
+ </object>
</object>
<object class="IBObjectContainer" key="IBDocument.Objects">
<object class="NSMutableArray" key="connectionRecords">
@@ -1652,6 +1655,14 @@
<int key="connectionID">635</int>
</object>
<object class="IBConnectionRecord">
+ <object class="IBOutletConnection" key="connection">
+ <string key="label">owner_</string>
+ <reference key="source" ref="979722531"/>
+ <reference key="destination" ref="1021"/>
+ </object>
+ <int key="connectionID">642</int>
+ </object>
+ <object class="IBConnectionRecord">
<object class="IBActionConnection" key="connection">
<string key="label">orderFrontStandardAboutPanel:</string>
<reference key="source" ref="168151378"/>
@@ -2527,6 +2538,11 @@
<reference key="object" ref="101838950"/>
<reference key="parent" ref="436720301"/>
</object>
+ <object class="IBObjectRecord">
+ <int key="objectID">641</int>
+ <reference key="object" ref="979722531"/>
+ <reference key="parent" ref="1049"/>
+ </object>
</object>
</object>
<object class="NSMutableDictionary" key="flattenedProperties">
@@ -2737,6 +2753,7 @@
<string>636.IBPluginDependency</string>
<string>639.IBPluginDependency</string>
<string>640.IBPluginDependency</string>
+ <string>641.IBPluginDependency</string>
<string>72.IBPluginDependency</string>
<string>72.ImportedFromIB2</string>
<string>73.IBPluginDependency</string>
@@ -2829,7 +2846,7 @@
<reference ref="9"/>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<reference ref="9"/>
- <string>{{358, 501}, {287, 263}}</string>
+ <string>{{484, 501}, {287, 263}}</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<reference ref="9"/>
<string>{{197, 734}, {243, 243}}</string>
@@ -2875,11 +2892,11 @@
<reference ref="9"/>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<reference ref="9"/>
- <string>{{613, 601}, {326, 163}}</string>
+ <string>{{1259, 601}, {326, 163}}</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<reference ref="9"/>
<string>{{525, 802}, {197, 73}}</string>
- <string>{{210, 764}, {535, 20}}</string>
+ <string>{{210, 764}, {1437, 20}}</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<reference ref="9"/>
<string>{74, 862}</string>
@@ -2927,7 +2944,7 @@
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
- <string>{{519, 731}, {347, 33}}</string>
+ <string>{{1031, 731}, {347, 33}}</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<reference ref="9"/>
@@ -2969,6 +2986,7 @@
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<reference ref="9"/>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<reference ref="9"/>
@@ -3014,7 +3032,7 @@
</object>
</object>
<nil key="sourceID"/>
- <int key="maxID">640</int>
+ <int key="maxID">642</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
@@ -3056,6 +3074,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">DownloadShelfController</string>
<string key="superclassName">NSViewController</string>
<object class="NSMutableDictionary" key="actions">
@@ -3108,6 +3134,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">NSObject</string>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
<string key="majorKey">IBProjectSource</string>
diff --git a/chrome/browser/app_controller_mac.mm b/chrome/browser/app_controller_mac.mm
index 40ccaad..ccec4f9 100644
--- a/chrome/browser/app_controller_mac.mm
+++ b/chrome/browser/app_controller_mac.mm
@@ -26,7 +26,6 @@
#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/tab_contents/tab_contents.h"
@@ -264,17 +263,6 @@
DCHECK(g_browser_process);
g_browser_process->AddRefModule();
- // TODO: move this into the MainMenu.xib once we clean up the startup order
- // dependencies so that works. http://crbug.com/17380
- // Create the localizer for the main menu. We can't do this in the nib
- // 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<ChromeUILocalizer> localizer(
- [[ChromeUILocalizer alloc] initWithBundle:nil]);
- [localizer localizeObject:[NSApplication sharedApplication]
- recursively:YES];
-
bookmarkMenuBridge_.reset(new BookmarkMenuBridge());
historyMenuBridge_.reset(new HistoryMenuBridge([self defaultProfile]));
diff --git a/chrome/browser/browser_main.cc b/chrome/browser/browser_main.cc
index 560fc54..3501779 100644
--- a/chrome/browser/browser_main.cc
+++ b/chrome/browser/browser_main.cc
@@ -118,13 +118,13 @@
namespace Platform {
-void WillInitializeMainMessageLoop(const CommandLine & command_line);
+void WillInitializeMainMessageLoop(const MainFunctionParams& parameters);
void WillTerminate();
#if defined(OS_WIN) || defined(OS_LINUX)
// Perform any platform-specific work that needs to be done before the main
// message loop is created and initialized.
-void WillInitializeMainMessageLoop(const CommandLine & command_line) {
+void WillInitializeMainMessageLoop(const MainFunctionParams& parameters) {
}
// Perform platform-specific work that needs to be done after the main event
@@ -299,7 +299,7 @@ int BrowserMain(const MainFunctionParams& parameters) {
// Do platform-specific things (such as finishing initializing Cocoa)
// prior to instantiating the message loop. This could be turned into a
// broadcast notification.
- Platform::WillInitializeMainMessageLoop(parsed_command_line);
+ Platform::WillInitializeMainMessageLoop(parameters);
MessageLoop main_message_loop(MessageLoop::TYPE_UI);
@@ -392,13 +392,17 @@ int BrowserMain(const MainFunctionParams& parameters) {
#endif
- // During first run we read the google_update registry key to find what
- // language the user selected when downloading the installer. This
- // becomes our default language in the prefs.
if (is_first_run) {
+#if !defined(OS_MACOSX)
+ // During first run we read the google_update registry key to find what
+ // language the user selected when downloading the installer. This
+ // becomes our default language in the prefs.
+ // Mac doesn't need this because it is always using language that Cocoa
+ // selected from the user's language list (in System Preferences).
std::wstring install_lang;
if (GoogleUpdateSettings::GetLanguage(&install_lang))
local_state->SetString(prefs::kApplicationLocale, install_lang);
+#endif // defined(OS_MACOSX)
if (GoogleUpdateSettings::GetCollectStatsConsent())
local_state->SetBoolean(prefs::kMetricsReportingEnabled, true);
}
@@ -427,12 +431,17 @@ int BrowserMain(const MainFunctionParams& parameters) {
// If we're running tests (ui_task is non-null), then the ResourceBundle
// has already been initialized.
+ // Mac starts it earlier in Platform::WillInitializeMainMessageLoop (because
+ // it is needed when loading the MainMenu.nib and the language doesn't depend
+ // on anything since it comes from Cocoa.
+#if !defined(OS_MACOSX)
if (!parameters.ui_task) {
ResourceBundle::InitSharedInstance(
local_state->GetString(prefs::kApplicationLocale));
// We only load the theme dll in the browser process.
ResourceBundle::GetSharedInstance().LoadThemeResources();
}
+#endif // !defined(OS_MACOSX)
#if defined(OS_WIN)
// This is experimental code. See first_run_win.cc for more info.
diff --git a/chrome/browser/browser_main_mac.mm b/chrome/browser/browser_main_mac.mm
index b532742..d3041cc 100644
--- a/chrome/browser/browser_main_mac.mm
+++ b/chrome/browser/browser_main_mac.mm
@@ -3,9 +3,11 @@
// found in the LICENSE file.
#import <Cocoa/Cocoa.h>
+#include "app/resource_bundle.h"
#include "base/command_line.h"
#import "chrome/app/keystone_glue.h"
#include "chrome/browser/browser_main_win.h"
+#include "chrome/common/main_function_params.h"
#include "chrome/common/result_codes.h"
namespace Platform {
@@ -20,8 +22,17 @@ namespace Platform {
// load the main nib directly. The main event loop is run from common code using
// the MessageLoop API, which works out ok for us because it's a wrapper around
// CFRunLoop.
-void WillInitializeMainMessageLoop(const CommandLine& command_line) {
+void WillInitializeMainMessageLoop(const MainFunctionParams& parameters) {
[NSApplication sharedApplication];
+ // Before we load the nib, we need to start up the resource bundle so we have
+ // the strings avaiable for localization.
+ if (!parameters.ui_task) {
+ ResourceBundle::InitSharedInstance(std::wstring());
+ // We only load the theme resources in the browser process, since this is
+ // the browser process, load them.
+ ResourceBundle::GetSharedInstance().LoadThemeResources();
+ }
+ // Now load the nib.
[NSBundle loadNibNamed:@"MainMenu" owner:NSApp];
// This is a no-op if the KeystoneRegistration framework is not present.