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

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

Issue 15297006: Translate (Linux): add after infobar UI for server side language detection (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: renaming Created 7 years, 7 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_infobar_delegate.h" 5 #include "chrome/browser/translate/translate_infobar_delegate.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/i18n/string_compare.h" 9 #include "base/i18n/string_compare.h"
10 #include "base/metrics/histogram.h" 10 #include "base/metrics/histogram.h"
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 273
274 // static 274 // static
275 string16 TranslateInfoBarDelegate::GetLanguageDisplayableName( 275 string16 TranslateInfoBarDelegate::GetLanguageDisplayableName(
276 const std::string& language_code) { 276 const std::string& language_code) {
277 return l10n_util::GetDisplayNameForLocale( 277 return l10n_util::GetDisplayNameForLocale(
278 language_code, g_browser_process->GetApplicationLocale(), true); 278 language_code, g_browser_process->GetApplicationLocale(), true);
279 } 279 }
280 280
281 // static 281 // static
282 void TranslateInfoBarDelegate::GetAfterTranslateStrings( 282 void TranslateInfoBarDelegate::GetAfterTranslateStrings(
283 std::vector<string16>* strings, bool* swap_languages) { 283 std::vector<string16>* strings,
284 DCHECK(strings); 284 bool* swap_languages,
285 DCHECK(swap_languages); 285 bool autodetermined_source_language) {
286
287 std::vector<size_t> offsets;
288 string16 text =
289 l10n_util::GetStringFUTF16(IDS_TRANSLATE_INFOBAR_AFTER_MESSAGE,
290 string16(), string16(), &offsets);
291 DCHECK_EQ(2U, offsets.size());
292
293 *swap_languages = (offsets[0] > offsets[1]);
294 if (*swap_languages)
295 std::swap(offsets[0], offsets[1]);
296
297 strings->push_back(text.substr(0, offsets[0]));
298 strings->push_back(text.substr(offsets[0], offsets[1] - offsets[0]));
299 strings->push_back(text.substr(offsets[1]));
300 }
301
302 // static
303 void TranslateInfoBarDelegate::GetAfterTranslateWithAutoStrings(
304 std::vector<string16>* strings) {
305 DCHECK(strings); 286 DCHECK(strings);
306 287
307 size_t offset; 288 if (autodetermined_source_language) {
308 string16 text = 289 size_t offset;
309 l10n_util::GetStringFUTF16(IDS_TRANSLATE_INFOBAR_AFTER_MESSAGE_WITH_AUTO, 290 string16 text = l10n_util::GetStringFUTF16(
310 string16(), &offset); 291 IDS_TRANSLATE_INFOBAR_AFTER_MESSAGE_AUTODETERMINED_SOURCE_LANGUAGE,
292 string16(),
293 &offset);
311 294
312 strings->push_back(text.substr(0, offset)); 295 strings->push_back(text.substr(0, offset));
313 strings->push_back(text.substr(offset)); 296 strings->push_back(text.substr(offset));
297 } else {
Peter Kasting 2013/05/23 19:59:56 Tiny nit: Might be better to early-return here so
Takashi Toyoshima 2013/05/27 06:07:51 Done.
298 DCHECK(swap_languages);
299
300 std::vector<size_t> offsets;
301 string16 text = l10n_util::GetStringFUTF16(
302 IDS_TRANSLATE_INFOBAR_AFTER_MESSAGE,
303 string16(),
304 string16(),
305 &offsets);
306 DCHECK_EQ(2U, offsets.size());
307
308 *swap_languages = (offsets[0] > offsets[1]);
309 if (*swap_languages)
310 std::swap(offsets[0], offsets[1]);
311
312 strings->push_back(text.substr(0, offsets[0]));
313 strings->push_back(text.substr(offsets[0], offsets[1] - offsets[0]));
314 strings->push_back(text.substr(offsets[1]));
315 }
314 } 316 }
315 317
316 TranslateInfoBarDelegate::TranslateInfoBarDelegate( 318 TranslateInfoBarDelegate::TranslateInfoBarDelegate(
317 Type infobar_type, 319 Type infobar_type,
318 TranslateErrors::Type error_type, 320 TranslateErrors::Type error_type,
319 InfoBarService* infobar_service, 321 InfoBarService* infobar_service,
320 PrefService* prefs, 322 PrefService* prefs,
321 ShortcutConfiguration shortcut_config, 323 ShortcutConfiguration shortcut_config,
322 const std::string& original_language, 324 const std::string& original_language,
323 const std::string& target_language) 325 const std::string& target_language)
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 403
402 TranslateInfoBarDelegate* 404 TranslateInfoBarDelegate*
403 TranslateInfoBarDelegate::AsTranslateInfoBarDelegate() { 405 TranslateInfoBarDelegate::AsTranslateInfoBarDelegate() {
404 return this; 406 return this;
405 } 407 }
406 408
407 std::string TranslateInfoBarDelegate::GetPageHost() { 409 std::string TranslateInfoBarDelegate::GetPageHost() {
408 NavigationEntry* entry = web_contents()->GetController().GetActiveEntry(); 410 NavigationEntry* entry = web_contents()->GetController().GetActiveEntry();
409 return entry ? entry->GetURL().HostNoBrackets() : std::string(); 411 return entry ? entry->GetURL().HostNoBrackets() : std::string();
410 } 412 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698