summaryrefslogtreecommitdiffstats
path: root/chrome/common/translate/translate_util.cc
blob: c607f3b344c80aef3013f5f9385a6dd694519d8b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Copyright 2013 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/common/translate/translate_util.h"

#include "base/basictypes.h"

namespace TranslateUtil {

// Language code synonyms. Some languages have changed codes over the years
// and sometimes the older codes are used, so we must see them as synonyms.
struct LanguageCodeSynonym {
  // Code used in supporting list of Translate.
  const char* const translate_language;

  // Code used in Chrome internal.
  const char* const chrome_language;
};

const LanguageCodeSynonym kLanguageCodeSynonyms[] = {
  {"no", "nb"},
  {"iw", "he"},
  {"jw", "jv"},
  {"tl", "fil"},
};

void ToTranslateLanguageSynonym(std::string* language) {
  // Apply liner search here because number of items in the list is just four.
  for (size_t i = 0; i < arraysize(kLanguageCodeSynonyms); ++i) {
    if (language->compare(kLanguageCodeSynonyms[i].chrome_language) == 0) {
      *language = std::string(kLanguageCodeSynonyms[i].translate_language);
      break;
    }
  }
}

void ToChromeLanguageSynonym(std::string* language) {
  // Apply liner search here because number of items in the list is just four.
  for (size_t i = 0; i < arraysize(kLanguageCodeSynonyms); ++i) {
    if (language->compare(kLanguageCodeSynonyms[i].translate_language) == 0) {
      *language = std::string(kLanguageCodeSynonyms[i].chrome_language);
      break;
    }
  }
}

}  // namespace TranslateUtil