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

Side by Side Diff: chrome/browser/translate/translate_language_list.cc

Issue 15987004: Translate: Filter and record languages whose names Chrome doesn't show (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Modified the test Created 7 years, 6 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_language_list.h" 5 #include "chrome/browser/translate/translate_language_list.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/json/json_reader.h" 10 #include "base/json/json_reader.h"
11 #include "base/lazy_instance.h" 11 #include "base/lazy_instance.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/strings/string_util.h" 13 #include "base/strings/string_util.h"
14 #include "base/strings/stringprintf.h" 14 #include "base/strings/stringprintf.h"
15 #include "base/values.h" 15 #include "base/values.h"
16 #include "chrome/browser/browser_process.h" 16 #include "chrome/browser/browser_process.h"
17 #include "chrome/browser/translate/translate_browser_metrics.h"
17 #include "chrome/browser/translate/translate_event_details.h" 18 #include "chrome/browser/translate/translate_event_details.h"
18 #include "chrome/browser/translate/translate_manager.h" 19 #include "chrome/browser/translate/translate_manager.h"
19 #include "chrome/browser/translate/translate_url_util.h" 20 #include "chrome/browser/translate/translate_url_util.h"
20 #include "googleurl/src/gurl.h" 21 #include "googleurl/src/gurl.h"
21 #include "net/base/load_flags.h" 22 #include "net/base/load_flags.h"
22 #include "net/base/url_util.h" 23 #include "net/base/url_util.h"
23 #include "net/http/http_status_code.h" 24 #include "net/http/http_status_code.h"
24 #include "net/url_request/url_fetcher.h" 25 #include "net/url_request/url_fetcher.h"
25 #include "net/url_request/url_request_status.h" 26 #include "net/url_request/url_request_status.h"
27 #include "ui/base/l10n/l10n_util.h"
26 28
27 namespace { 29 namespace {
28 30
29 // The default list of languages the Google translation server supports. 31 // The default list of languages the Google translation server supports.
30 // We use this list until we receive the list that the server exposes. 32 // We use this list until we receive the list that the server exposes.
31 // For information, here is the list of languages that Chrome can be run in 33 // For information, here is the list of languages that Chrome can be run in
32 // but that the translation server does not support: 34 // but that the translation server does not support:
33 // am Amharic 35 // am Amharic
34 // bn Bengali 36 // bn Bengali
35 // gu Gujarati 37 // gu Gujarati
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 DictionaryValue* language_dict = 157 DictionaryValue* language_dict =
156 static_cast<DictionaryValue*>(json_value.get()); 158 static_cast<DictionaryValue*>(json_value.get());
157 DictionaryValue* target_languages = NULL; 159 DictionaryValue* target_languages = NULL;
158 if (!language_dict->GetDictionary(TranslateLanguageList::kTargetLanguagesKey, 160 if (!language_dict->GetDictionary(TranslateLanguageList::kTargetLanguagesKey,
159 &target_languages) || 161 &target_languages) ||
160 target_languages == NULL) { 162 target_languages == NULL) {
161 NOTREACHED(); 163 NOTREACHED();
162 return; 164 return;
163 } 165 }
164 166
167 const std::string& locale = g_browser_process->GetApplicationLocale();
168
165 // Now we can clear language list. 169 // Now we can clear language list.
166 set->clear(); 170 set->clear();
167 std::string message; 171 std::string message;
168 // ... and replace it with the values we just fetched from the server. 172 // ... and replace it with the values we just fetched from the server.
169 for (DictionaryValue::Iterator iter(*target_languages); 173 for (DictionaryValue::Iterator iter(*target_languages);
170 !iter.IsAtEnd(); 174 !iter.IsAtEnd();
171 iter.Advance()) { 175 iter.Advance()) {
172 // TODO(toyoshim): Check if UI libraries support adding locale. 176 // TODO(toyoshim): Check if UI libraries support adding locale.
173 set->insert(iter.key()); 177 const std::string& lang = iter.key();
178 if (!l10n_util::IsLocaleNameTranslated(lang.c_str(), locale)) {
179 TranslateBrowserMetrics::ReportUndisplayableLanguage(lang);
180 continue;
181 }
182 set->insert(lang);
174 if (message.empty()) 183 if (message.empty())
175 message += iter.key(); 184 message += lang;
176 else 185 else
177 message += ", " + iter.key(); 186 message += ", " + lang;
178 } 187 }
179 NotifyEvent(__LINE__, message); 188 NotifyEvent(__LINE__, message);
180 } 189 }
181 190
182 } // namespace 191 } // namespace
183 192
184 TranslateLanguageList::LanguageListFetcher::LanguageListFetcher( 193 TranslateLanguageList::LanguageListFetcher::LanguageListFetcher(
185 bool include_alpha_languages) 194 bool include_alpha_languages)
186 : include_alpha_languages_(include_alpha_languages), 195 : include_alpha_languages_(include_alpha_languages),
187 state_(IDLE) { 196 state_(IDLE) {
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 std::set<std::string>::const_iterator iter; 356 std::set<std::string>::const_iterator iter;
348 for (iter = supported_languages_.begin(); 357 for (iter = supported_languages_.begin();
349 iter != supported_languages_.end(); 358 iter != supported_languages_.end();
350 ++iter) 359 ++iter)
351 all_supported_languages_.insert(*iter); 360 all_supported_languages_.insert(*iter);
352 for (iter = supported_alpha_languages_.begin(); 361 for (iter = supported_alpha_languages_.begin();
353 iter != supported_alpha_languages_.end(); 362 iter != supported_alpha_languages_.end();
354 ++iter) 363 ++iter)
355 all_supported_languages_.insert(*iter); 364 all_supported_languages_.insert(*iter);
356 } 365 }
OLDNEW
« no previous file with comments | « chrome/browser/translate/translate_browser_metrics_unittest.cc ('k') | chrome/browser/translate/translate_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698