Better apple tree generation
[oweals/minetest.git] / src / gettext.h
1 #ifndef GETTEXT_HEADER
2 #include "config.h" // for USE_GETTEXT
3 #include <iostream>
4
5 #if USE_GETTEXT
6 #include <libintl.h>
7 #else
8 #define gettext(String) String
9 #endif
10
11 #define _(String) gettext(String)
12 #define gettext_noop(String) String
13 #define N_(String) gettext_noop (String)
14
15 inline void init_gettext(const char *path) {
16 #if USE_GETTEXT
17         // don't do this if MSVC compiler is used, it gives an assertion fail
18         #ifndef _MSC_VER
19                 setlocale(LC_MESSAGES, "");
20         #endif
21         bindtextdomain(PROJECT_NAME, path);
22         textdomain(PROJECT_NAME);
23 #endif
24 }
25
26 inline wchar_t* chartowchar_t(const char *str)
27 {
28         size_t l = strlen(str)+1;
29         wchar_t* nstr = new wchar_t[l];
30         mbstowcs(nstr, str, l);
31         return nstr;
32 }
33
34 inline wchar_t* wgettext(const char *str)
35 {
36         return chartowchar_t(gettext(str));
37 }
38
39 inline void changeCtype(const char *l)
40 {
41         char *ret = NULL;
42         ret = setlocale(LC_CTYPE, l);
43         if(ret == NULL)
44                 std::cout<<"locale could not be set"<<std::endl;
45         else
46                 std::cout<<"locale has been set to:"<<ret<<std::endl;
47 }
48 #define GETTEXT_HEADER
49 #endif