OLD | NEW |
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_manager.h" | 5 #include "chrome/browser/translate/translate_manager.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/memory/singleton.h" | 10 #include "base/memory/singleton.h" |
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
431 | 431 |
432 // Don't translate any Chrome specific page, e.g., New Tab Page, Download, | 432 // Don't translate any Chrome specific page, e.g., New Tab Page, Download, |
433 // History, and so on. | 433 // History, and so on. |
434 GURL page_url = web_contents->GetURL(); | 434 GURL page_url = web_contents->GetURL(); |
435 if (!IsTranslatableURL(page_url)) { | 435 if (!IsTranslatableURL(page_url)) { |
436 TranslateBrowserMetrics::ReportInitiationStatus( | 436 TranslateBrowserMetrics::ReportInitiationStatus( |
437 TranslateBrowserMetrics::INITIATION_STATUS_URL_IS_NOT_SUPPORTED); | 437 TranslateBrowserMetrics::INITIATION_STATUS_URL_IS_NOT_SUPPORTED); |
438 return; | 438 return; |
439 } | 439 } |
440 | 440 |
441 // Don't translate similar languages (ex: en-US to en). | |
442 std::string target_lang = GetTargetLanguage(prefs); | 441 std::string target_lang = GetTargetLanguage(prefs); |
443 std::string language_code = GetLanguageCode(page_lang); | 442 std::string language_code = GetLanguageCode(page_lang); |
444 if (language_code == target_lang) { | |
445 TranslateBrowserMetrics::ReportInitiationStatus( | |
446 TranslateBrowserMetrics::INITIATION_STATUS_SIMILAR_LANGUAGES); | |
447 return; | |
448 } | |
449 | 443 |
450 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 444 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
451 | 445 |
| 446 // Don't translate similar languages (ex: en-US to en). |
| 447 // When the flag --enable-translate-settings is on, the locale (|target_lang|) |
| 448 // is not needed to be considered because the user can configure the languages |
| 449 // in the settings UI. |
| 450 if (!command_line->HasSwitch(switches::kEnableTranslateSettings)) { |
| 451 if (language_code == target_lang) { |
| 452 TranslateBrowserMetrics::ReportInitiationStatus( |
| 453 TranslateBrowserMetrics::INITIATION_STATUS_SIMILAR_LANGUAGES); |
| 454 return; |
| 455 } |
| 456 } |
| 457 |
452 // Don't translate any language the user configured as accepted languages. | 458 // Don't translate any language the user configured as accepted languages. |
453 // When the flag --enable-translate-settings is on, the condition is | 459 // When the flag --enable-translate-settings is on, the condition is |
454 // different. In this case, even though a language is an Accept language, | 460 // different. In this case, even though a language is an Accept language, |
455 // it could be translated due to the blacklist. | 461 // it could be translated due to the blacklist. |
456 if (!command_line->HasSwitch(switches::kEnableTranslateSettings) && | 462 if (!command_line->HasSwitch(switches::kEnableTranslateSettings) && |
457 accept_languages_->IsAcceptLanguage(original_profile, language_code)) { | 463 accept_languages_->IsAcceptLanguage(original_profile, language_code)) { |
458 TranslateBrowserMetrics::ReportInitiationStatus( | 464 TranslateBrowserMetrics::ReportInitiationStatus( |
459 TranslateBrowserMetrics::INITIATION_STATUS_ACCEPT_LANGUAGES); | 465 TranslateBrowserMetrics::INITIATION_STATUS_ACCEPT_LANGUAGES); |
460 return; | 466 return; |
461 } | 467 } |
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
798 // reason so we are more aggressive showing the shortcuts for never translate. | 804 // reason so we are more aggressive showing the shortcuts for never translate. |
799 #if defined(OS_ANDROID) | 805 #if defined(OS_ANDROID) |
800 config.never_translate_min_count = 1; | 806 config.never_translate_min_count = 1; |
801 #else | 807 #else |
802 config.never_translate_min_count = 3; | 808 config.never_translate_min_count = 3; |
803 #endif // defined(OS_ANDROID) | 809 #endif // defined(OS_ANDROID) |
804 | 810 |
805 config.always_translate_min_count = 3; | 811 config.always_translate_min_count = 3; |
806 return config; | 812 return config; |
807 } | 813 } |
OLD | NEW |