]> git.saurik.com Git - wxWidgets.git/blame - include/wx/intl.h
Enable variadic macros for VC9 and later.
[wxWidgets.git] / include / wx / intl.h
CommitLineData
c801d85f 1/////////////////////////////////////////////////////////////////////////////
58d5dfc1 2// Name: wx/intl.h
77ffb593 3// Purpose: Internationalization and localisation for wxWidgets
c801d85f 4// Author: Vadim Zeitlin
849a28d0
VS
5// Modified by: Michael N. Filippov <michael@idisys.iae.nsk.su>
6// (2003/09/30 - plural forms support)
c801d85f
KB
7// Created: 29/01/98
8// RCS-ID: $Id$
9// Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
65571936 10// Licence: wxWindows licence
c801d85f
KB
11/////////////////////////////////////////////////////////////////////////////
12
dccce9ea
VZ
13#ifndef _WX_INTL_H_
14#define _WX_INTL_H_
c801d85f 15
c801d85f
KB
16#include "wx/defs.h"
17#include "wx/string.h"
ea144923 18#include "wx/translation.h"
18e065b4 19
b137e493
WS
20// Make wxLayoutDirection enum available without need for wxUSE_INTL so wxWindow, wxApp
21// and other classes are not distrubed by wxUSE_INTL
22
23enum wxLayoutDirection
24{
25 wxLayout_Default,
26 wxLayout_LeftToRight,
27 wxLayout_RightToLeft
28};
29
88ac883a
VZ
30#if wxUSE_INTL
31
dccce9ea 32#include "wx/fontenc.h"
ea144923 33#include "wx/language.h"
dccce9ea 34
c801d85f
KB
35// ============================================================================
36// global decls
37// ============================================================================
38
c801d85f
KB
39// ----------------------------------------------------------------------------
40// macros
41// ----------------------------------------------------------------------------
42
c801d85f
KB
43// ----------------------------------------------------------------------------
44// forward decls
45// ----------------------------------------------------------------------------
ec37df57 46
b5dbe15d
VS
47class WXDLLIMPEXP_FWD_BASE wxLocale;
48class WXDLLIMPEXP_FWD_BASE wxLanguageInfoArray;
c801d85f
KB
49
50// ============================================================================
51// locale support
52// ============================================================================
53
fda91381
VS
54// ----------------------------------------------------------------------------
55// wxLanguageInfo: encapsulates wxLanguage to OS native lang.desc.
56// translation information
57// ----------------------------------------------------------------------------
58
bddd7a8d 59struct WXDLLIMPEXP_BASE wxLanguageInfo
fda91381
VS
60{
61 int Language; // wxLanguage id
62 wxString CanonicalName; // Canonical name, e.g. fr_FR
d98a58c5 63#ifdef __WINDOWS__
dccce9ea
VZ
64 wxUint32 WinLang, // Win32 language identifiers
65 WinSublang;
d98a58c5 66#endif // __WINDOWS__
fda91381 67 wxString Description; // human-readable name of the language
978af864 68 wxLayoutDirection LayoutDirection;
ea65760d 69
d98a58c5 70#ifdef __WINDOWS__
ea65760d
VZ
71 // return the LCID corresponding to this language
72 wxUint32 GetLCID() const;
d98a58c5 73#endif // __WINDOWS__
86d62b51
VZ
74
75 // return the locale name corresponding to this language usable with
76 // setlocale() on the current system
77 wxString GetLocaleName() const;
fda91381
VS
78};
79
86d62b51
VZ
80// for Unix systems GetLocaleName() is trivial so implement it inline here, for
81// MSW it's implemented in intl.cpp
d98a58c5 82#ifndef __WINDOWS__
86d62b51 83inline wxString wxLanguageInfo::GetLocaleName() const { return CanonicalName; }
d98a58c5 84#endif // !__WINDOWS__
86d62b51 85
18e065b4 86
f2a139ad
VZ
87// ----------------------------------------------------------------------------
88// wxLocaleCategory: the category of locale settings
89// ----------------------------------------------------------------------------
90
91enum wxLocaleCategory
92{
93 // (any) numbers
94 wxLOCALE_CAT_NUMBER,
95
96 // date/time
97 wxLOCALE_CAT_DATE,
98
99 // monetary value
100 wxLOCALE_CAT_MONEY,
101
89a7e1ff
VZ
102 // default category for wxLocaleInfo values which only apply to a single
103 // category (e.g. wxLOCALE_SHORT_DATE_FMT)
104 wxLOCALE_CAT_DEFAULT,
105
f2a139ad
VZ
106 wxLOCALE_CAT_MAX
107};
108
109// ----------------------------------------------------------------------------
110// wxLocaleInfo: the items understood by wxLocale::GetInfo()
111// ----------------------------------------------------------------------------
112
113enum wxLocaleInfo
114{
89a7e1ff 115 // the thousands separator (for wxLOCALE_CAT_NUMBER or MONEY)
f2a139ad
VZ
116 wxLOCALE_THOUSANDS_SEP,
117
89a7e1ff
VZ
118 // the character used as decimal point (for wxLOCALE_CAT_NUMBER or MONEY)
119 wxLOCALE_DECIMAL_POINT,
120
121 // the stftime()-formats used for short/long date and time representations
122 // (under some platforms short and long date formats are the same)
123 //
124 // NB: these elements should appear in this order, code in GetInfo() relies
125 // on it
126 wxLOCALE_SHORT_DATE_FMT,
127 wxLOCALE_LONG_DATE_FMT,
128 wxLOCALE_DATE_TIME_FMT,
129 wxLOCALE_TIME_FMT
f2a139ad
VZ
130
131};
132
c801d85f
KB
133// ----------------------------------------------------------------------------
134// wxLocale: encapsulates all language dependent settings, including current
84c18814 135// message catalogs, date, time and currency formats (TODO) &c
c801d85f 136// ----------------------------------------------------------------------------
fda91381
VS
137
138enum wxLocaleInitFlags
139{
f30bd8f2 140 wxLOCALE_DONT_LOAD_DEFAULT = 0x0000, // don't load wxwin.mo
3acf8a8d
VS
141 wxLOCALE_LOAD_DEFAULT = 0x0001 // load wxwin.mo?
142#if WXWIN_COMPATIBILITY_2_8
143 ,wxLOCALE_CONV_ENCODING = 0x0002 // no longer used, simply remove
144 // it from the existing code
145#endif
fda91381
VS
146};
147
bddd7a8d 148class WXDLLIMPEXP_BASE wxLocale
c801d85f
KB
149{
150public:
84c18814
VZ
151 // ctor & dtor
152 // -----------
153
154 // call Init() if you use this ctor
ea8f6fc7
VZ
155 wxLocale() { DoCommonInit(); }
156
84c18814 157 // the ctor has a side effect of changing current locale
31b7522e
VS
158 wxLocale(const wxString& name, // name (for messages)
159 const wxString& shortName = wxEmptyString, // dir prefix (for msg files)
160 const wxString& locale = wxEmptyString, // locale (for setlocale)
3acf8a8d
VS
161 bool bLoadDefault = true // preload wxstd.mo?
162#if WXWIN_COMPATIBILITY_2_8
163 ,bool bConvertEncoding = true // convert Win<->Unix if necessary?
164#endif
165 )
58d5dfc1 166 {
ea8f6fc7
VZ
167 DoCommonInit();
168
1be12624 169#if WXWIN_COMPATIBILITY_2_8
31b7522e 170 Init(name, shortName, locale, bLoadDefault, bConvertEncoding);
1be12624
VS
171#else
172 Init(name, shortName, locale, bLoadDefault);
173#endif
fda91381
VS
174 }
175
ec37df57 176 wxLocale(int language, // wxLanguage id or custom language
3acf8a8d 177 int flags = wxLOCALE_LOAD_DEFAULT)
ea8f6fc7
VZ
178 {
179 DoCommonInit();
fda91381 180
ea8f6fc7
VZ
181 Init(language, flags);
182 }
183
184 // the same as a function (returns true on success)
31b7522e
VS
185 bool Init(const wxString& name,
186 const wxString& shortName = wxEmptyString,
187 const wxString& locale = wxEmptyString,
3acf8a8d
VS
188 bool bLoadDefault = true
189#if WXWIN_COMPATIBILITY_2_8
190 ,bool bConvertEncoding = true
191#endif
192 );
fda91381 193
ea8f6fc7 194 // same as second ctor (returns true on success)
fda91381 195 bool Init(int language = wxLANGUAGE_DEFAULT,
3acf8a8d 196 int flags = wxLOCALE_LOAD_DEFAULT);
ec37df57 197
84c18814 198 // restores old locale
d4a724d4 199 virtual ~wxLocale();
58d5dfc1 200
3103e8a9 201 // Try to get user's (or OS's) preferred language setting.
ec37df57 202 // Return wxLANGUAGE_UNKNOWN if language-guessing algorithm failed
41780009 203 static int GetSystemLanguage();
84c18814 204
dccce9ea
VZ
205 // get the encoding used by default for text on this system, returns
206 // wxFONTENCODING_SYSTEM if it couldn't be determined
207 static wxFontEncoding GetSystemEncoding();
208
209 // get the string describing the system encoding, return empty string if
210 // couldn't be determined
211 static wxString GetSystemEncodingName();
212
f2a139ad
VZ
213 // get the values of the given locale-dependent datum: the current locale
214 // is used, the US default value is returned if everything else fails
89a7e1ff
VZ
215 static wxString GetInfo(wxLocaleInfo index,
216 wxLocaleCategory cat = wxLOCALE_CAT_DEFAULT);
f2a139ad 217
ea8f6fc7 218 // return true if the locale was set successfully
3ca6a5f0
BP
219 bool IsOk() const { return m_pszOldLocale != NULL; }
220
84c18814 221 // returns locale name
31b7522e 222 const wxString& GetLocale() const { return m_strLocale; }
58d5dfc1 223
fda91381
VS
224 // return current locale wxLanguage value
225 int GetLanguage() const { return m_language; }
84c18814 226
58d5dfc1 227 // return locale name to be passed to setlocale()
fda91381
VS
228 wxString GetSysName() const;
229
58d5dfc1 230 // return 'canonical' name, i.e. in the form of xx[_YY], where xx is
fda91381
VS
231 // language code according to ISO 639 and YY is country name
232 // as specified by ISO 3166.
233 wxString GetCanonicalName() const { return m_strShort; }
58d5dfc1 234
84c18814
VZ
235 // add a prefix to the catalog lookup path: the message catalog files will be
236 // looked up under prefix/<lang>/LC_MESSAGES, prefix/LC_MESSAGES and prefix
237 // (in this order).
238 //
239 // This only applies to subsequent invocations of AddCatalog()!
18e065b4
VS
240 static void AddCatalogLookupPathPrefix(const wxString& prefix)
241 { wxFileTranslationsLoader::AddCatalogLookupPathPrefix(prefix); }
84c18814
VZ
242
243 // add a catalog: it's searched for in standard places (current directory
244 // first, system one after), but the you may prepend additional directories to
245 // the search path with AddCatalogLookupPathPrefix().
246 //
247 // The loaded catalog will be used for message lookup by GetString().
248 //
249 // Returns 'true' if it was successfully loaded
0d28a1f9
VS
250 bool AddCatalog(const wxString& domain);
251 bool AddCatalog(const wxString& domain, wxLanguage msgIdLanguage);
31b7522e
VS
252 bool AddCatalog(const wxString& domain,
253 wxLanguage msgIdLanguage, const wxString& msgIdCharset);
84c18814 254
cec5ffc4
VZ
255 // check if the given locale is provided by OS and C run time
256 static bool IsAvailable(int lang);
257
84c18814 258 // check if the given catalog is loaded
0d28a1f9 259 bool IsLoaded(const wxString& domain) const;
58d5dfc1 260
14f8fa9d
VZ
261 // Retrieve the language info struct for the given language
262 //
263 // Returns NULL if no info found, pointer must *not* be deleted by caller
264 static const wxLanguageInfo *GetLanguageInfo(int lang);
265
4a6e4a46
VS
266 // Returns language name in English or empty string if the language
267 // is not in database
268 static wxString GetLanguageName(int lang);
269
18e065b4
VS
270 // Returns ISO code ("canonical name") of language or empty string if the
271 // language is not in database
272 static wxString GetLanguageCanonicalName(int lang);
273
9d1e1be4
VZ
274 // Find the language for the given locale string which may be either a
275 // canonical ISO 2 letter language code ("xx"), a language code followed by
276 // the country code ("xx_XX") or a Windows full language name ("Xxxxx...")
277 //
278 // Returns NULL if no info found, pointer must *not* be deleted by caller
279 static const wxLanguageInfo *FindLanguageInfo(const wxString& locale);
280
fda91381
VS
281 // Add custom language to the list of known languages.
282 // Notes: 1) wxLanguageInfo contains platform-specific data
283 // 2) must be called before Init to have effect
41780009 284 static void AddLanguage(const wxLanguageInfo& info);
84c18814
VZ
285
286 // retrieve the translation for a string in all loaded domains unless
287 // the szDomain parameter is specified (and then only this domain is
288 // searched)
849a28d0 289 // n - additional parameter for PluralFormsParser
84c18814
VZ
290 //
291 // return original string if translation is not available
292 // (in this case an error message is generated the first time
293 // a string is not found; use wxLogNull to suppress it)
294 //
295 // domains are searched in the last to first order, i.e. catalogs
296 // added later override those added before.
18e065b4
VS
297 const wxString& GetString(const wxString& origString,
298 const wxString& domain = wxEmptyString) const
299 {
0d28a1f9 300 return wxGetTranslation(origString, domain);
18e065b4 301 }
849a28d0 302 // plural form version of the same:
18e065b4
VS
303 const wxString& GetString(const wxString& origString,
304 const wxString& origString2,
dfbb5eff 305 unsigned n,
18e065b4
VS
306 const wxString& domain = wxEmptyString) const
307 {
0d28a1f9 308 return wxGetTranslation(origString, origString2, n, domain);
18e065b4 309 }
84c18814 310
a64be16e
VS
311 // this is hack to work around a problem with wxGetTranslation() which
312 // returns const wxString& and not wxString, so when it returns untranslated
313 // string, it needs to have a copy of it somewhere
18e065b4
VS
314 static const wxString& GetUntranslatedString(const wxString& str)
315 { return wxTranslations::GetUntranslatedString(str); }
a64be16e 316
84c18814
VZ
317 // Returns the current short name for the locale
318 const wxString& GetName() const { return m_strShort; }
319
c48908df 320 // return the contents of .po file header
31b7522e 321 wxString GetHeaderValue(const wxString& header,
0d28a1f9 322 const wxString& domain = wxEmptyString) const;
c48908df 323
41780009
VS
324 // These two methods are for internal use only. First one creates
325 // ms_languagesDB if it doesn't already exist, second one destroys
326 // it.
327 static void CreateLanguagesDB();
328 static void DestroyLanguagesDB();
329
84c18814 330private:
18e065b4
VS
331 bool DoInit(const wxString& name,
332 const wxString& shortName,
333 const wxString& locale);
58d5dfc1 334
fda91381 335 // copy default table of languages from global static array to
41780009
VS
336 // m_langugagesInfo, called by InitLanguagesDB
337 static void InitLanguagesDB();
84c18814 338
ea8f6fc7
VZ
339 // initialize the member fields to default values
340 void DoCommonInit();
341
afc94fa6
VS
342 wxString m_strLocale, // this locale name
343 m_strShort; // short name for the locale
fda91381 344 int m_language; // this locale wxLanguage value
84c18814 345
52de37c7 346 const char *m_pszOldLocale; // previous locale from setlocale()
afc94fa6 347 wxLocale *m_pOldLocale; // previous wxLocale
84c18814 348
3202d00d
VS
349 bool m_initialized;
350
18e065b4
VS
351 wxTranslations m_translations;
352
41780009 353 static wxLanguageInfoArray *ms_languagesDB;
22f3361e 354
c0c133e1 355 wxDECLARE_NO_COPY_CLASS(wxLocale);
c801d85f
KB
356};
357
9d8046f6 358// ----------------------------------------------------------------------------
a1530845 359// global functions
9d8046f6
VZ
360// ----------------------------------------------------------------------------
361
84c18814 362// get the current locale object (note that it may be NULL!)
bddd7a8d 363extern WXDLLIMPEXP_BASE wxLocale* wxGetLocale();
84c18814 364
ea144923 365#endif // wxUSE_INTL
b12915c1 366
dccce9ea 367#endif // _WX_INTL_H_