diff options
author | jcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-02 08:23:53 +0000 |
---|---|---|
committer | jcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-02 08:23:53 +0000 |
commit | 13c0fb1a4d5d83149dbccd2001f7828dbdb5473b (patch) | |
tree | 6ccf0dab37a7010a36fe4a33c09fbc35df7ce982 /chrome/browser/renderer_host/translation_service.cc | |
parent | 96721067675b115fec50d299302fb2ec08de394d (diff) | |
download | chromium_src-13c0fb1a4d5d83149dbccd2001f7828dbdb5473b.zip chromium_src-13c0fb1a4d5d83149dbccd2001f7828dbdb5473b.tar.gz chromium_src-13c0fb1a4d5d83149dbccd2001f7828dbdb5473b.tar.bz2 |
Translating from the English locale would translate to Afrikaans.
This is because the English locale 'en-US' would not match the English
language code 'en' and we would default to the 1st language, Afrikaan.
BUG=None
TEST=Test that translate when Chrome is configured in English (US and UK),
Spanish, Portuguese (Brazil and Portugal) does translate to the
language Chrome is configured to be in.
TBR=kuan
Review URL: http://codereview.chromium.org/563005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@37813 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/renderer_host/translation_service.cc')
-rw-r--r-- | chrome/browser/renderer_host/translation_service.cc | 31 |
1 files changed, 14 insertions, 17 deletions
diff --git a/chrome/browser/renderer_host/translation_service.cc b/chrome/browser/renderer_host/translation_service.cc index 8f37e35..f3512e7 100644 --- a/chrome/browser/renderer_host/translation_service.cc +++ b/chrome/browser/renderer_host/translation_service.cc @@ -33,8 +33,8 @@ const char kFormatParam[] = "format"; const char kSSLParam[] = "ssl"; const char kTranslationCountParam[] = "tc"; -// Describes languages deemed equivalent from a translation point of view. -// This is used to detect unnecessary translations. +// Mapping from a locale name to a language code name. +// Locale names not included are translated as is. struct LocaleToCLDLanguage { const char* locale_language; // Language Chrome locale is in. const char* cld_language; // Language the CLD reports. @@ -43,6 +43,8 @@ LocaleToCLDLanguage kLocaleToCLDLanguages[] = { { "en-GB", "en" }, { "en-US", "en" }, { "es-419", "es" }, + { "pt-PT", "pt" }, + { "pt-BR", "pt" }, }; // The list of languages the Google translation server supports. @@ -385,21 +387,6 @@ void TranslationService::OnURLFetchComplete(const URLFetcher* source, } // static -bool TranslationService::ShouldTranslatePage( - const std::string& page_language, const std::string& chrome_language) { - // Most locale names are the actual ISO 639 codes that the Google translate - // API uses, but for the ones longer than 2 chars. - // See l10n_util.cc for the list. - for (size_t i = 0; i < arraysize(kLocaleToCLDLanguages); ++i) { - if (chrome_language == kLocaleToCLDLanguages[i].locale_language && - page_language == kLocaleToCLDLanguages[i].cld_language) { - return false; - } - } - return true; -} - -// static bool TranslationService::IsTranslationEnabled() { return GURL(kServiceURL).host() != "disabled"; } @@ -412,6 +399,16 @@ void TranslationService::GetSupportedLanguages( languages->push_back(kSupportedLanguages[i]); } +// static +std::string TranslationService::GetLanguageCode( + const std::string& chrome_locale) { + for (size_t i = 0; i < arraysize(kLocaleToCLDLanguages); ++i) { + if (chrome_locale == kLocaleToCLDLanguages[i].locale_language) + return kLocaleToCLDLanguages[i].cld_language; + } + return chrome_locale; +} + //////////////////////////////////////////////////////////////////////////////// // TranslationService, protected: |