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