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

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: Made Translate.ServerReportedUnsupportedLanguage deprecated 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/command_line.h" 9 #include "base/command_line.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/string_util.h" 13 #include "base/string_util.h"
14 #include "base/values.h" 14 #include "base/values.h"
15 #include "chrome/browser/browser_process.h" 15 #include "chrome/browser/browser_process.h"
16 #include "chrome/browser/translate/translate_browser_metrics.h"
16 #include "chrome/browser/translate/translate_url_util.h" 17 #include "chrome/browser/translate/translate_url_util.h"
17 #include "chrome/common/chrome_switches.h" 18 #include "chrome/common/chrome_switches.h"
18 #include "googleurl/src/gurl.h" 19 #include "googleurl/src/gurl.h"
19 #include "net/base/load_flags.h" 20 #include "net/base/load_flags.h"
20 #include "net/base/url_util.h" 21 #include "net/base/url_util.h"
21 #include "net/http/http_status_code.h" 22 #include "net/http/http_status_code.h"
22 #include "net/url_request/url_fetcher.h" 23 #include "net/url_request/url_fetcher.h"
23 #include "net/url_request/url_request_status.h" 24 #include "net/url_request/url_request_status.h"
25 #include "ui/base/l10n/l10n_util.h"
24 26
25 namespace { 27 namespace {
26 28
27 // The default list of languages the Google translation server supports. 29 // The default list of languages the Google translation server supports.
28 // We use this list until we receive the list that the server exposes. 30 // We use this list until we receive the list that the server exposes.
29 // For information, here is the list of languages that Chrome can be run in 31 // For information, here is the list of languages that Chrome can be run in
30 // but that the translation server does not support: 32 // but that the translation server does not support:
31 // am Amharic 33 // am Amharic
32 // bn Bengali 34 // bn Bengali
33 // gu Gujarati 35 // gu Gujarati
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 // and the other for target languages, we want to use the target languages. 226 // and the other for target languages, we want to use the target languages.
225 DictionaryValue* language_dict = 227 DictionaryValue* language_dict =
226 static_cast<DictionaryValue*>(json_value.get()); 228 static_cast<DictionaryValue*>(json_value.get());
227 DictionaryValue* target_languages = NULL; 229 DictionaryValue* target_languages = NULL;
228 if (!language_dict->GetDictionary(TranslateLanguageList::kTargetLanguagesKey, 230 if (!language_dict->GetDictionary(TranslateLanguageList::kTargetLanguagesKey,
229 &target_languages) || 231 &target_languages) ||
230 target_languages == NULL) { 232 target_languages == NULL) {
231 NOTREACHED(); 233 NOTREACHED();
232 return; 234 return;
233 } 235 }
236
237 const std::string& locale = g_browser_process->GetApplicationLocale();
238
234 // Now we can clear our current state... 239 // Now we can clear our current state...
235 supported_languages_.clear(); 240 supported_languages_.clear();
236 // ... and replace it with the values we just fetched from the server. 241 // ... and replace it with the values we just fetched from the server.
237 for (DictionaryValue::Iterator iter(*target_languages); 242 for (DictionaryValue::Iterator iter(*target_languages);
238 !iter.IsAtEnd(); 243 !iter.IsAtEnd();
239 iter.Advance()) { 244 iter.Advance()) {
240 supported_languages_.insert(iter.key()); 245 const std::string& lang = iter.key();
246 if (!l10n_util::IsLocaleNameTranslated(lang.c_str(), locale)) {
247 TranslateBrowserMetrics::ReportUndisplayableLanguage(lang);
248 continue;
249 }
250 supported_languages_.insert(lang);
241 } 251 }
242 } 252 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698