3 * Copyright (C) 2005-2013 Team XBMC
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)
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.
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/>.
22 #include "utils/StdString.h"
27 class CLangCodeExpander
38 CLangCodeExpander(void);
39 ~CLangCodeExpander(void);
41 bool Lookup(CStdString& desc, const CStdString& code);
42 bool Lookup(CStdString& desc, const int code);
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.
50 bool CompareFullLangNames(const CStdString& lang1, const CStdString& lang2);
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.
58 bool CompareLangCodes(const CStdString& code1, const CStdString& code2);
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.
68 bool ConvertToTwoCharCode(CStdString& code, const CStdString& lang, bool checkXbmcLocales = true);
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.
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);
81 bool ConvertLinuxToWindowsRegionCodes(const CStdString& strTwoCharCode, CStdString& strThreeCharCode);
82 bool ConvertWindowsToGeneralCharCode(const CStdString& strWindowsCharCode, CStdString& strThreeCharCode);
85 void LoadUserCodes(const TiXmlElement* pRootElement);
88 std::vector<std::string> GetLanguageNames(LANGFORMATS format = ISO_639_1) const;
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.
96 void CodeToString(long code, CStdString& ret);
98 typedef std::map<CStdString, CStdString> STRINGLOOKUPTABLE;
99 STRINGLOOKUPTABLE m_mapUser;
101 bool LookupInDb(CStdString& desc, const CStdString& code);
102 bool LookupInMap(CStdString& desc, const CStdString& code);
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.
110 bool ReverseLookup(const CStdString& desc, CStdString& code);
113 extern CLangCodeExpander g_LangCodeExpander;