summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorthomasvl@chromium.org <thomasvl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-07 19:26:36 +0000
committerthomasvl@chromium.org <thomasvl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-07 19:26:36 +0000
commitaff5eec98954766821f46a7e9fab07b7007f0319 (patch)
treef1f93210978317adc3ca097e49486cf79035c389
parent086eaec4d8ed6b6207925253f17fdabef82a0ed7 (diff)
downloadchromium_src-aff5eec98954766821f46a7e9fab07b7007f0319.zip
chromium_src-aff5eec98954766821f46a7e9fab07b7007f0319.tar.gz
chromium_src-aff5eec98954766821f46a7e9fab07b7007f0319.tar.bz2
Move some Mac l10n helpers out into app/l10n so they are closer to the generic ones.
Complete the apis points so the ones folks might need are all there already. Switch the code using the old calls over to the new helpers. TEST=no l10n stuff broke BUG=none Review URL: http://codereview.chromium.org/165132 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@22753 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--app/app.gyp3
-rw-r--r--app/l10n_util.h8
-rw-r--r--app/l10n_util_mac.h68
-rw-r--r--app/l10n_util_mac.mm106
-rw-r--r--app/l10n_util_mac_unittest.mm (renamed from chrome/browser/cocoa/ui_localizer_unittest.mm)8
-rw-r--r--chrome/browser/cocoa/ui_localizer.h4
-rw-r--r--chrome/browser/cocoa/ui_localizer.mm33
-rw-r--r--chrome/browser/tab_contents/render_view_context_menu_mac.mm5
-rw-r--r--chrome/chrome.gyp1
9 files changed, 195 insertions, 41 deletions
diff --git a/app/app.gyp b/app/app.gyp
index 5c989ae..e63ff82 100644
--- a/app/app.gyp
+++ b/app/app.gyp
@@ -88,6 +88,8 @@
'gfx/text_elider.h',
'l10n_util.cc',
'l10n_util.h',
+ 'l10n_util_mac.h',
+ 'l10n_util_mac.mm',
'l10n_util_posix.cc',
'l10n_util_win.cc',
'l10n_util_win.h',
@@ -170,6 +172,7 @@
'gfx/font_unittest.cc',
'gfx/icon_util_unittest.cc',
'gfx/text_elider_unittest.cc',
+ 'l10n_util_mac_unittest.mm',
'l10n_util_unittest.cc',
'os_exchange_data_win_unittest.cc',
'run_all_unittests.cc',
diff --git a/app/l10n_util.h b/app/l10n_util.h
index 464c3b8..0944912 100644
--- a/app/l10n_util.h
+++ b/app/l10n_util.h
@@ -26,6 +26,10 @@
#include "unicode/ubidi.h"
#include "unicode/uchar.h"
+#if defined(OS_MACOSX)
+#include "app/l10n_util.h"
+#endif // OS_MACOSX
+
class FilePath;
class PrefService;
@@ -66,6 +70,10 @@ string16 GetDisplayNameForLocale(const std::string& locale_code,
const std::string& display_locale,
bool is_for_ui);
+//
+// Mac Note: See l10n_util_mac.h for some NSString versions and other support.
+//
+
// Pulls resource string from the string bundle and returns it.
std::wstring GetString(int message_id);
std::string GetStringUTF8(int message_id);
diff --git a/app/l10n_util_mac.h b/app/l10n_util_mac.h
new file mode 100644
index 0000000..87ccb05
--- /dev/null
+++ b/app/l10n_util_mac.h
@@ -0,0 +1,68 @@
+// 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 APP_L10N_UTIL_MAC_H_
+#define APP_L10N_UTIL_MAC_H_
+
+#include "app/l10n_util.h"
+#include "base/basictypes.h"
+#include "base/string16.h"
+
+#ifdef __OBJC__
+@class NSString;
+#else
+class NSString;
+#endif
+
+namespace l10n_util {
+
+// Remove the Windows-style accelerator marker (for labels, menuitems, etc.)
+// and change "..." into an ellipsis.
+// Returns the result in an autoreleased NSString.
+NSString* FixUpWindowsStyleLabel(const string16& label);
+
+// Pulls resource string from the string bundle and returns it.
+NSString* GetNSString(int message_id);
+
+// Get a resource string and replace $1-$2-$3 with |a| and |b|
+// respectively. Additionally, $$ is replaced by $.
+NSString* GetNSStringF(int message_id,
+ const string16& a);
+NSString* GetNSStringF(int message_id,
+ const string16& a,
+ const string16& b);
+NSString* GetNSStringF(int message_id,
+ const string16& a,
+ const string16& b,
+ const string16& c);
+NSString* GetNSStringF(int message_id,
+ const string16& a,
+ const string16& b,
+ const string16& c,
+ const string16& d);
+
+// Same as GetNSString, but runs the result through FixUpWindowsStyleLabel
+// before returning it.
+NSString* GetNSStringWithFixup(int message_id);
+
+// Same as GetNSStringF, but runs the result through FixUpWindowsStyleLabel
+// before returning it.
+NSString* GetNSStringFWithFixup(int message_id,
+ const string16& a);
+NSString* GetNSStringFWithFixup(int message_id,
+ const string16& a,
+ const string16& b);
+NSString* GetNSStringFWithFixup(int message_id,
+ const string16& a,
+ const string16& b,
+ const string16& c);
+NSString* GetNSStringFWithFixup(int message_id,
+ const string16& a,
+ const string16& b,
+ const string16& c,
+ const string16& d);
+
+} // namespace l10n_util
+
+#endif // APP_L10N_UTIL_MAC_H_
diff --git a/app/l10n_util_mac.mm b/app/l10n_util_mac.mm
new file mode 100644
index 0000000..a664eb3
--- /dev/null
+++ b/app/l10n_util_mac.mm
@@ -0,0 +1,106 @@
+// 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 <Foundation/Foundation.h>
+#include "app/l10n_util_mac.h"
+#include "base/sys_string_conversions.h"
+
+namespace l10n_util {
+
+// Remove the Windows-style accelerator marker and change "..." into an
+// ellipsis. Returns the result in an autoreleased NSString.
+NSString* FixUpWindowsStyleLabel(const string16& label) {
+ const char16 kEllipsisUTF16 = 0x2026;
+ string16 ret;
+ size_t label_len = label.length();
+ ret.reserve(label_len);
+ for (size_t i = 0; i < label_len; ++i) {
+ char16 c = label[i];
+ if (c == '&') {
+ if (i + 1 < label_len && label[i + 1] == '&') {
+ ret.push_back(c);
+ ++i;
+ }
+ } else if (c == '.' && i + 2 < label_len && label[i + 1] == '.'
+ && label[i + 2] == '.') {
+ ret.push_back(kEllipsisUTF16);
+ i += 2;
+ } else {
+ ret.push_back(c);
+ }
+ }
+
+ return base::SysUTF16ToNSString(ret);
+}
+
+NSString* GetNSString(int message_id) {
+ return base::SysUTF16ToNSString(l10n_util::GetStringUTF16(message_id));
+}
+
+NSString* GetNSStringF(int message_id,
+ const string16& a) {
+ return base::SysUTF16ToNSString(l10n_util::GetStringFUTF16(message_id,
+ a));
+}
+
+NSString* GetNSStringF(int message_id,
+ const string16& a,
+ const string16& b) {
+ return base::SysUTF16ToNSString(l10n_util::GetStringFUTF16(message_id,
+ a, b));
+}
+
+NSString* GetNSStringF(int message_id,
+ const string16& a,
+ const string16& b,
+ const string16& c) {
+ return base::SysUTF16ToNSString(l10n_util::GetStringFUTF16(message_id,
+ a, b, c));
+}
+
+NSString* GetNSStringF(int message_id,
+ const string16& a,
+ const string16& b,
+ const string16& c,
+ const string16& d) {
+ return base::SysUTF16ToNSString(l10n_util::GetStringFUTF16(message_id,
+ a, b, c, d));
+}
+
+NSString* GetNSStringWithFixup(int message_id) {
+ return FixUpWindowsStyleLabel(l10n_util::GetStringUTF16(message_id));
+}
+
+NSString* GetNSStringFWithFixup(int message_id,
+ const string16& a) {
+ return FixUpWindowsStyleLabel(l10n_util::GetStringFUTF16(message_id,
+ a));
+}
+
+NSString* GetNSStringFWithFixup(int message_id,
+ const string16& a,
+ const string16& b) {
+ return FixUpWindowsStyleLabel(l10n_util::GetStringFUTF16(message_id,
+ a, b));
+}
+
+NSString* GetNSStringFWithFixup(int message_id,
+ const string16& a,
+ const string16& b,
+ const string16& c) {
+ return FixUpWindowsStyleLabel(l10n_util::GetStringFUTF16(message_id,
+ a, b, c));
+}
+
+NSString* GetNSStringFWithFixup(int message_id,
+ const string16& a,
+ const string16& b,
+ const string16& c,
+ const string16& d) {
+ return FixUpWindowsStyleLabel(l10n_util::GetStringFUTF16(message_id,
+ a, b, c, d));
+}
+
+
+} // namespace l10n_util
diff --git a/chrome/browser/cocoa/ui_localizer_unittest.mm b/app/l10n_util_mac_unittest.mm
index a6756a9..e6c4485 100644
--- a/chrome/browser/cocoa/ui_localizer_unittest.mm
+++ b/app/l10n_util_mac_unittest.mm
@@ -5,13 +5,13 @@
#import <Foundation/Foundation.h>
#include "base/sys_string_conversions.h"
-#include "chrome/browser/cocoa/ui_localizer.h"
+#include "app/l10n_util_mac.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/platform_test.h"
-typedef PlatformTest UILocalizerTest;
+typedef PlatformTest L10nUtilMacTest;
-TEST_F(UILocalizerTest, FixUpWindowsStyleLabel) {
+TEST_F(L10nUtilMacTest, FixUpWindowsStyleLabel) {
struct TestData {
NSString* input;
NSString* output;
@@ -36,7 +36,7 @@ TEST_F(UILocalizerTest, FixUpWindowsStyleLabel) {
for (size_t idx = 0; idx < ARRAYSIZE_UNSAFE(data); ++idx) {
string16 input16(base::SysNSStringToUTF16(data[idx].input));
- NSString* result = ui_localizer::FixUpWindowsStyleLabel(input16);
+ NSString* result = l10n_util::FixUpWindowsStyleLabel(input16);
EXPECT_TRUE(result != nil) << "Fixup Failed, idx = " << idx;
EXPECT_TRUE([data[idx].output isEqualTo:result])
diff --git a/chrome/browser/cocoa/ui_localizer.h b/chrome/browser/cocoa/ui_localizer.h
index 36efc59..50c480a 100644
--- a/chrome/browser/cocoa/ui_localizer.h
+++ b/chrome/browser/cocoa/ui_localizer.h
@@ -13,10 +13,6 @@
namespace ui_localizer {
-// Remove the Windows-style accelerator marker and change "..." into an
-// ellipsis. Returns the result in an autoreleased NSString.
-NSString* FixUpWindowsStyleLabel(const string16& label);
-
struct ResourceMap {
const char* const name;
unsigned int label_id;
diff --git a/chrome/browser/cocoa/ui_localizer.mm b/chrome/browser/cocoa/ui_localizer.mm
index 5467203..7fd4d44 100644
--- a/chrome/browser/cocoa/ui_localizer.mm
+++ b/chrome/browser/cocoa/ui_localizer.mm
@@ -6,36 +6,12 @@
#import <Foundation/Foundation.h>
-#include "app/l10n_util.h"
+#include "app/l10n_util_mac.h"
#include "base/sys_string_conversions.h"
#include "base/logging.h"
namespace ui_localizer {
-NSString* FixUpWindowsStyleLabel(const string16& label) {
- const char16 kEllipsisUTF16 = 0x2026;
- string16 ret;
- size_t label_len = label.length();
- ret.reserve(label_len);
- for (size_t i = 0; i < label_len; ++i) {
- char16 c = label[i];
- if (c == '&') {
- if (i + 1 < label_len && label[i + 1] == '&') {
- ret.push_back(c);
- ++i;
- }
- } else if (c == '.' && i + 2 < label_len && label[i + 1] == '.'
- && label[i + 2] == '.') {
- ret.push_back(kEllipsisUTF16);
- i += 2;
- } else {
- ret.push_back(c);
- }
- }
-
- return base::SysUTF16ToNSString(ret);
-}
-
NSString* LocalizedStringForKeyFromMapList(NSString* key,
const ResourceMap* map_list,
size_t map_list_len) {
@@ -54,12 +30,11 @@ NSString* LocalizedStringForKeyFromMapList(NSString* key,
if (map_list[i].label_arg_id != 0) {
const string16 label_arg(
l10n_util::GetStringUTF16(map_list[i].label_arg_id));
- return FixUpWindowsStyleLabel(
- l10n_util::GetStringFUTF16(map_list[i].label_id, label_arg));
+ return l10n_util::GetNSStringFWithFixup(map_list[i].label_id,
+ label_arg);
}
- return FixUpWindowsStyleLabel(
- l10n_util::GetStringUTF16(map_list[i].label_id));
+ return l10n_util::GetNSStringWithFixup(map_list[i].label_id);
}
// If we've passed where the string would be, give up.
diff --git a/chrome/browser/tab_contents/render_view_context_menu_mac.mm b/chrome/browser/tab_contents/render_view_context_menu_mac.mm
index 0004750..3a1a9af 100644
--- a/chrome/browser/tab_contents/render_view_context_menu_mac.mm
+++ b/chrome/browser/tab_contents/render_view_context_menu_mac.mm
@@ -4,10 +4,9 @@
#include "chrome/browser/tab_contents/render_view_context_menu_mac.h"
-#include "app/l10n_util.h"
+#include "app/l10n_util_mac.h"
#include "base/compiler_specific.h"
#include "base/sys_string_conversions.h"
-#import "chrome/browser/cocoa/ui_localizer.h"
#include "chrome/browser/profile.h"
#include "grit/generated_resources.h"
#include "base/scoped_nsobject.h"
@@ -71,7 +70,7 @@ void RenderViewContextMenuMac::DoInit() {
// and middle-truncate?
NSString* RenderViewContextMenuMac::PrepareLabelForDisplay(
const string16& label) {
- NSString* title = ui_localizer::FixUpWindowsStyleLabel(label);
+ NSString* title = l10n_util::FixUpWindowsStyleLabel(label);
DCHECK(title);
return title ? title : @"";
}
diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp
index a4bda02..9eabb03 100644
--- a/chrome/chrome.gyp
+++ b/chrome/chrome.gyp
@@ -3783,7 +3783,6 @@
'browser/cocoa/toolbar_button_cell_unittest.mm',
'browser/cocoa/toolbar_controller_unittest.mm',
'browser/cocoa/toolbar_view_unittest.mm',
- 'browser/cocoa/ui_localizer_unittest.mm',
'browser/cocoa/view_resizer_pong.h',
'browser/cocoa/view_resizer_pong.mm',
'browser/cocoa/web_drop_target_unittest.mm',