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