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

Side by Side Diff: chrome/common/translate/translate_util.cc

Issue 25531002: Move language detection to a component (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fix compilation Created 7 years, 2 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/common/translate/translate_util.h"
6
7 #include "base/basictypes.h"
8 #include "base/command_line.h"
9 #include "chrome/common/chrome_switches.h"
10 #include "url/gurl.h"
11
12 namespace TranslateUtil {
13
14 // Language code synonyms. Some languages have changed codes over the years
15 // and sometimes the older codes are used, so we must see them as synonyms.
16 struct LanguageCodeSynonym {
17 // Code used in supporting list of Translate.
18 const char* const translate_language;
19
20 // Code used in Chrome internal.
21 const char* const chrome_language;
22 };
23
24 // If this table is updated, please sync this with that in
25 // chrome/browser/resources/options/language_options.js
26 const LanguageCodeSynonym kLanguageCodeSynonyms[] = {
27 {"no", "nb"},
28 {"iw", "he"},
29 {"jw", "jv"},
30 {"tl", "fil"},
31 };
32
33 const char kSecurityOrigin[] = "https://translate.googleapis.com/";
34
35 void ToTranslateLanguageSynonym(std::string* language) {
36 // Apply liner search here because number of items in the list is just four.
37 for (size_t i = 0; i < arraysize(kLanguageCodeSynonyms); ++i) {
38 if (language->compare(kLanguageCodeSynonyms[i].chrome_language) == 0) {
39 *language = std::string(kLanguageCodeSynonyms[i].translate_language);
40 break;
41 }
42 }
43 }
44
45 void ToChromeLanguageSynonym(std::string* language) {
46 // Apply liner search here because number of items in the list is just four.
47 for (size_t i = 0; i < arraysize(kLanguageCodeSynonyms); ++i) {
48 if (language->compare(kLanguageCodeSynonyms[i].translate_language) == 0) {
49 *language = std::string(kLanguageCodeSynonyms[i].chrome_language);
50 break;
51 }
52 }
53 }
54
55 GURL GetTranslateSecurityOrigin() {
56 std::string security_origin(kSecurityOrigin);
57 CommandLine* command_line = CommandLine::ForCurrentProcess();
58 if (command_line->HasSwitch(switches::kTranslateSecurityOrigin)) {
59 security_origin =
60 command_line->GetSwitchValueASCII(switches::kTranslateSecurityOrigin);
61 }
62 return GURL(security_origin);
63 }
64
65 } // namespace TranslateUtil
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698