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