diff options
author | thomasvl@chromium.org <thomasvl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-07 19:26:36 +0000 |
---|---|---|
committer | thomasvl@chromium.org <thomasvl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-07 19:26:36 +0000 |
commit | aff5eec98954766821f46a7e9fab07b7007f0319 (patch) | |
tree | f1f93210978317adc3ca097e49486cf79035c389 /app/l10n_util_mac.mm | |
parent | 086eaec4d8ed6b6207925253f17fdabef82a0ed7 (diff) | |
download | chromium_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
Diffstat (limited to 'app/l10n_util_mac.mm')
-rw-r--r-- | app/l10n_util_mac.mm | 106 |
1 files changed, 106 insertions, 0 deletions
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 |