Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(137)

Side by Side Diff: chrome/browser/translate/translate_infobars_delegates.cc

Issue 597042: Translate: Move label parsing logic into common code. (Closed)
Patch Set: Fix indentation. Created 10 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/translate/translate_infobars_delegates.h" 5 #include "chrome/browser/translate/translate_infobars_delegates.h"
6 6
7 #include "app/l10n_util.h" 7 #include "app/l10n_util.h"
8 #include "app/resource_bundle.h" 8 #include "app/resource_bundle.h"
9 #include "chrome/browser/browser_process.h" 9 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/renderer_host/translation_service.h" 10 #include "chrome/browser/renderer_host/translation_service.h"
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 if (always_translate_) 151 if (always_translate_)
152 prefs_.WhitelistLanguagePair(original_lang_code(), target_lang_code()); 152 prefs_.WhitelistLanguagePair(original_lang_code(), target_lang_code());
153 else 153 else
154 prefs_.RemoveLanguagePairFromWhitelist(original_lang_code(), 154 prefs_.RemoveLanguagePairFromWhitelist(original_lang_code(),
155 target_lang_code()); 155 target_lang_code());
156 } else { 156 } else {
157 NOTREACHED() << "Invalid mehod called for translate state"; 157 NOTREACHED() << "Invalid mehod called for translate state";
158 } 158 }
159 } 159 }
160 160
161 void TranslateInfoBarDelegate::GetMessageText(string16 *message_text,
162 std::vector<size_t> *offsets, bool *swapped_language_placeholders) {
163 *swapped_language_placeholders = false;
164 offsets->clear();
165
166 std::vector<size_t> offsets_tmp;
167 int message_resource_id = IDS_TRANSLATE_INFOBAR_BEFORE_MESSAGE;
168 if (state() == kAfterTranslate)
169 message_resource_id = IDS_TRANSLATE_INFOBAR_AFTER_MESSAGE;
170 *message_text = l10n_util::GetStringFUTF16(message_resource_id,
171 string16(), string16(), &offsets_tmp);
172
173 if (offsets_tmp.empty() || offsets_tmp.size() > 2) {
174 NOTREACHED() << "Invalid no. of placeholders in label.";
175 return;
176 }
177 // Sort the offsets if necessary.
178 if (offsets_tmp.size() == 2 && offsets_tmp[0] > offsets_tmp[1]) {
179 size_t offset0 = offsets_tmp[0];
180 offsets_tmp[0] = offsets_tmp[1];
181 offsets_tmp[1] = offset0;
182 *swapped_language_placeholders = true;
183 }
184 if (offsets_tmp[offsets_tmp.size() - 1] != message_text->length())
185 offsets_tmp.push_back(message_text->length());
186 *offsets = offsets_tmp;
187 }
188
161 // TranslateInfoBarDelegate: static: ------------------------------------------- 189 // TranslateInfoBarDelegate: static: -------------------------------------------
162 190
163 string16 TranslateInfoBarDelegate::GetDisplayNameForLocale( 191 string16 TranslateInfoBarDelegate::GetDisplayNameForLocale(
164 const std::string& language_code) { 192 const std::string& language_code) {
165 return l10n_util::GetDisplayNameForLocale( 193 return l10n_util::GetDisplayNameForLocale(
166 language_code, g_browser_process->GetApplicationLocale(), true); 194 language_code, g_browser_process->GetApplicationLocale(), true);
167 } 195 }
168 196
169 #if !defined(TOOLKIT_VIEWS) 197 #if !defined(TOOLKIT_VIEWS)
170 // TranslateInfoBarDelegate: InfoBarDelegate overrides: ------------------------ 198 // TranslateInfoBarDelegate: InfoBarDelegate overrides: ------------------------
171 199
172 InfoBar* TranslateInfoBarDelegate::CreateInfoBar() { 200 InfoBar* TranslateInfoBarDelegate::CreateInfoBar() {
173 NOTIMPLEMENTED(); 201 NOTIMPLEMENTED();
174 return NULL; 202 return NULL;
175 } 203 }
176 #endif // !TOOLKIT_VIEWS 204 #endif // !TOOLKIT_VIEWS
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698