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 #  define _(String, ...)        (StringUtils::insertValues(translations->w_gettext(String), ##__VA_ARGS__))
35 #undef _C
36 #undef _P
37 #  define _C(Ctx, String, ...)  (StringUtils::insertValues(translations->w_gettext(String, Ctx), ##__VA_ARGS__))
38 #  define _P(Singular, Plural, Num, ...) (StringUtils::insertValues(translations->w_ngettext(Singular, Plural, Num), Num, ##__VA_ARGS__))
39 #  define _CP(Ctx, Singular, Plural, Num, ...) (StringUtils::insertValues(translations->w_ngettext(Singular, Plural, Num, Ctx), Num, ##__VA_ARGS__))
40 #  define gettext_noop(String)  (String)
41 #  define N_(String)            (gettext_noop (String))
42 // libintl defines its own fprintf, which doesn't work properly
43 #  if defined(WIN32) && !defined(__CYGWIN__)
44 #    undef fprintf
45 #  endif
46 
47 class Translations
48 {
49 private:
50 #ifndef SERVER_ONLY
51     tinygettext::DictionaryManager m_dictionary_manager;
52     tinygettext::Dictionary        m_dictionary;
53 
54     static std::map<std::string, std::string> m_localized_name;
55     static std::map<std::string, std::map<std::string, irr::core::stringw> > m_localized_country_codes;
56     std::string m_current_language_name;
57     std::string m_current_language_name_code;
58     std::string m_current_language_tag;
59 #endif
60 
61 public:
62                        Translations();
63                       ~Translations();
64 
65     irr::core::stringw w_gettext(const wchar_t* original, const char* context=NULL);
66     irr::core::stringw w_gettext(const char* original, const char* context=NULL);
67 
68     irr::core::stringw w_ngettext(const wchar_t* singular, const wchar_t* plural, int num, const char* context=NULL);
69     irr::core::stringw w_ngettext(const char* singular, const char* plural, int num, const char* context=NULL);
70 
71 #ifndef SERVER_ONLY
72     const std::vector<std::string>* getLanguageList() const;
73 
74     std::set<wchar_t>        getCurrentAllChar();
75 
76     std::string              getCurrentLanguageName();
77 
78     std::string              getCurrentLanguageNameCode();
79 
80     const std::string&       getLocalizedName(const std::string& str) const;
81 
82     irr::core::stringw       getLocalizedCountryName(const std::string& country_code) const;
83 
84     void                     insertThaiBreakMark(const std::u32string& thai, std::vector<bool>& breakable);
85 #endif
86 };   // Translations
87 
88 
89 extern Translations* translations;
90 #endif
91 /* EOF */
92