Merge pull request #4676 from jmarshallnz/dont_set_scraper_on_tvshow_on_nfo
[vuplus_xbmc] / xbmc / utils / LangCodeExpander.h
1 #pragma once
2 /*
3  *      Copyright (C) 2005-2013 Team XBMC
4  *      http://xbmc.org
5  *
6  *  This Program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 2, or (at your option)
9  *  any later version.
10  *
11  *  This Program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with XBMC; see the file COPYING.  If not, see
18  *  <http://www.gnu.org/licenses/>.
19  *
20  */
21
22 #include "utils/StdString.h"
23 #include <map>
24
25 class TiXmlElement;
26
27 class CLangCodeExpander
28 {
29 public:
30
31   enum LANGFORMATS
32   {
33     ISO_639_1,
34     ISO_639_2,
35     ENGLISH_NAME
36   };
37
38   CLangCodeExpander(void);
39   ~CLangCodeExpander(void);
40
41   bool Lookup(CStdString& desc, const CStdString& code);
42   bool Lookup(CStdString& desc, const int code);
43
44   /** \brief Determines if two english language names represent the same language.
45   *   \param[in] lang1 The first language string to compare given as english language name.
46   *   \param[in] lang2 The second language string to compare given as english language name.
47   *   \return true if the two language strings represent the same language, false otherwise.
48   *   For example "Abkhaz" and "Abkhazian" represent the same language.
49   */ 
50   bool CompareFullLangNames(const CStdString& lang1, const CStdString& lang2);
51
52   /** \brief Determines if two languages given as ISO 639-1, ISO 639-2/T, or ISO 639-2/B codes represent the same language.
53   *   \param[in] code1 The first language to compare given as ISO 639-1, ISO 639-2/T, or ISO 639-2/B code.
54   *   \param[in] code2 The second language to compare given as ISO 639-1, ISO 639-2/T, or ISO 639-2/B code.
55   *   \return true if the two language codes represent the same language, false otherwise.
56   *   For example "ger", "deu" and "de" represent the same language.
57   */ 
58   bool CompareLangCodes(const CStdString& code1, const CStdString& code2);
59
60   /** \brief Converts a language given as 2-Char (ISO 639-1),
61   *          3-Char (ISO 639-2/T or ISO 639-2/B),
62   *          or full english name string to a 2-Char (ISO 639-1) code.  
63   *   \param[out] code The 2-Char language code of the given language lang.
64   *   \param[in] lang The language that should be converted.
65   *   \param[in] checkXbmcLocales Try to find in XBMC specific locales
66   *   \return true if the conversion succeeded, false otherwise. 
67   */ 
68   bool ConvertToTwoCharCode(CStdString& code, const CStdString& lang, bool checkXbmcLocales = true);
69
70   /** \brief Converts a language given as 2-Char (ISO 639-1),
71   *          3-Char (ISO 639-2/T or ISO 639-2/B),
72   *          or full english name string to a 3-Char ISO 639-2/T code.
73   *   \param[in] lang The language that should be converted.
74   *   \return The 3-Char ISO 639-2/T code of lang if that code exists, lang otherwise.
75   */
76   CStdString ConvertToISO6392T(const CStdString& lang);
77   bool ConvertTwoToThreeCharCode(CStdString& strThreeCharCode, const CStdString& strTwoCharCode, bool checkWin32Locales = false);
78   bool ConvertToThreeCharCode(CStdString& strThreeCharCode, const CStdString& strCharCode, bool checkXbmcLocales = true, bool checkWin32Locales = false);
79
80 #ifdef TARGET_WINDOWS
81   bool ConvertLinuxToWindowsRegionCodes(const CStdString& strTwoCharCode, CStdString& strThreeCharCode);
82   bool ConvertWindowsToGeneralCharCode(const CStdString& strWindowsCharCode, CStdString& strThreeCharCode);
83 #endif
84
85   void LoadUserCodes(const TiXmlElement* pRootElement);
86   void Clear();
87
88   std::vector<std::string> GetLanguageNames(LANGFORMATS format = ISO_639_1) const;
89 protected:
90
91   /** \brief Converts a language code given as a long, see #MAKECODE(a, b, c, d)
92   *          to its string representation.
93   *   \param[in] code The language code given as a long, see #MAKECODE(a, b, c, d).
94   *   \param[out] ret The string representation of the given language code code.
95   */ 
96   void CodeToString(long code, CStdString& ret);
97
98   typedef std::map<CStdString, CStdString> STRINGLOOKUPTABLE;
99   STRINGLOOKUPTABLE m_mapUser;
100
101   bool LookupInDb(CStdString& desc, const CStdString& code);
102   bool LookupInMap(CStdString& desc, const CStdString& code);
103
104   /** \brief Looks up the ISO 639-1, ISO 639-2/T, or ISO 639-2/B, whichever it finds first,
105   *          code of the given english language name.
106   *   \param[in] desc The english language name for which a code is looked for.
107   *   \param[out] code The ISO 639-1, ISO 639-2/T, or ISO 639-2/B code of the given language desc.
108   *   \return true if the a code was found, false otherwise.
109   */ 
110   bool ReverseLookup(const CStdString& desc, CStdString& code);
111 };
112
113 extern CLangCodeExpander g_LangCodeExpander;