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

Unified Diff: chrome/renderer/render_view.cc

Issue 523108: Port back CLD to Linux and Mac and fix Trad Chinese detection (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 11 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
Index: chrome/renderer/render_view.cc
===================================================================
--- chrome/renderer/render_view.cc (revision 36529)
+++ chrome/renderer/render_view.cc (working copy)
@@ -67,10 +67,7 @@
#include "net/base/net_errors.h"
#include "skia/ext/bitmap_platform_device.h"
#include "skia/ext/image_operations.h"
-#if defined(OS_WIN)
-// TODO(port): The compact language detection library works only for Windows.
#include "third_party/cld/bar/toolbar/cld/i18n/encodings/compact_lang_det/win/cld_unicodetext.h"
-#endif
#include "third_party/WebKit/WebKit/chromium/public/WebAccessibilityCache.h"
#include "third_party/WebKit/WebKit/chromium/public/WebAccessibilityObject.h"
#include "third_party/WebKit/WebKit/chromium/public/WebCString.h"
@@ -223,7 +220,7 @@
static const char* const kBackForwardNavigationScheme = "history";
// The string returned in DetectLanguage if we failed to detect the language.
-static const char* const kUnknownLanguageCode = "unknown";
+static const char* const kUnknownLanguageCode = "und";
static void GetRedirectChain(WebDataSource* ds, std::vector<GURL>* result) {
WebVector<WebURL> urls;
@@ -3082,31 +3079,29 @@
if (!webview() || is_loading_)
return kUnknownLanguageCode;
- std::string language = kUnknownLanguageCode;
-#if defined(OS_WIN) // CLD is only available on Windows at this time.
WebFrame* main_frame = webview()->mainFrame();
std::wstring contents;
CaptureText(main_frame, &contents);
- language = DetermineTextLanguage(contents);
-#endif
-
- return language;
+ return DetermineTextLanguage(contents);
}
// static
std::string RenderView::DetermineTextLanguage(const std::wstring& text) {
std::string language = kUnknownLanguageCode;
-#if defined(OS_WIN) // CLD is only available on Windows at this time.
int num_languages = 0;
bool is_reliable = false;
+ string16 input = WideToUTF16(text);
Language cld_language =
- DetectLanguageOfUnicodeText(NULL, text.c_str(), true, &is_reliable,
+ DetectLanguageOfUnicodeText(NULL, input.c_str(), true, &is_reliable,
&num_languages, NULL);
if (cld_language != NUM_LANGUAGES && cld_language != UNKNOWN_LANGUAGE &&
cld_language != TG_UNKNOWN_LANGUAGE) {
- language = LanguageCodeISO639_1(cld_language);
+ // We should not LanguageCode_ISO_639_1 because it does not cover all the
+ // languages CLD can detect. As a result, it'll return the invalid language
+ // code for tradtional Chinese among others. |LanguageCode| will go through
+ // ISO 639-1, ISO-639-2 and 'other' tables to do the 'right' thing.
+ language = LanguageCode(cld_language);
}
-#endif
return language;
}

Powered by Google App Engine
This is Rietveld 408576698