summaryrefslogtreecommitdiffstats
path: root/chrome/browser/translate
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/translate')
-rw-r--r--chrome/browser/translate/translate_infobars_delegates.cc28
-rw-r--r--chrome/browser/translate/translate_infobars_delegates.h15
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;