summaryrefslogtreecommitdiff
path: root/include/m_langpack.h
blob: 946d2a28cd663a7d2b9c44cd559f096d269f5b74 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
/*

Miranda IM: the free IM client for Microsoft* Windows*

Copyright 2000-2008 Miranda ICQ/IM project,
all portions of this codebase are copyrighted to the people
listed in contributors.txt.

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/

#ifndef M_LANGPACK_H__
#define M_LANGPACK_H__

#if MIRANDA_VER >= 0x0A00 && !defined( _STATIC )
	#define MIRANDA_CUSTOM_LP
#endif

#define LANG_UNICODE 0x1000

//translates a single string into the user's local language	  v0.1.1.0+
//wParam=0
//lParam=(LPARAM)(const char*)szEnglish
//returns a pointer to the localised string. If there is no known translation
//it will return szEnglish. The return value does not need to be freed in any
//way
//Note that the Translate() macro as defined below will crash plugins that are
//loaded into Miranda 0.1.0.1 and earlier. If anyone's actually using one of
//these versions, I pity them.
#define MS_LANGPACK_TRANSLATESTRING  "LangPack/TranslateString"

#if defined( MIRANDA_CUSTOM_LP )

extern int hLangpack;

__inline static char* Translate(const char* str)
{	return (char*)CallService(MS_LANGPACK_TRANSLATESTRING,hLangpack,(LPARAM)(str));
}

__inline static WCHAR* TranslateW(const WCHAR* str)
{	return (WCHAR*)CallService(MS_LANGPACK_TRANSLATESTRING,hLangpack+LANG_UNICODE,(LPARAM)(str));
}

#else

__inline static char* Translate(const char* str)
{	return (char*)CallService(MS_LANGPACK_TRANSLATESTRING,0,(LPARAM)(str));
}

__inline static WCHAR* TranslateW(const WCHAR* str)
{	return (WCHAR*)CallService(MS_LANGPACK_TRANSLATESTRING,LANG_UNICODE,(LPARAM)(str));
}

#endif

#ifdef _UNICODE
	#define TranslateT(s)	TranslateW(_T(s))
	#define TranslateTS(s)	TranslateW(s)
#else
	#define TranslateT(s)	Translate(s)
	#define TranslateTS(s)	Translate(s)
#endif

// If you're storing some string for calling later-on Translate or using it
// with an API call that does translation automatically marked with
// [TRANSLATED-BY-CORE] please wrap it with one of LPGEN macros in order to
// generate proper language pack.
#define LPGEN(s)			s
#define LPGENW(s)			L ## s
#ifdef _UNICODE
	#define LPGENT(s)		_T(s)
#else
	#define LPGENT(s)		s
#endif
//Those macros do NOTHING. They are just markers for lpgen.pl.

//translates a dialog into the user's local language	  v0.1.1.0+
//wParam=0
//lParam=(LPARAM)(LANGPACKTRANSLATEDIALOG*)&lptd
//returns 0 on success, nonzero on failure
//This service only knows about the following controls:
//Window titles, STATIC, EDIT, Hyperlink, BUTTON
typedef struct {
	int cbSize;
	DWORD flags;
	HWND hwndDlg;
	const int *ignoreControls;   //zero-terminated list of control IDs *not* to
	    //translate
} LANGPACKTRANSLATEDIALOG;
#define LPTDF_NOIGNOREEDIT   1     //translate all edit controls. By default
                   //non-read-only edit controls are not translated
#define LPTDF_NOTITLE        2     //do not translate the title of the dialog

#define MS_LANGPACK_TRANSLATEDIALOG  "LangPack/TranslateDialog"

#if defined( MIRANDA_CUSTOM_LP )

__inline static INT_PTR TranslateDialogDefault(HWND hwndDlg)
{
	LANGPACKTRANSLATEDIALOG lptd;
	lptd.cbSize=sizeof(lptd);
	lptd.flags=hLangpack;
	lptd.hwndDlg=hwndDlg;
	lptd.ignoreControls=NULL;
	return CallService(MS_LANGPACK_TRANSLATEDIALOG,0,(LPARAM)&lptd);
}

#else

__inline static INT_PTR TranslateDialogDefault(HWND hwndDlg)
{
	LANGPACKTRANSLATEDIALOG lptd;
	lptd.cbSize=sizeof(lptd);
	lptd.flags=0;
	lptd.hwndDlg=hwndDlg;
	lptd.ignoreControls=NULL;
	return CallService(MS_LANGPACK_TRANSLATEDIALOG,0,(LPARAM)&lptd);
}

#endif

//translates a menu into the user's local language	  v0.1.1.0+
//wParam=(WPARAM)(HMENU)hMenu
//lParam=langpack handle (v.0.10.0+)
//returns 0 on success, nonzero on failure
#define MS_LANGPACK_TRANSLATEMENU    "LangPack/TranslateMenu"

#if defined( MIRANDA_CUSTOM_LP )

__inline static INT_PTR TranslateMenu(HMENU hMenu)
{	return CallService(MS_LANGPACK_TRANSLATEMENU, (WPARAM)hMenu, hLangpack);
}

#else

__inline static INT_PTR TranslateMenu(HMENU hMenu)
{	return CallService(MS_LANGPACK_TRANSLATEMENU, (LPARAM)hMenu, 0);
}

#endif

//returns the codepage used in the language pack 	  v0.4.3.0+
//wParam=0
//lParam=0
//returns the codepage stated in the langpack, or CP_ACP if no langpack is present
#define MS_LANGPACK_GETCODEPAGE      "LangPack/GetCodePage"

//returns the locale id associated with the language pack    v0.4.3.0+
//wParam=0
//lParam=0
//returns the Windows locale id stated in the langpack, or LOCALE_USER_DEFAULT if no langpack is present
#define MS_LANGPACK_GETLOCALE        "LangPack/GetLocale"

//returns the strdup/wcsdup of lparam according to the langpack  v0.4.3.0+
//wParam=langpack handle (v.0.10.0+)
//lParam=(LPARAM)(char*)source string
//returns a string converted from char* to TCHAR* using the langpack codepage.
//This string should be freed using mir_free() then
#define MS_LANGPACK_PCHARTOTCHAR     "LangPack/PcharToTchar"

#if defined( MIRANDA_CUSTOM_LP )

__inline static INT_PTR Langpack_PCharToTChar(const char* str)
{	return CallService(MS_LANGPACK_PCHARTOTCHAR, hLangpack, (LPARAM)str);
}

#else

__inline static INT_PTR Langpack_PCharToTChar(const char* str)
{	return CallService(MS_LANGPACK_PCHARTOTCHAR, 0, (LPARAM)str);
}

#endif

//initializes the plugin-specific translation context  v0.10.0+
//wParam=pointer to the langpack handle
//lParam=PLUGININFOEX* of the caller plugin
//always returns 0
#define MS_LANGPACK_REGISTER         "LangPack/Register"

#if defined( MIRANDA_CUSTOM_LP )

__forceinline void mir_getLP( const PLUGININFOEX* pInfo )
{	CallService(MS_LANGPACK_REGISTER, (WPARAM)&hLangpack, (LPARAM)pInfo);
}

#endif

#endif // M_LANGPACK_H__