From 7b22524519ce66c5b660bf215013adcabd8ab936 Mon Sep 17 00:00:00 2001 From: "pinkerton@chromium.org" Date: Wed, 20 May 2009 17:59:34 +0000 Subject: Use GTM's l10n class to substitute the correctly branded string for "Quit Chromium" at runtime. Update the string grd files to have this string. BUG=11486. TEST=check the quit menu item in the app menu for the correct branding. Review URL: http://codereview.chromium.org/115574 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@16489 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/browser/app_controller_mac.mm | 10 ++++++++++ chrome/browser/cocoa/menu_localizer.h | 19 +++++++++++++++++++ chrome/browser/cocoa/menu_localizer.mm | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+) create mode 100644 chrome/browser/cocoa/menu_localizer.h create mode 100644 chrome/browser/cocoa/menu_localizer.mm (limited to 'chrome/browser') diff --git a/chrome/browser/app_controller_mac.mm b/chrome/browser/app_controller_mac.mm index 859840f..0b88c36 100644 --- a/chrome/browser/app_controller_mac.mm +++ b/chrome/browser/app_controller_mac.mm @@ -14,6 +14,7 @@ #include "chrome/browser/browser_shutdown.h" #import "chrome/browser/cocoa/bookmark_menu_bridge.h" #import "chrome/browser/cocoa/encoding_menu_controller_delegate_mac.h" +#import "chrome/browser/cocoa/menu_localizer.h" #import "chrome/browser/cocoa/preferences_window_controller.h" #include "chrome/browser/command_updater.h" #include "chrome/common/pref_names.h" @@ -67,6 +68,15 @@ DCHECK(g_browser_process); g_browser_process->AddRefModule(); + // 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 localizer( + [[MenuLocalizer alloc] initWithBundle:nil]); + [localizer localizeObject:[NSApplication sharedApplication] + recursively:YES]; + bookmarkMenuBridge_.reset(new BookmarkMenuBridge()); // Register any Mac-specific preferences. diff --git a/chrome/browser/cocoa/menu_localizer.h b/chrome/browser/cocoa/menu_localizer.h new file mode 100644 index 0000000..862ba20 --- /dev/null +++ b/chrome/browser/cocoa/menu_localizer.h @@ -0,0 +1,19 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_COCOA_MENU_LOCALIZER_H_ +#define CHROME_BROWSER_COCOA_MENU_LOCALIZER_H_ + +#import + +#import "third_party/GTM/AppKit/GTMUILocalizer.h" + +// A subclass of GTMUILocalizer that handles localizing our main menus. It maps +// from the ^-prefixed strings in the nib into the strings bundles. + +@interface MenuLocalizer : GTMUILocalizer { +} +@end + +#endif // CHROME_BROWSER_COCOA_MENU_LOCALIZER_H_ diff --git a/chrome/browser/cocoa/menu_localizer.mm b/chrome/browser/cocoa/menu_localizer.mm new file mode 100644 index 0000000..7b09520 --- /dev/null +++ b/chrome/browser/cocoa/menu_localizer.mm @@ -0,0 +1,33 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#import "chrome/browser/cocoa/menu_localizer.h" + +#include "app/l10n_util.h" +#include "base/sys_string_conversions.h" +#include "grit/chromium_strings.h" + +@implementation MenuLocalizer + +// Override to map into our string bundles instead of strings plists. +// TODO(pinkerton): This should use a string lookup table to map the string to +// a constant. +- (NSString *)localizedStringForString:(NSString *)string { + if ([string isEqualToString:@"^Quit Chromium"]) { + std::wstring quitString = l10n_util::GetString(IDS_EXIT_MAC); + return base::SysWideToNSString(quitString); + } else if ([string isEqualToString:@"^About Chromium"]) { + std::wstring quitString = l10n_util::GetString(IDS_ABOUT_CHROME_TITLE); + return base::SysWideToNSString(quitString); + } else if ([string isEqualToString:@"^Hide Chromium"]) { + std::wstring quitString = l10n_util::GetString(IDS_HIDE_MAC); + return base::SysWideToNSString(quitString); + } else if ([string isEqualToString:@"^Chromium Help"]) { + std::wstring quitString = l10n_util::GetString(IDS_HELP_MAC); + return base::SysWideToNSString(quitString); + } + return [super localizedStringForString:string]; +} + +@end -- cgit v1.1