OpenTREP Logo  0.6.0
C++ Open Travel Request Parsing Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Language.cpp
Go to the documentation of this file.
1 // //////////////////////////////////////////////////////////////////////
2 // Import section
3 // //////////////////////////////////////////////////////////////////////
4 // STL
5 #include <cassert>
6 // OpenTrep
7 #include <opentrep/Language.hpp>
8 
9 namespace OPENTREP {
10 
11  // //////////////////////////////////////////////////////////////////////
12  const std::string Language::_longLabels[LAST_VALUE+1] = {
13  "common",
14  "ar", "ar_DZ", "ar_MA", "ar_SA", "ar_TN",
15  "de", "de_DE", "en", "en_GB", "en_US", "es", "es_AR", "es_ES", "es_MX",
16  "fa", "fa_IR",
17  "fr", "fr_BE", "fr_CA", "fr_CH", "fr_FR",
18  "he", "he_IL", "ko", "ko_KR", "pl", "pl_PL", "pt", "pt_BR", "pt_PT",
19  "sv", "sv_SE",
20  "ru", "ru_RU", "uk", "uk_UA", "zh", "zh_CN", "zh_HK", "zh_TW",
21  "out-of-index"};
22 
23  // //////////////////////////////////////////////////////////////////////
24  const std::string Language::_shortLabels[LAST_VALUE+1] = {
25  "",
26  "ar", "ar", "ar", "ar", "ar",
27  "de", "de", "en", "en", "en", "es", "es", "es", "es",
28  "fa", "fa",
29  "fr", "fr", "fr", "fr", "fr",
30  "he", "he", "ko", "ko", "pl", "pl", "pt", "pt", "pt",
31  "sv", "sv",
32  "ru", "ru", "uk", "uk", "zh", "zh", "zh", "zh",
33  "out-of-index"};
34 
35  // //////////////////////////////////////////////////////////////////////
36  const std::string& Language::
38  return Language::_longLabels[iLanguage];
39  }
40 
41  // //////////////////////////////////////////////////////////////////////
42  const std::string& Language::
44  return Language::_shortLabels[iLanguage];
45  }
46 
47  // //////////////////////////////////////////////////////////////////////
48  Language::EN_Language Language::getCode (const std::string& iLanguageString) {
49  EN_Language oLanguageCode = LAST_VALUE;
50 
51  // An empty language code means that it is common to all the languages.
52  if (iLanguageString.empty() == true) {
53  EN_Language oLanguageCode = lg_com;
54  return oLanguageCode;
55  }
56 
57  for (unsigned int itLanguageCode = 1; itLanguageCode != LAST_VALUE;
58  ++itLanguageCode) {
59  const EN_Language lLanguageCode= static_cast<EN_Language> (itLanguageCode);
60 
61  if (getShortLabel (lLanguageCode) == iLanguageString) {
62  oLanguageCode = lLanguageCode;
63  break;
64  }
65  }
66 
67  return oLanguageCode;
68  }
69 
70 }
static const std::string & getLongLabel(const EN_Language &)
Definition: Language.cpp:37
static const std::string & getShortLabel(const EN_Language &)
Definition: Language.cpp:43
static EN_Language getCode(const std::string &)
Definition: Language.cpp:48