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