]> git.saurik.com Git - wxWidgets.git/blame - docs/latex/wx/locale.tex
First step in background erase optimization
[wxWidgets.git] / docs / latex / wx / locale.tex
CommitLineData
c1b7dab0
VZ
1\section{\class{wxLocale}}\label{wxlocale}
2
dbdb39b2
JS
3wxLocale class encapsulates all language-dependent settings and is a
4generalization of the C locale concept.
c1b7dab0 5
fc2171bd 6In wxWidgets this class manages message catalogs which contain the translations
c1b7dab0
VZ
7of the strings used to the current language.
8
0a67eeac
MB
9\perlnote{In wxPerl you can't use the '\_' function name, so
10the {\tt Wx::Locale} module can export the {\tt gettext} and
11{\tt gettext\_noop} under any given name.
d2c2afc9 12
5873607e 13\begin{verbatim}
0a67eeac
MB
14 # this imports gettext ( equivalent to Wx::GetTranslation
15 # and gettext_noop ( a noop )
16 # into your module
17 use Wx::Locale qw(:default);
5873607e
VZ
18
19 # ....
20
0a67eeac
MB
21 # use the functions
22 print gettext( ``Panic!'' );
5873607e 23
0a67eeac
MB
24 button = Wx::Button->new( window, -1, gettext( ``Label'' ) );
25\end{verbatim}
d2c2afc9 26
0a67eeac
MB
27If you need to translate a lot of strings, then adding gettext( ) around
28each one is a long task ( that is why \_( ) was introduced ), so just choose
29a shorter name for gettext:
d2c2afc9 30
0a67eeac
MB
31\begin{verbatim}
32 #
33 use Wx::Locale 'gettext' => 't',
34 'gettext_noop' => 'gettext_noop';
35
36 # ...
37
38 # use the functions
39 print t( ``Panic!!'' );
40
41 # ...
5873607e 42\end{verbatim}
d2c2afc9 43}%
5873607e 44
c1b7dab0
VZ
45\wxheading{Derived from}
46
47No base class
48
ed93168b
VZ
49\wxheading{See also}
50
5db9e0e8
VZ
51\helpref{Internationalization overview}{internationalization},\\
52\helpref{Internat sample}{sampleinternat}
ed93168b 53
dbdb39b2
JS
54\wxheading{Include files}
55
56<wx/intl.h>
57
8ec77cd7 58
c1b7dab0
VZ
59\latexignore{\rtfignore{\wxheading{Members}}}
60
8ec77cd7 61
f0ab09cc 62
8ec77cd7
VS
63\membersection{Supported languages}\label{wxlanguage}
64
429ffcc4
VS
65See \helpref{list of recognized language constants}{languagecodes}.
66These constants may be used to specify the language
8ec77cd7
VS
67in \helpref{Init}{wxlocaleinit} and are returned by
68\helpref{GetSystemLanguage}{wxlocalegetsystemlanguage}:
69
41780009 70
c1b7dab0
VZ
71\membersection{wxLocale::wxLocale}\label{wxlocaledefctor}
72
73\func{}{wxLocale}{\void}
74
75This is the default constructor and it does nothing to initialize the object:
dbdb39b2 76\helpref{Init()}{wxlocaleinit} must be used to do that.
c1b7dab0 77
8ec77cd7
VS
78\func{}{wxLocale}{\param{int }{language}, \param{int }{flags =
79 wxLOCALE\_LOAD\_DEFAULT | wxLOCALE\_CONV\_ENCODING}}
80
81See \helpref{Init()}{wxlocaleinit} for parameters description.
82
cc81d32f 83\func{}{wxLocale}{\param{const char }{*szName}, \param{const char }{*szShort = NULL}, \param{const char }{*szLocale = NULL}, \param{bool }{bLoadDefault = true}, \param{bool }{bConvertEncoding = false}}
c1b7dab0 84
8ec77cd7 85See \helpref{Init()}{wxlocaleinit} for parameters description.
c1b7dab0
VZ
86
87The call of this function has several global side effects which you should
88understand: first of all, the application locale is changed - note that this
89will affect many of standard C library functions such as printf() or strftime().
90Second, this wxLocale object becomes the new current global locale for the
91application and so all subsequent calls to wxGetTranslation() will try to
92translate the messages using the message catalogs for this locale.
93
8ec77cd7 94
f0ab09cc 95
c1b7dab0
VZ
96\membersection{wxLocale::\destruct{wxLocale}}\label{wxlocaledtor}
97
98\func{}{\destruct{wxLocale}}{\void}
99
dbdb39b2 100The destructor, like the constructor, also has global side effects: the previously
c1b7dab0
VZ
101set locale is restored and so the changes described in
102\helpref{Init}{wxlocaleinit} documentation are rolled back.
103
f0ab09cc 104
c1b7dab0
VZ
105\membersection{wxLocale::AddCatalog}\label{wxlocaleaddcatalog}
106
107\func{bool}{AddCatalog}{\param{const char }{*szDomain}}
108
d721baa9
VS
109\func{bool}{AddCatalog}{\param{const char }{*szDomain}, \param{wxLanguage}{msgIdLanguage}, \param{const char }{*msgIdCharset}}
110
f6bcfd97 111Add a catalog for use with the current locale: it is searched for in standard
dbdb39b2 112places (current directory first, then the system one), but you may also prepend
c1b7dab0 113additional directories to the search path with
dbdb39b2 114\helpref{AddCatalogLookupPathPrefix()}{wxlocaleaddcataloglookuppathprefix}.
c1b7dab0 115
d721baa9
VS
116All loaded catalogs will be used for message lookup by
117\helpref{GetString()}{wxlocalegetstring} for the current locale.
c1b7dab0 118
cc81d32f 119Returns true if catalog was successfully loaded, false otherwise (which might
c1b7dab0
VZ
120mean that the catalog is not found or that it isn't in the correct format).
121
d721baa9
VS
122The second form of this method takes two additional arguments,
123\arg{msgIdLanguage} and \arg{msgIdCharset}.
124
125\arg{msgIdLanguage} specifies the language of "msgid" strings in source code
126(i.e. arguments to \helpref{GetString}{wxlocalegetstring},
127\helpref{wxGetTranslation}{wxgettranslation} and the
128\helpref{\_()}{underscore} macro). It is used if AddCatalog cannot find any
129catalog for current language: if the language is same as source code language,
130then strings from source code are used instead.
131
132\arg{msgIdCharset} lets you specify the charset used for msgids in sources
133in case they use 8-bit characters (e.g. German or French strings). This
134argument has no effect in Unicode build, because literals in sources are
135Unicode strings; you have to use compiler-specific method of setting the right
136charset when compiling with Unicode.
137
138By default (i.e. when you use the first form), msgid strings are assumed
139to be in English and written only using 7-bit ASCII characters.
140
141If you have to deal with non-English strings or 8-bit characters in the source
142code, see the instructions in
143\helpref{Writing non-English applications}{nonenglishoverview}.
144
f0ab09cc 145
c1b7dab0
VZ
146\membersection{wxLocale::AddCatalogLookupPathPrefix}\label{wxlocaleaddcataloglookuppathprefix}
147
148\func{void}{AddCatalogLookupPathPrefix}{\param{const wxString\& }{prefix}}
149
150Add a prefix to the catalog lookup path: the message catalog files will be
151looked up under prefix/<lang>/LC\_MESSAGES, prefix/LC\_MESSAGES and prefix
152(in this order).
153
154This only applies to subsequent invocations of AddCatalog()!
155
f0ab09cc 156
8ec77cd7
VS
157\membersection{wxLocale::AddLanguage}\label{wxlocaleaddlanguage}
158
41780009 159\func{static void}{AddLanguage}{\param{const wxLanguageInfo\& }{info}}
8ec77cd7
VS
160
161Adds custom, user-defined language to the database of known languages. This
2edb0bde 162database is used in conjunction with the first form of
8ec77cd7
VS
163\helpref{Init}{wxlocaleinit}.
164
165wxLanguageInfo is defined as follows:
166
167\begin{verbatim}
168struct WXDLLEXPORT wxLanguageInfo
169{
170 int Language; // wxLanguage id
171 wxString CanonicalName; // Canonical name, e.g. fr_FR
172#ifdef __WIN32__
173 wxUint32 WinLang, WinSublang; // Win32 language identifiers
174 // (LANG_xxxx, SUBLANG_xxxx)
175#endif
176 wxString Description; // human-readable name of the language
177};
178\end{verbatim}
179
180
181{\it Language} should be greater than wxLANGUAGE\_USER\_DEFINED.
182
0a67eeac
MB
183\perlnote{In wxPerl Wx::LanguageInfo has only one method:\par
184Wx::LanguageInfo->new( language, canonicalName, WinLang, WinSubLang, Description )}
8ec77cd7 185
f0ab09cc 186
9d1e1be4
VZ
187\membersection{wxLocale::FindLanguageInfo}{wxlocalefindlanguageinfo}
188
189\constfunc{static wxLanguageInfo *}{FindLanguageInfo}{\param{const wxString\& }{locale}}
190
191This function may be used to find the language description structure for the
192given locale, specified either as a two letter ISO language code (for example,
193"pt"), a language code followed by the country code ("pt\_BR") or a full, human
194readable, language description ("Portuguese-Brazil").
195
196Returns the information for the given language or {\tt NULL} if this language
197is unknown. Note that even if the returned pointer is valid, the caller should
198{\it not} delete it.
199
200\wxheading{See also}
201
202\helpref{GetLanguageInfo}{wxlocalegetlanguageinfo}
8ec77cd7 203
f0ab09cc 204
8ec77cd7
VS
205\membersection{wxLocale::GetCanonicalName}\label{wxlocalegetcanonicalname}
206
207\constfunc{wxString}{GetSysName}{\void}
208
209Returns the canonical form of current locale name. Canonical form is the
210one that is used on UNIX systems: it is a two- or five-letter string in xx or
211xx\_YY format, where xx is ISO 639 code of language and YY is ISO 3166 code of
212the country. Examples are "en", "en\_GB", "en\_US" or "fr\_FR".
213
214This form is internally used when looking up message catalogs.
215
216Compare \helpref{GetSysName}{wxlocalegetsysname}.
217
218
219
f0ab09cc 220
8ec77cd7
VS
221\membersection{wxLocale::GetLanguage}\label{wxlocalegetlanguage}
222
223\constfunc{int}{GetLanguage}{\void}
224
225Returns \helpref{wxLanguage}{wxlanguage} constant of current language.
226Note that you can call this function only if you used the form of
227\helpref{Init}{wxlocaleinit} that takes wxLanguage argument.
228
f0ab09cc 229
14f8fa9d
VZ
230\membersection{wxLocale::GetLanguageInfo}\label{wxlocalegetlanguageinfo}
231
232\constfunc{static wxLanguageInfo *}{GetLanguageInfo}{\param{int }{lang}}
233
234Returns a pointer to wxLanguageInfo structure containing information about the
235given language or {\tt NULL} if this language is unknown. Note that even if the
236returned pointer is valid, the caller should {\it not} delete it.
237
238See \helpref{AddLanguage}{wxlocaleaddlanguage} for the wxLanguageInfo
239description.
240
f0ab09cc
VZ
241As with \helpref{Init}{wxlocaleinit}, \texttt{wxLANGUAGE\_DEFAULT} has the
242special meaning if passed as an argument to this function and in this case the
243result of \helpref{GetSystemLanguage()}{wxlocalegetsystemlanguage} is used.
244
245
4a6e4a46
VS
246\membersection{wxLocale::GetLanguageName}\label{wxlocalegetlanguagename}
247
248\constfunc{static wxString}{GetLanguageName}{\param{int }{lang}}
249
250Returns English name of the given language or empty string if this
251language is unknown.
252
f0ab09cc
VZ
253See \helpref{GetLanguageInfo}{wxlocalegetlanguageinfo} for a remark about
254special meaning of \texttt{wxLANGUAGE\_DEFAULT}.
255
8ec77cd7 256
3ca6a5f0
BP
257\membersection{wxLocale::GetLocale}\label{wxlocalegetlocale}
258
259\constfunc{const char*}{GetLocale}{\void}
260
261Returns the locale name as passed to the constructor or
8ec77cd7
VS
262\helpref{Init()}{wxlocaleinit}. This is full, human-readable name,
263e.g. "English" or "French".
264
3ca6a5f0 265
f0ab09cc 266
3ca6a5f0
BP
267\membersection{wxLocale::GetName}\label{wxlocalegetname}
268
269\constfunc{const wxString\&}{GetName}{\void}
270
271Returns the current short name for the locale (as given to the constructor or
272the Init() function).
273
f0ab09cc 274
3ca6a5f0
BP
275\membersection{wxLocale::GetString}\label{wxlocalegetstring}
276
277\constfunc{const char*}{GetString}{\param{const char }{*szOrigString}, \param{const char }{*szDomain = NULL}}
278
6f80247a
VS
279\constfunc{const char*}{GetString}{\param{const char }{*szOrigString}, \param{const char }{*szOrigString2}, \param{size\_t }{n}, \param{const char }{*szDomain = NULL}}
280
3ca6a5f0
BP
281Retrieves the translation for a string in all loaded domains unless the szDomain
282parameter is specified (and then only this catalog/domain is searched).
283
284Returns original string if translation is not available
285(in this case an error message is generated the first time
286a string is not found; use \helpref{wxLogNull}{wxlogoverview} to suppress it).
287
6f80247a
VS
288The second form is used when retrieving translation of string that has
289different singular and plural form in English or different plural forms in some
9e3b313e
VS
290other language. It takes two extra arguments: \arg{szOrigString}
291parameter must contain the singular form of the string to be converted.
292It is also used as the key for the search in the catalog.
293The \arg{szOrigString2} parameter is the plural form (in English).
294The parameter \arg{n} is used to determine the plural form. If no
295message catalog is found \arg{szOrigString} is returned if `n == 1',
296otherwise \arg{szOrigString2}.
297See \urlref{GNU gettext manual}{http://www.gnu.org/manual/gettext/html\_chapter/gettext\_10.html\#SEC150} for additional information on plural forms handling.
6f80247a 298
d721baa9
VS
299This method is called by the \helpref{wxGetTranslation}{wxgettranslation}
300function and \helpref{\_()}{underscore} macro.
301
3ca6a5f0
BP
302\wxheading{Remarks}
303
304Domains are searched in the last to first order, i.e. catalogs
305added later override those added before.
306
f0ab09cc 307
c48908df
VZ
308\membersection{wxLocale::GetHeaderValue}\label{wxlocalegetheadervalue}
309
310\constfunc{wxString}{GetHeaderValue}{\param{const char }{*szHeader}, \param{const char }{*szDomain = NULL}}
311
312Returns the header value for header \arg{szHeader}. The search for \arg{szHeader} is case sensitive. If an \arg{szDomain}
313is passed, this domain is searched. Else all domains will be searched until a header has been found.
314The return value is the value of the header if found. Else this will be empty.
315
8ec77cd7
VS
316\membersection{wxLocale::GetSysName}\label{wxlocalegetsysname}
317
318\constfunc{wxString}{GetSysName}{\void}
319
320Returns current platform-specific locale name as passed to setlocale().
321
322Compare \helpref{GetCanonicalName}{wxlocalegetcanonicalname}.
323
324
f0ab09cc 325
dccce9ea
VZ
326\membersection{wxLocale::GetSystemEncoding}\label{wxlocalegetsystemencoding}
327
328\constfunc{static wxFontEncoding}{GetSystemEncoding}{\void}
329
330Tries to detect the user's default font encoding.
331Returns \helpref{wxFontEncoding}{wxfont} value or
332{\bf wxFONTENCODING\_SYSTEM} if it couldn't be determined.
333
f0ab09cc 334
dccce9ea
VZ
335\membersection{wxLocale::GetSystemEncodingName}\label{wxlocalegetsystemencodingname}
336
337\constfunc{static wxString}{GetSystemEncodingName}{\void}
338
339Tries to detect the name of the user's default font encoding. This string isn't
340particularly useful for the application as its form is platform-dependent and
341so you should probably use
342\helpref{GetSystemEncoding}{wxlocalegetsystemencoding} instead.
343
344Returns a user-readable string value or an empty string if it couldn't be
345determined.
346
f0ab09cc 347
8ec77cd7
VS
348\membersection{wxLocale::GetSystemLanguage}\label{wxlocalegetsystemlanguage}
349
41780009 350\constfunc{static int}{GetSystemLanguage}{\void}
8ec77cd7
VS
351
352Tries to detect the user's default language setting.
353Returns \helpref{wxLanguage}{wxlanguage} value or
354 {\bf wxLANGUAGE\_UNKNOWN} if the language-guessing algorithm failed.
355
356
f0ab09cc 357
c1b7dab0
VZ
358\membersection{wxLocale::Init}\label{wxlocaleinit}
359
8ec77cd7
VS
360
361\func{bool}{Init}{\param{int }{language = wxLANGUAGE\_DEFAULT}, \param{int }{flags =
362 wxLOCALE\_LOAD\_DEFAULT | wxLOCALE\_CONV\_ENCODING}}
363
cc81d32f 364\func{bool}{Init}{\param{const char }{*szName}, \param{const char }{*szShort = NULL}, \param{const char }{*szLocale = NULL}, \param{bool }{bLoadDefault = true}, \param{bool }{bConvertEncoding = false}}
c1b7dab0 365
8ec77cd7
VS
366The second form is deprecated, use the first one unless you know what you are
367doing.
dbdb39b2 368
8ec77cd7
VS
369
370\wxheading{Parameters}
371
372\docparam{language}{\helpref{wxLanguage}{wxlanguage} identifier of the locale.
373wxLANGUAGE\_DEFAULT has special meaning -- wxLocale will use system's default
374language (see \helpref{GetSystemLanguage}{wxlocalegetsystemlanguage}).}
375
376\docparam{flags}{Combination of the following:
75173186
JS
377
378
8ec77cd7
VS
379\begin{twocollist}\itemsep=0pt
380\twocolitem{\windowstyle{wxLOCALE\_LOAD\_DEFAULT}}{Load the message catalog
fc2171bd 381for the given locale containing the translations of standard wxWidgets messages
8ec77cd7
VS
382automatically.}
383\twocolitem{\windowstyle{wxLOCALE\_CONV\_ENCODING}}{Automatically convert message
ae71a6e8 384catalogs to platform's default encoding. Note that it will do only basic
8ec77cd7
VS
385conversion between well-known pair like iso8859-1 and windows-1252 or
386iso8859-2 and windows-1250. See \helpref{Writing non-English applications}{nonenglishoverview} for detailed
ae71a6e8 387description of this behaviour. Note that this flag is meaningless in Unicode build.}
8ec77cd7
VS
388\end{twocollist}
389}
390
391\docparam{szName}{The name of the locale. Only used in diagnostic messages.}
392
393\docparam{szShort}{The standard 2 letter locale abbreviation and is used as the
394directory prefix when looking for the message catalog files.}
395
396\docparam{szLocale}{The parameter for the call to setlocale(). Note that it is
397platform-specific.}
398
cc81d32f 399\docparam{bLoadDefault}{May be set to false to prevent loading of the message catalog
fc2171bd 400for the given locale containing the translations of standard wxWidgets messages.
8ec77cd7
VS
401This parameter would be rarely used in normal circumstances.}
402
cc81d32f 403\docparam{bConvertEncoding}{May be set to true to do automatic conversion of message
a4313e3b
VS
404catalogs to platform's native encoding. Note that it will do only basic
405conversion between well-known pair like iso8859-1 and windows-1252 or
406iso8859-2 and windows-1250.
407See \helpref{Writing non-English applications}{nonenglishoverview} for detailed
8ec77cd7
VS
408description of this behaviour.}
409
c1b7dab0
VZ
410
411The call of this function has several global side effects which you should
412understand: first of all, the application locale is changed - note that this
413will affect many of standard C library functions such as printf() or strftime().
414Second, this wxLocale object becomes the new current global locale for the
d721baa9
VS
415application and so all subsequent calls to
416\helpref{wxGetTranslation()}{wxgettranslation} will try to
c1b7dab0
VZ
417translate the messages using the message catalogs for this locale.
418
cc81d32f 419Returns true on success or false if the given locale couldn't be set.
c1b7dab0 420
f0ab09cc 421
c1b7dab0
VZ
422\membersection{wxLocale::IsLoaded}\label{wxlocaleisloaded}
423
dbdb39b2
JS
424\constfunc{bool}{IsLoaded}{\param{const char* }{domain}}
425
cc81d32f 426Check if the given catalog is loaded, and returns true if it is.
c1b7dab0 427
dbdb39b2
JS
428According to GNU gettext tradition, each catalog
429normally corresponds to 'domain' which is more or less the application name.
c1b7dab0
VZ
430
431See also: \helpref{AddCatalog}{wxlocaleaddcatalog}
432
f0ab09cc 433
3ca6a5f0 434\membersection{wxLocale::IsOk}\label{wxlocaleisok}
c1b7dab0 435
3ca6a5f0 436\constfunc{bool}{IsOk}{\void}
dbdb39b2 437
cc81d32f 438Returns true if the locale could be set successfully.
dbdb39b2 439