SuperTuxKart
translation.hpp
1 //
2 // SuperTuxKart - a fun racing game with go-kart
3 // Copyright (C) 2006-2015 Joerg Henrichs
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 3
8 // of the License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 
19 #ifndef TRANSLATION_HPP
20 #define TRANSLATION_HPP
21 
22 #include <irrString.h>
23 #include <map>
24 #include <set>
25 #include <sstream>
26 #include <string>
27 #include <utility>
28 #include <vector>
29 
30 #ifndef SERVER_ONLY
31 #include "tinygettext/tinygettext.hpp"
32 #endif
33 
34 #ifdef STK_UTF8_GETTEXT
35 #define STK_GETTEXT gettext
36 #define STK_NGETTEXT ngettext
37 #else
38 #define STK_GETTEXT w_gettext
39 #define STK_NGETTEXT w_ngettext
40 #endif
41 
42 # define _(String, ...) (StringUtils::insertValues(translations->STK_GETTEXT(String), ##__VA_ARGS__))
43 #undef _C
44 #undef _P
45 # define _C(Ctx, String, ...) (StringUtils::insertValues(translations->STK_GETTEXT(String, Ctx), ##__VA_ARGS__))
46 # define _P(Singular, Plural, Num, ...) (StringUtils::insertValues(translations->STK_NGETTEXT(Singular, Plural, Num), Num, ##__VA_ARGS__))
47 # define _CP(Ctx, Singular, Plural, Num, ...) (StringUtils::insertValues(translations->STK_NGETTEXT(Singular, Plural, Num, Ctx), Num, ##__VA_ARGS__))
48 # define gettext_noop(String) (String)
49 # define N_(String) (gettext_noop (String))
50 // libintl defines its own fprintf, which doesn't work properly
51 # if defined(WIN32) && !defined(__CYGWIN__)
52 # undef fprintf
53 # endif
54 
56 {
57 private:
58 #ifndef SERVER_ONLY
59  tinygettext::DictionaryManager m_dictionary_manager;
60  tinygettext::Dictionary* m_dictionary;
61 
62  static std::map<std::string, std::string> m_localized_name;
63  static std::map<std::string, std::map<std::string, irr::core::stringw> > m_localized_country_codes;
64  std::string m_current_language_name;
65  std::string m_current_language_name_code;
66  std::string m_current_language_tag;
67 #endif
68 
69 public:
70  Translations();
71  ~Translations();
72 
73  irr::core::stringw w_gettext(const wchar_t* original, const char* context=NULL);
74  irr::core::stringw w_gettext(const char* original, const char* context=NULL);
75  std::string gettext(const char* original, const char* context=NULL);
76 
77  irr::core::stringw w_ngettext(const wchar_t* singular, const wchar_t* plural, int num, const char* context=NULL);
78  irr::core::stringw w_ngettext(const char* singular, const char* plural, int num, const char* context=NULL);
79  std::string ngettext(const char* singular, const char* plural, int num, const char* context=NULL);
80 
81 #ifndef SERVER_ONLY
82  const std::vector<std::string>* getLanguageList() const;
83 
84  std::set<unsigned int> getCurrentAllChar();
85 
86  std::string getCurrentLanguageName();
87 
88  std::string getCurrentLanguageNameCode();
89 
90  const std::string getLocalizedName(const std::string& str) const;
91 
92  irr::core::stringw getLocalizedCountryName(const std::string& country_code) const;
93 
94  void insertThaiBreakMark(const std::u32string& thai, std::vector<bool>& breakable);
95 #endif
96 }; // Translations
97 
98 
99 extern Translations* translations;
100 #endif
101 /* EOF */
Definition: translation.hpp:56
irr::core::stringw w_ngettext(const wchar_t *singular, const wchar_t *plural, int num, const char *context=NULL)
Definition: translation.cpp:677
irr::core::stringw w_gettext(const wchar_t *original, const char *context=NULL)
Definition: translation.cpp:595
std::string ngettext(const char *singular, const char *plural, int num, const char *context=NULL)
Definition: translation.cpp:723
std::string gettext(const char *original, const char *context=NULL)
Definition: translation.cpp:643