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

Unified Diff: chrome/renderer/translate_helper.cc

Issue 11052002: Get the document language directly from WebKit (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Reduced patch that only expects langauge from http-equiv setting. Created 8 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/renderer/translate_helper.h ('k') | chrome/renderer/translate_helper_browsertest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/renderer/translate_helper.cc
diff --git a/chrome/renderer/translate_helper.cc b/chrome/renderer/translate_helper.cc
old mode 100644
new mode 100755
index fcbc3c7bd5cee7a114f82532a5b62581e5b1f55a..e2d23bf25baec9cc2e0073ddbbb04ff4a782ede6
--- a/chrome/renderer/translate_helper.cc
+++ b/chrome/renderer/translate_helper.cc
@@ -9,6 +9,7 @@
#include "base/logging.h"
#include "base/message_loop.h"
#include "base/metrics/histogram.h"
+#include "base/string16.h"
#include "base/utf_string_conversions.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/render_messages.h"
@@ -60,9 +61,25 @@ TranslateHelper::~TranslateHelper() {
void TranslateHelper::PageCaptured(const string16& contents) {
WebDocument document = render_view()->GetWebView()->mainFrame()->document();
- // If the page explicitly specifies a language, use it, otherwise we'll
- // determine it based on the text content using the CLD.
- std::string language = GetPageLanguageFromMetaTag(&document);
+
+ // Get the document language as set by WebKit from the http-equiv
+ // meta tag for "content-language". This may or may not also
+ // have a value derived from the actual Content-Language HTTP
+ // header. The two actually have different meanings (despite the
+ // original intent of http-equiv to be an equivalent) with the former
+ // being the language of the document and the latter being the
+ // language of the intended audience (a distinction really only
+ // relevant for things like langauge textbooks). This distinction
+ // shouldn't affect translation.
+ std::string language = document.contentLanguage().utf8();
+ size_t coma_index = language.find(',');
+ if (coma_index != std::string::npos) {
+ // There are more than 1 language specified, just keep the first one.
+ language = language.substr(0, coma_index);
+ }
+ TrimWhitespaceASCII(language, TRIM_ALL, &language);
+ language = StringToLowerASCII(language);
+
if (language.empty()) {
base::TimeTicks begin_time = base::TimeTicks::Now();
language = DetermineTextLanguage(contents);
@@ -105,40 +122,6 @@ bool TranslateHelper::IsPageTranslatable(WebDocument* document) {
}
// static
-std::string TranslateHelper::GetPageLanguageFromMetaTag(WebDocument* document) {
- // The META language tag looks like:
- // <meta http-equiv="content-language" content="en">
- // It can contain more than one language:
- // <meta http-equiv="content-language" content="en, fr">
- std::vector<WebElement> meta_elements;
- webkit_glue::GetMetaElementsWithAttribute(document,
- ASCIIToUTF16("http-equiv"),
- ASCIIToUTF16("content-language"),
- &meta_elements);
- if (meta_elements.empty())
- return std::string();
-
- // We don't expect more than one such tag. If there are several, just use the
- // first one.
- WebString attribute = meta_elements[0].getAttribute("content");
- if (attribute.isEmpty())
- return std::string();
-
- // The value is supposed to be ASCII.
- if (!IsStringASCII(attribute))
- return std::string();
-
- std::string language = StringToLowerASCII(UTF16ToASCII(attribute));
- size_t coma_index = language.find(',');
- if (coma_index != std::string::npos) {
- // There are more than 1 language specified, just keep the first one.
- language = language.substr(0, coma_index);
- }
- TrimWhitespaceASCII(language, TRIM_ALL, &language);
- return language;
-}
-
-// static
std::string TranslateHelper::DetermineTextLanguage(const string16& text) {
std::string language = chrome::kUnknownLanguageCode;
int num_languages = 0;
« no previous file with comments | « chrome/renderer/translate_helper.h ('k') | chrome/renderer/translate_helper_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698