]> git.lizzy.rs Git - minetest.git/blob - src/gettext.h
jthread remove locks that aren't absolutely required
[minetest.git] / src / gettext.h
1 /*
2 Minetest
3 Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (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 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #ifndef GETTEXT_HEADER
21 #define GETTEXT_HEADER
22
23 #include "config.h" // for USE_GETTEXT
24 #include "log.h"
25
26 #if USE_GETTEXT
27 #include <libintl.h>
28 #else
29 #define gettext(String) String
30 #endif
31
32 #define _(String) gettext(String)
33 #define gettext_noop(String) String
34 #define N_(String) gettext_noop (String)
35
36 #if defined(_WIN32)
37 #define WIN32_LEAN_AND_MEAN
38 #ifndef _WIN32_WINNT
39         #define _WIN32_WINNT 0x0501
40 #endif
41 #include <windows.h>
42
43 #endif // #if defined(_WIN32)
44
45 #ifdef _MSC_VER
46 void init_gettext(const char *path,std::string configured_language,int argc, char** argv);
47 #else
48 void init_gettext(const char *path,std::string configured_language);
49 #endif
50
51 /******************************************************************************/
52 inline wchar_t* chartowchar_t(const char *str)
53 {
54         wchar_t* nstr = 0;
55 #if defined(_WIN32)
56         int nResult = MultiByteToWideChar( CP_UTF8, 0, (LPCSTR) str, -1, 0, 0 );
57         if( nResult == 0 )
58         {
59                 errorstream<<"gettext: MultiByteToWideChar returned null"<<std::endl;
60         }
61         else
62         {
63                 nstr = new wchar_t[nResult];
64                 MultiByteToWideChar( CP_UTF8, 0, (LPCSTR) str, -1, (WCHAR *) nstr, nResult );
65         }
66 #else
67         size_t l = strlen(str)+1;
68         nstr = new wchar_t[l];
69         mbstowcs(nstr, str, l);
70 #endif
71
72         return nstr;
73 }
74
75 /******************************************************************************/
76 inline wchar_t* wgettext(const char *str)
77 {
78         return chartowchar_t(gettext(str));
79 }
80
81 /******************************************************************************/
82 inline std::wstring wstrgettext(std::string text) {
83         wchar_t* wlabel = wgettext(text.c_str());
84         std::wstring out = (std::wstring)wlabel;
85         delete[] wlabel;
86         return out;
87 }
88
89 #endif