]> git.lizzy.rs Git - dragonfireclient.git/blob - src/gettext.h
Add ObjectRef.hud_set_hotbar_itemcount and add TOCLIENT_HUD_SET_PARAM
[dragonfireclient.git] / src / gettext.h
1 #ifndef GETTEXT_HEADER
2 #include "config.h" // for USE_GETTEXT
3 #include "log.h"
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 #if defined(_WIN32)
16 #define WIN32_LEAN_AND_MEAN
17 #include <windows.h>
18 #endif
19
20 inline void init_gettext(const char *path) {
21 #if USE_GETTEXT
22         // don't do this if MSVC compiler is used, it gives an assertion fail
23         #ifndef _MSC_VER
24                 setlocale(LC_MESSAGES, "");
25         #endif
26         bindtextdomain(PROJECT_NAME, path);
27         textdomain(PROJECT_NAME);
28 #if defined(_WIN32)
29         // As linux is successfully switched to UTF-8 completely at about year 2005
30         // Windows still uses obsolete codepage based locales because you
31         // cannot recompile closed-source applications
32
33         // Set character encoding for Win32
34         char *tdomain = textdomain( (char *) NULL );
35         if( tdomain == NULL )
36         {
37                 fprintf( stderr, "warning: domainname parameter is the null pointer, default domain is not set\n" );
38                 tdomain = (char *) "messages";
39         }
40         /*char *codeset = */bind_textdomain_codeset( tdomain, "UTF-8" );
41         //fprintf( stdout, "%s: debug: domainname = %s; codeset = %s\n", argv[0], tdomain, codeset );
42 #endif // defined(_WIN32)
43 #endif
44 }
45
46 inline wchar_t* chartowchar_t(const char *str)
47 {
48         wchar_t* nstr = 0;
49 #if defined(_WIN32)
50         int nResult = MultiByteToWideChar( CP_UTF8, 0, (LPCSTR) str, -1, 0, 0 );
51         if( nResult == 0 )
52         {
53                 fprintf( stderr, "error: MultiByteToWideChar returned null\n" );
54         }
55         else
56         {
57                 nstr = new wchar_t[nResult];
58                 MultiByteToWideChar( CP_UTF8, 0, (LPCSTR) str, -1, (WCHAR *) nstr, nResult );
59         }
60 #else
61         size_t l = strlen(str)+1;
62         nstr = new wchar_t[l];
63         mbstowcs(nstr, str, l);
64 #endif
65
66         return nstr;
67 }
68
69 inline wchar_t* wgettext(const char *str)
70 {
71         return chartowchar_t(gettext(str));
72 }
73
74 inline void changeCtype(const char *l)
75 {
76         /*char *ret = NULL;
77         ret = setlocale(LC_CTYPE, l);
78         if(ret == NULL)
79                 infostream<<"locale could not be set"<<std::endl;
80         else
81                 infostream<<"locale has been set to:"<<ret<<std::endl;*/
82 }
83 #define GETTEXT_HEADER
84 #endif