summaryrefslogtreecommitdiffstats
path: root/chrome/browser/translate
diff options
context:
space:
mode:
authorkuan@chromium.org <kuan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-02 06:42:11 +0000
committerkuan@chromium.org <kuan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-02 06:42:11 +0000
commit96721067675b115fec50d299302fb2ec08de394d (patch)
treeb3649c6fa7ecbba7f1c65b21bbb76dfa8ec15185 /chrome/browser/translate
parent3919ae943247f31414cd444dab0a053e22226179 (diff)
downloadchromium_src-96721067675b115fec50d299302fb2ec08de394d.zip
chromium_src-96721067675b115fec50d299302fb2ec08de394d.tar.gz
chromium_src-96721067675b115fec50d299302fb2ec08de394d.tar.bz2
implement proper localized display names for translate languages
- in the process, modify to use indexes into vector of languages to communicate between infobars and delegates BUG=31297 TEST=verify that language names in translate infobars' language buttons, dropdown lists and options are properly localized. Review URL: http://codereview.chromium.org/566012 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@37809 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/translate')
-rw-r--r--chrome/browser/translate/languages_menu_model.cc8
-rw-r--r--chrome/browser/translate/options_menu_model.cc15
-rw-r--r--chrome/browser/translate/translate_infobars_delegates.cc119
-rw-r--r--chrome/browser/translate/translate_infobars_delegates.h26
4 files changed, 79 insertions, 89 deletions
diff --git a/chrome/browser/translate/languages_menu_model.cc b/chrome/browser/translate/languages_menu_model.cc
index 3f26d58..ba749df 100644
--- a/chrome/browser/translate/languages_menu_model.cc
+++ b/chrome/browser/translate/languages_menu_model.cc
@@ -1,6 +1,6 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved. Use of this
-// source code is governed by a BSD-style license that can be found in the
-// LICENSE file.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
#include "chrome/browser/translate/languages_menu_model.h"
@@ -24,7 +24,7 @@ LanguagesMenuModel::LanguagesMenuModel(
}
std::vector<std::string>::const_iterator iter = languages.begin();
for (int i = base_command_id; iter != languages.end(); ++i, ++iter) {
- AddItem(i, ASCIIToUTF16(*iter));
+ AddItem(i, TranslateInfoBarDelegate::GetDisplayNameForLocale(*iter));
}
}
diff --git a/chrome/browser/translate/options_menu_model.cc b/chrome/browser/translate/options_menu_model.cc
index 4dfd631..da1f896 100644
--- a/chrome/browser/translate/options_menu_model.cc
+++ b/chrome/browser/translate/options_menu_model.cc
@@ -1,6 +1,6 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved. Use of this
-// source code is governed by a BSD-style license that can be found in the
-// LICENSE file.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
#include "chrome/browser/translate/options_menu_model.h"
@@ -13,7 +13,8 @@ OptionsMenuModel::OptionsMenuModel(menus::SimpleMenuModel::Delegate* delegate,
TranslateInfoBarDelegate* translate_delegate, bool before_translate)
: menus::SimpleMenuModel(delegate) {
string16 original_language =
- ASCIIToUTF16(translate_delegate->original_language());
+ TranslateInfoBarDelegate::GetDisplayNameForLocale(
+ translate_delegate->original_lang_code());
if (before_translate) {
AddCheckItem(IDC_TRANSLATE_OPTIONS_NEVER_TRANSLATE_LANG,
l10n_util::GetStringFUTF16(
@@ -23,10 +24,12 @@ OptionsMenuModel::OptionsMenuModel(menus::SimpleMenuModel::Delegate* delegate,
l10n_util::GetStringUTF16(
IDS_TRANSLATE_INFOBAR_OPTIONS_NEVER_TRANSLATE_SITE));
} else {
+ string16 target_language =
+ TranslateInfoBarDelegate::GetDisplayNameForLocale(
+ translate_delegate->target_lang_code());
AddCheckItem(IDC_TRANSLATE_OPTIONS_ALWAYS,
l10n_util::GetStringFUTF16(IDS_TRANSLATE_INFOBAR_OPTIONS_ALWAYS,
- original_language,
- ASCIIToUTF16(translate_delegate->target_language())));
+ original_language, target_language));
}
AddItemWithStringId(IDC_TRANSLATE_OPTIONS_ABOUT,
IDS_TRANSLATE_INFOBAR_OPTIONS_ABOUT);
diff --git a/chrome/browser/translate/translate_infobars_delegates.cc b/chrome/browser/translate/translate_infobars_delegates.cc
index 15d165b..3dba0ca 100644
--- a/chrome/browser/translate/translate_infobars_delegates.cc
+++ b/chrome/browser/translate/translate_infobars_delegates.cc
@@ -6,6 +6,8 @@
#include "app/l10n_util.h"
#include "app/resource_bundle.h"
+#include "chrome/browser/browser_process.h"
+#include "chrome/browser/renderer_host/translation_service.h"
#include "chrome/browser/tab_contents/tab_contents.h"
#include "grit/generated_resources.h"
#include "grit/theme_resources.h"
@@ -30,61 +32,19 @@ void TranslateInfoBarDelegate::InfoBarClosed() {
// TranslateInfoBarDelegate: public: -------------------------------------------
-void TranslateInfoBarDelegate::ModifyOriginalLanguage(
- const std::string& original_language) {
- original_language_ = original_language;
+void TranslateInfoBarDelegate::ModifyOriginalLanguage(int lang_index) {
+ original_lang_index_ = lang_index;
// TODO(kuan): Send stats to Google Translate that original language has been
// modified.
}
-void TranslateInfoBarDelegate::ModifyTargetLanguage(
- const std::string& target_language) {
+void TranslateInfoBarDelegate::ModifyTargetLanguage(int lang_index) {
NOTREACHED() << "Subclass should override";
}
void TranslateInfoBarDelegate::GetAvailableOriginalLanguages(
std::vector<std::string>* languages) {
- // TODO(kuan): Call backend when it's ready; hardcode a list for now.
- languages->push_back("Arabic");
- languages->push_back("Bengali");
- languages->push_back("Bulgarian");
- languages->push_back("Chinese (Simplified Han)");
- languages->push_back("Chinese (Traditional Han)");
- languages->push_back("Croatian");
- languages->push_back("Czech");
- languages->push_back("Danish");
- languages->push_back("Dutch");
- languages->push_back("English");
- languages->push_back("Estonian");
- languages->push_back("Filipino");
- languages->push_back("Finnish");
- languages->push_back("French");
- languages->push_back("German");
- languages->push_back("Greek");
- languages->push_back("Hebrew");
- languages->push_back("Hindi");
- languages->push_back("Hungarian");
- languages->push_back("Indonesian");
- languages->push_back("Italian");
- languages->push_back("Japanese");
- languages->push_back("Korean");
- languages->push_back("Latvian");
- languages->push_back("Lithuanian");
- languages->push_back("Norwegian");
- languages->push_back("Polish");
- languages->push_back("Portuguese");
- languages->push_back("Romanian");
- languages->push_back("Russian");
- languages->push_back("Serbian");
- languages->push_back("Slovak");
- languages->push_back("Slovenian");
- languages->push_back("Spanish");
- languages->push_back("Swedish");
- languages->push_back("Tamil");
- languages->push_back("Thai");
- languages->push_back("Turkish");
- languages->push_back("Ukrainian");
- languages->push_back("Vietnamese");
+ TranslationService::GetSupportedLanguages(languages);
}
void TranslateInfoBarDelegate::GetAvailableTargetLanguages(
@@ -93,7 +53,7 @@ void TranslateInfoBarDelegate::GetAvailableTargetLanguages(
}
void TranslateInfoBarDelegate::Translate() {
- tab_contents_->TranslatePage(original_language_, target_language_);
+ tab_contents_->TranslatePage(original_lang_code(), target_lang_code());
}
bool TranslateInfoBarDelegate::IsLanguageBlacklisted() {
@@ -123,25 +83,46 @@ void TranslateInfoBarDelegate::ToggleAlwaysTranslate() {
NOTREACHED() << "Subclass should override";
}
+// TranslateInfoBarDelegate: static: -------------------------------------------
+
+string16 TranslateInfoBarDelegate::GetDisplayNameForLocale(
+ const std::string& language_code) {
+ return l10n_util::GetDisplayNameForLocale(
+ language_code, g_browser_process->GetApplicationLocale(), true);
+}
+
// TranslateInfoBarDelegate: protected: ----------------------------------------
TranslateInfoBarDelegate::TranslateInfoBarDelegate(TabContents* tab_contents,
- PrefService* user_prefs, const std::string& original_language,
- const std::string& target_language)
+ PrefService* user_prefs, const std::string& original_lang_code,
+ const std::string& target_lang_code)
: InfoBarDelegate(tab_contents),
tab_contents_(tab_contents),
- original_language_(original_language),
- target_language_(target_language),
+ original_lang_index_(0),
+ target_lang_index_(0),
prefs_(user_prefs) {
+ TranslationService::GetSupportedLanguages(&supported_languages_);
+ for (size_t i = 0; i < supported_languages_.size(); ++i) {
+ if (original_lang_code == supported_languages_[i]) {
+ original_lang_index_ = i;
+ break;
+ }
+ }
+ for (size_t i = 0; i < supported_languages_.size(); ++i) {
+ if (target_lang_code == supported_languages_[i]) {
+ target_lang_index_ = i;
+ break;
+ }
+ }
}
// BeforeTranslateInfoBarDelegate: public: -------------------------------------
BeforeTranslateInfoBarDelegate::BeforeTranslateInfoBarDelegate(
TabContents* tab_contents, PrefService* user_prefs, const GURL& url,
- const std::string& original_language, const std::string& target_language)
- : TranslateInfoBarDelegate(tab_contents, user_prefs, original_language,
- target_language),
+ const std::string& original_lang_code, const std::string& target_lang_code)
+ : TranslateInfoBarDelegate(tab_contents, user_prefs, original_lang_code,
+ target_lang_code),
site_(url.HostNoBrackets()),
never_translate_language_(false),
never_translate_site_(false) {
@@ -149,16 +130,16 @@ BeforeTranslateInfoBarDelegate::BeforeTranslateInfoBarDelegate(
bool BeforeTranslateInfoBarDelegate::IsLanguageBlacklisted() {
never_translate_language_ =
- prefs_.IsLanguageBlacklisted(original_language());
+ prefs_.IsLanguageBlacklisted(original_lang_code());
return never_translate_language_;
}
void BeforeTranslateInfoBarDelegate::ToggleLanguageBlacklist() {
never_translate_language_ = !never_translate_language_;
if (never_translate_language_)
- prefs_.BlacklistLanguage(original_language());
+ prefs_.BlacklistLanguage(original_lang_code());
else
- prefs_.RemoveLanguageFromBlacklist(original_language());
+ prefs_.RemoveLanguageFromBlacklist(original_lang_code());
}
bool BeforeTranslateInfoBarDelegate::IsSiteBlacklisted() {
@@ -185,36 +166,34 @@ InfoBar* BeforeTranslateInfoBarDelegate::CreateInfoBar() {
AfterTranslateInfoBarDelegate::AfterTranslateInfoBarDelegate(
TabContents* tab_contents, PrefService* user_prefs,
- const std::string& original_language, const std::string& target_language)
- : TranslateInfoBarDelegate(tab_contents, user_prefs, original_language,
- target_language),
+ const std::string& original_lang_code, const std::string& target_lang_code)
+ : TranslateInfoBarDelegate(tab_contents, user_prefs, original_lang_code,
+ target_lang_code),
always_translate_(false) {
}
void AfterTranslateInfoBarDelegate::GetAvailableTargetLanguages(
std::vector<std::string>* languages) {
- // TODO(kuan): Call backend when it's ready; hardcode a list for now.
- GetAvailableOriginalLanguages(languages);
+ TranslationService::GetSupportedLanguages(languages);
}
-void AfterTranslateInfoBarDelegate::ModifyTargetLanguage(
- const std::string& target_language) {
- target_language_ = target_language;
+void AfterTranslateInfoBarDelegate::ModifyTargetLanguage(int lang_index) {
+ target_lang_index_ = lang_index;
}
bool AfterTranslateInfoBarDelegate::ShouldAlwaysTranslate() {
- always_translate_ = prefs_.IsLanguagePairWhitelisted(original_language(),
- target_language());
+ always_translate_ = prefs_.IsLanguagePairWhitelisted(original_lang_code(),
+ target_lang_code());
return always_translate_;
}
void AfterTranslateInfoBarDelegate::ToggleAlwaysTranslate() {
always_translate_ = !always_translate_;
if (always_translate_)
- prefs_.WhitelistLanguagePair(original_language(), target_language());
+ prefs_.WhitelistLanguagePair(original_lang_code(), target_lang_code());
else
- prefs_.RemoveLanguagePairFromWhitelist(original_language(),
- target_language());
+ prefs_.RemoveLanguagePairFromWhitelist(original_lang_code(),
+ target_lang_code());
}
#if !defined(TOOLKIT_VIEWS)
diff --git a/chrome/browser/translate/translate_infobars_delegates.h b/chrome/browser/translate/translate_infobars_delegates.h
index 80bada0..18416c4 100644
--- a/chrome/browser/translate/translate_infobars_delegates.h
+++ b/chrome/browser/translate/translate_infobars_delegates.h
@@ -18,8 +18,8 @@ class TranslateInfoBarDelegate : public InfoBarDelegate {
std::vector<std::string>* languages);
virtual void GetAvailableTargetLanguages(
std::vector<std::string>* languages);
- virtual void ModifyOriginalLanguage(const std::string& original_language);
- virtual void ModifyTargetLanguage(const std::string& target_language);
+ virtual void ModifyOriginalLanguage(int lang_index);
+ virtual void ModifyTargetLanguage(int lang_index);
virtual void Translate();
virtual bool IsLanguageBlacklisted();
virtual void ToggleLanguageBlacklist();
@@ -28,11 +28,14 @@ class TranslateInfoBarDelegate : public InfoBarDelegate {
virtual bool ShouldAlwaysTranslate();
virtual void ToggleAlwaysTranslate();
- const std::string& original_language() const {
- return original_language_;
+ const std::string& original_lang_code() const {
+ return supported_languages_[original_lang_index_];
}
- const std::string& target_language() const {
- return target_language_;
+ const std::string& target_lang_code() const {
+ return supported_languages_[target_lang_index_];
+ }
+ const std::string& GetLocaleFromIndex(int lang_index) const {
+ return supported_languages_[lang_index];
}
TabContents* tab_contents() const {
return tab_contents_;
@@ -49,14 +52,19 @@ class TranslateInfoBarDelegate : public InfoBarDelegate {
}
virtual void InfoBarClosed();
+ // Returns the printable version of the language code |language_code|.
+ static string16 GetDisplayNameForLocale(const std::string& language_code);
+
protected:
TranslateInfoBarDelegate(TabContents* contents, PrefService* user_prefs,
const std::string& original_language, const std::string& target_language);
TabContents* tab_contents_; // Weak.
- std::string original_language_;
- std::string target_language_;
+ int original_lang_index_;
+ int target_lang_index_;
TranslatePrefs prefs_;
+ // The list of languages supported.
+ std::vector<std::string> supported_languages_;
DISALLOW_COPY_AND_ASSIGN(TranslateInfoBarDelegate);
};
@@ -92,7 +100,7 @@ class AfterTranslateInfoBarDelegate : public TranslateInfoBarDelegate {
// Overriden from TranslateInfoBar:
virtual void GetAvailableTargetLanguages(
std::vector<std::string>* languages);
- virtual void ModifyTargetLanguage(const std::string& target_language);
+ virtual void ModifyTargetLanguage(int lang_index);
virtual bool ShouldAlwaysTranslate();
virtual void ToggleAlwaysTranslate();