diff options
author | jeremy@chromium.org <jeremy@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-17 07:49:53 +0000 |
---|---|---|
committer | jeremy@chromium.org <jeremy@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-17 07:49:53 +0000 |
commit | 2e59325fed2416cd23d0b418cd46e302148aa584 (patch) | |
tree | 12a5fa4d92c38c32b4e03a8df4a55a8688f1e449 /chrome/browser/translate | |
parent | 3e52d7d6df02b80809826c8a68b897d337ec8f94 (diff) | |
download | chromium_src-2e59325fed2416cd23d0b418cd46e302148aa584.zip chromium_src-2e59325fed2416cd23d0b418cd46e302148aa584.tar.gz chromium_src-2e59325fed2416cd23d0b418cd46e302148aa584.tar.bz2 |
Translate: Move label parsing logic into common code.
* Add a string16 & Cocoa version of GetStringF().
* Move logic for parsing translate infobar label into translate_infobars_delegates.
* Make views variant of translate infobars use new code.
BUG=34466
TEST=Translate infobars should continue to workon Windows.
Review URL: http://codereview.chromium.org/597042
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@39206 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/translate')
-rw-r--r-- | chrome/browser/translate/translate_infobars_delegates.cc | 28 | ||||
-rw-r--r-- | chrome/browser/translate/translate_infobars_delegates.h | 15 |
2 files changed, 43 insertions, 0 deletions
diff --git a/chrome/browser/translate/translate_infobars_delegates.cc b/chrome/browser/translate/translate_infobars_delegates.cc index ed86b6c..06d7da8 100644 --- a/chrome/browser/translate/translate_infobars_delegates.cc +++ b/chrome/browser/translate/translate_infobars_delegates.cc @@ -158,6 +158,34 @@ void TranslateInfoBarDelegate::ToggleAlwaysTranslate() { } } +void TranslateInfoBarDelegate::GetMessageText(string16 *message_text, + std::vector<size_t> *offsets, bool *swapped_language_placeholders) { + *swapped_language_placeholders = false; + offsets->clear(); + + std::vector<size_t> offsets_tmp; + int message_resource_id = IDS_TRANSLATE_INFOBAR_BEFORE_MESSAGE; + if (state() == kAfterTranslate) + message_resource_id = IDS_TRANSLATE_INFOBAR_AFTER_MESSAGE; + *message_text = l10n_util::GetStringFUTF16(message_resource_id, + string16(), string16(), &offsets_tmp); + + if (offsets_tmp.empty() || offsets_tmp.size() > 2) { + NOTREACHED() << "Invalid no. of placeholders in label."; + return; + } + // Sort the offsets if necessary. + if (offsets_tmp.size() == 2 && offsets_tmp[0] > offsets_tmp[1]) { + size_t offset0 = offsets_tmp[0]; + offsets_tmp[0] = offsets_tmp[1]; + offsets_tmp[1] = offset0; + *swapped_language_placeholders = true; + } + if (offsets_tmp[offsets_tmp.size() - 1] != message_text->length()) + offsets_tmp.push_back(message_text->length()); + *offsets = offsets_tmp; +} + // TranslateInfoBarDelegate: static: ------------------------------------------- string16 TranslateInfoBarDelegate::GetDisplayNameForLocale( diff --git a/chrome/browser/translate/translate_infobars_delegates.h b/chrome/browser/translate/translate_infobars_delegates.h index 311b847..ceeda17 100644 --- a/chrome/browser/translate/translate_infobars_delegates.h +++ b/chrome/browser/translate/translate_infobars_delegates.h @@ -60,6 +60,21 @@ class TranslateInfoBarDelegate : public InfoBarDelegate { return state_; } + // Retrieve the text for the toolbar label. The toolbar label is a bit + // strange since we need to place popup menus inside the string in question. + // To do this we use two placeholders. + // + // |message_text| is the text to display for the label. + // |offsets| contains the offsets of the number of placeholders in the text + // + message_text->length() i.e. it can contain 2 or 3 elements. + // offsets[0] < offsets[1] even in cases where the languages need to be + // displayed in reverse order. + // |swapped_language_placeholders| is true if we need to flip the order + // of the menus in the current locale. + void GetMessageText(string16 *message_text, + std::vector<size_t> *offsets, + bool *swapped_language_placeholders); + // Overridden from InfoBarDelegate. virtual Type GetInfoBarType() { return PAGE_ACTION_TYPE; |