summaryrefslogtreecommitdiffstats
path: root/xbmc/utils/LangCodeExpander.h
diff options
context:
space:
mode:
authormanuel <manuel@mausz.at>2020-10-19 00:52:24 +0200
committermanuel <manuel@mausz.at>2020-10-19 00:52:24 +0200
commitbe933ef2241d79558f91796cc5b3a161f72ebf9c (patch)
treefe3ab2f130e20c99001f2d7a81d610c78c96a3f4 /xbmc/utils/LangCodeExpander.h
parent5f8335c1e49ce108ef3481863833c98efa00411b (diff)
downloadkodi-pvr-build-be933ef2241d79558f91796cc5b3a161f72ebf9c.tar.gz
kodi-pvr-build-be933ef2241d79558f91796cc5b3a161f72ebf9c.tar.bz2
kodi-pvr-build-be933ef2241d79558f91796cc5b3a161f72ebf9c.zip
sync with upstream
Diffstat (limited to 'xbmc/utils/LangCodeExpander.h')
-rw-r--r--xbmc/utils/LangCodeExpander.h143
1 files changed, 143 insertions, 0 deletions
diff --git a/xbmc/utils/LangCodeExpander.h b/xbmc/utils/LangCodeExpander.h
new file mode 100644
index 0000000..5e26a65
--- /dev/null
+++ b/xbmc/utils/LangCodeExpander.h
@@ -0,0 +1,143 @@
1/*
2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
4 *
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
8
9#pragma once
10
11#include <map>
12#include <string>
13#include <vector>
14
15class TiXmlElement;
16
17class CLangCodeExpander
18{
19public:
20 CLangCodeExpander();
21 ~CLangCodeExpander();
22
23 enum LANGFORMATS
24 {
25 ISO_639_1,
26 ISO_639_2,
27 ENGLISH_NAME
28 };
29
30 void LoadUserCodes(const TiXmlElement* pRootElement);
31 void Clear();
32
33 bool Lookup(const std::string& code, std::string& desc);
34 bool Lookup(const int code, std::string& desc);
35
36 /** \brief Determines if two english language names represent the same language.
37 * \param[in] lang1 The first language string to compare given as english language name.
38 * \param[in] lang2 The second language string to compare given as english language name.
39 * \return true if the two language strings represent the same language, false otherwise.
40 * For example "Abkhaz" and "Abkhazian" represent the same language.
41 */
42 bool CompareFullLanguageNames(const std::string& lang1, const std::string& lang2);
43
44 /** \brief Determines if two languages given as ISO 639-1, ISO 639-2/T, or ISO 639-2/B codes represent the same language.
45 * \param[in] code1 The first language to compare given as ISO 639-1, ISO 639-2/T, or ISO 639-2/B code.
46 * \param[in] code2 The second language to compare given as ISO 639-1, ISO 639-2/T, or ISO 639-2/B code.
47 * \return true if the two language codes represent the same language, false otherwise.
48 * For example "ger", "deu" and "de" represent the same language.
49 */
50 bool CompareISO639Codes(const std::string& code1, const std::string& code2);
51
52 /** \brief Converts a language given as 2-Char (ISO 639-1),
53 * 3-Char (ISO 639-2/T or ISO 639-2/B),
54 * or full english name string to a 2-Char (ISO 639-1) code.
55 * \param[out] code The 2-Char language code of the given language lang.
56 * \param[in] lang The language that should be converted.
57 * \return true if the conversion succeeded, false otherwise.
58 */
59 bool ConvertToISO6391(const std::string& lang, std::string& code);
60
61 /** \brief Converts a language given as 2-Char (ISO 639-1),
62 * 3-Char (ISO 639-2/T or ISO 639-2/B),
63 * or full english name string to a 3-Char ISO 639-2/B code.
64 * \param[in] lang The language that should be converted.
65 * \return The 3-Char ISO 639-2/B code of lang if that code exists, lang otherwise.
66 */
67 std::string ConvertToISO6392B(const std::string& lang);
68
69 /** \brief Converts a language given as 2-Char (ISO 639-1) to a 3-Char (ISO 639-2/T) code.
70 * \param[in] strISO6391 The language that should be converted.
71 * \param[out] strISO6392B The 3-Char (ISO 639-2/B) language code of the given language strISO6391.
72 * \param[in] checkWin32Locales Whether to also check WIN32 specific language codes.
73 * \return true if the conversion succeeded, false otherwise.
74 */
75 static bool ConvertISO6391ToISO6392B(const std::string& strISO6391, std::string& strISO6392B, bool checkWin32Locales = false);
76
77 /** \brief Converts a language given as 2-Char (ISO 639-1),
78 * 3-Char (ISO 639-2/T or ISO 639-2/B),
79 * or full english name string to a 3-Char ISO 639-2/T code.
80 * \param[in] strCharCode The language that should be converted.
81 * \param[out] strISO6392B The 3-Char (ISO 639-2/B) language code of the given language strISO6391.
82 * \param[in] checkWin32Locales Whether to also check WIN32 specific language codes.
83 * \return true if the conversion succeeded, false otherwise.
84 */
85 bool ConvertToISO6392B(const std::string& strCharCode, std::string& strISO6392B, bool checkWin32Locales = false);
86
87 /** \brief Converts a language given as 2-Char (ISO 639-1),
88 * 3-Char (ISO 639-2/T or ISO 639-2/B),
89 * or full english name string to a 3-Char ISO 639-2/T code.
90 * \param[in] strCharCode The language that should be converted.
91 * \param[out] strISO6392T The 3-Char (ISO 639-2/T) language code of the given language strISO6391.
92 * \param[in] checkWin32Locales Whether to also check WIN32 specific language codes.
93 * \return true if the conversion succeeded, false otherwise.
94 */
95 bool ConvertToISO6392T(const std::string& strCharCode, std::string& strISO6392T, bool checkWin32Locales = false);
96
97 /** \brief Converts a language given as 2-Char (ISO 639-1),
98 * 3-Char (ISO 639-2/T or ISO 639-2/B),
99 * or full english name string to a 3-Char ISO 639-2/T code.
100 * \param[in] lang The language that should be converted.
101 * \return The 3-Char ISO 639-2/T code of lang if that code exists, lang otherwise.
102 */
103 std::string ConvertToISO6392T(const std::string& lang);
104
105#ifdef TARGET_WINDOWS
106 static bool ConvertISO31661Alpha2ToISO31661Alpha3(const std::string& strISO31661Alpha2, std::string& strISO31661Alpha3);
107 static bool ConvertWindowsLanguageCodeToISO6392B(const std::string& strWindowsLanguageCode, std::string& strISO6392B);
108#endif
109
110 std::vector<std::string> GetLanguageNames(LANGFORMATS format = ISO_639_1, bool customNames = false);
111protected:
112
113 /** \brief Converts a language code given as a long, see #MAKECODE(a, b, c, d)
114 * to its string representation.
115 * \param[in] code The language code given as a long, see #MAKECODE(a, b, c, d).
116 * \param[out] ret The string representation of the given language code code.
117 */
118 static void CodeToString(long code, std::string& ret);
119
120 static bool LookupInISO639Tables(const std::string& code, std::string& desc);
121 bool LookupInUserMap(const std::string& code, std::string& desc);
122
123 /** \brief Looks up the ISO 639-1, ISO 639-2/T, or ISO 639-2/B, whichever it finds first,
124 * code of the given english language name.
125 * \param[in] desc The english language name for which a code is looked for.
126 * \param[out] code The ISO 639-1, ISO 639-2/T, or ISO 639-2/B code of the given language desc.
127 * \return true if the a code was found, false otherwise.
128 */
129 bool ReverseLookup(const std::string& desc, std::string& code);
130
131
132 /** \brief Looks up the user defined code of the given code or language name.
133 * \param[in] desc The language code or name that should be converted.
134 * \param[out] userCode The user defined language code of the given language desc.
135 * \return true if desc was found, false otherwise.
136 */
137 bool LookupUserCode(const std::string& desc, std::string &userCode);
138
139 typedef std::map<std::string, std::string> STRINGLOOKUPTABLE;
140 STRINGLOOKUPTABLE m_mapUser;
141};
142
143extern CLangCodeExpander g_LangCodeExpander;