1 \section{\class{wxLocale
}}\label{wxlocale
}
3 wxLocale class encapsulates all language-dependent settings and is a
4 generalization of the C locale concept.
6 In wxWidgets this class manages message catalogs which contain the translations
7 of the strings used to the current language.
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.
14 # this imports gettext ( equivalent to Wx::GetTranslation
15 # and gettext_noop ( a noop )
17 use Wx::Locale qw(:default);
22 print gettext( ``Panic!'' );
24 button = Wx::Button->new( window, -
1, gettext( ``Label'' ) );
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:
33 use Wx::Locale 'gettext' => 't',
34 'gettext_noop' => 'gettext_noop';
39 print t( ``Panic!!'' );
45 \wxheading{Derived from
}
51 \helpref{Internationalization overview
}{internationalization
},\\
52 \helpref{Internat sample
}{sampleinternat
}
54 \wxheading{Include files
}
60 \helpref{wxBase
}{librarieslist
}
63 \latexignore{\rtfignore{\wxheading{Members
}}}
67 \membersection{Supported languages
}\label{wxlanguage
}
69 See
\helpref{list of recognized language constants
}{languagecodes
}.
70 These constants may be used to specify the language
71 in
\helpref{Init
}{wxlocaleinit
} and are returned by
72 \helpref{GetSystemLanguage
}{wxlocalegetsystemlanguage
}:
75 \membersection{wxLocale::wxLocale
}\label{wxlocaledefctor
}
77 \func{}{wxLocale
}{\void}
79 This is the default constructor and it does nothing to initialize the object:
80 \helpref{Init()
}{wxlocaleinit
} must be used to do that.
82 \func{}{wxLocale
}{\param{int
}{language
},
\param{int
}{flags =
83 wxLOCALE
\_LOAD\_DEFAULT | wxLOCALE
\_CONV\_ENCODING}}
85 See
\helpref{Init()
}{wxlocaleinit
} for parameters description.
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
}}
89 See
\helpref{Init()
}{wxlocaleinit
} for parameters description.
91 The call of this function has several global side effects which you should
92 understand: first of all, the application locale is changed - note that this
93 will affect many of standard C library functions such as printf() or strftime().
94 Second, this wxLocale object becomes the new current global locale for the
95 application and so all subsequent calls to wxGetTranslation() will try to
96 translate the messages using the message catalogs for this locale.
100 \membersection{wxLocale::
\destruct{wxLocale
}}\label{wxlocaledtor
}
102 \func{}{\destruct{wxLocale
}}{\void}
104 The destructor, like the constructor, also has global side effects: the previously
105 set locale is restored and so the changes described in
106 \helpref{Init
}{wxlocaleinit
} documentation are rolled back.
109 \membersection{wxLocale::AddCatalog
}\label{wxlocaleaddcatalog
}
111 \func{bool
}{AddCatalog
}{\param{const wxString\&
}{domain
}}
113 \func{bool
}{AddCatalog
}{\param{const wxString\&
}{domain
},
\param{wxLanguage
}{msgIdLanguage
},
\param{const wxString\&
}{msgIdCharset
}}
115 Add a catalog for use with the current locale: it is searched for in standard
116 places (current directory first, then the system one), but you may also prepend
117 additional directories to the search path with
118 \helpref{AddCatalogLookupPathPrefix()
}{wxlocaleaddcataloglookuppathprefix
}.
120 All loaded catalogs will be used for message lookup by
121 \helpref{GetString()
}{wxlocalegetstring
} for the current locale.
123 Returns true if catalog was successfully loaded, false otherwise (which might
124 mean that the catalog is not found or that it isn't in the correct format).
126 The second form of this method takes two additional arguments,
127 \arg{msgIdLanguage
} and
\arg{msgIdCharset
}.
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
133 catalog for current language: if the language is same as source code language,
134 then strings from source code are used instead.
136 \arg{msgIdCharset
} lets you specify the charset used for msgids in sources
137 in case they use
8-bit characters (e.g. German or French strings). This
138 argument has no effect in Unicode build, because literals in sources are
139 Unicode strings; you have to use compiler-specific method of setting the right
140 charset when compiling with Unicode.
142 By default (i.e. when you use the first form), msgid strings are assumed
143 to be in English and written only using
7-bit ASCII characters.
145 If you have to deal with non-English strings or
8-bit characters in the source
146 code, see the instructions in
147 \helpref{Writing non-English applications
}{nonenglishoverview
}.
150 \membersection{wxLocale::AddCatalogLookupPathPrefix
}\label{wxlocaleaddcataloglookuppathprefix
}
152 \func{void
}{AddCatalogLookupPathPrefix
}{\param{const wxString\&
}{prefix
}}
154 Add a prefix to the catalog lookup path: the message catalog files will be
155 looked up under prefix/<lang>/LC
\_MESSAGES, prefix/<lang> and prefix
158 This only applies to subsequent invocations of AddCatalog().
160 \membersection{wxLocale::AddLanguage
}\label{wxlocaleaddlanguage
}
162 \func{static void
}{AddLanguage
}{\param{const wxLanguageInfo\&
}{info
}}
164 Adds custom, user-defined language to the database of known languages. This
165 database is used in conjunction with the first form of
166 \helpref{Init
}{wxlocaleinit
}.
168 wxLanguageInfo is defined as follows:
171 struct WXDLLEXPORT wxLanguageInfo
173 int Language; // wxLanguage id
174 wxString CanonicalName; // Canonical name, e.g. fr_FR
176 wxUint32 WinLang, WinSublang; // Win32 language identifiers
177 // (LANG_xxxx, SUBLANG_xxxx)
179 wxString Description; // human-readable name of the language
184 {\it Language
} should be greater than wxLANGUAGE
\_USER\_DEFINED.
186 \perlnote{In wxPerl Wx::LanguageInfo has only one method:
\par
187 Wx::LanguageInfo->new( language, canonicalName, WinLang, WinSubLang, Description )
}
190 \membersection{wxLocale::FindLanguageInfo
}\label{wxlocalefindlanguageinfo
}
192 \func{static wxLanguageInfo *
}{FindLanguageInfo
}{\param{const wxString\&
}{locale
}}
194 This function may be used to find the language description structure for the
195 given 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
197 readable, language description ("Portuguese-Brazil").
199 Returns the information for the given language or
{\tt NULL
} if this language
200 is unknown. Note that even if the returned pointer is valid, the caller should
205 \helpref{GetLanguageInfo
}{wxlocalegetlanguageinfo
}
208 \membersection{wxLocale::GetCanonicalName
}\label{wxlocalegetcanonicalname
}
210 \constfunc{wxString
}{GetCanonicalName
}{\void}
212 Returns the canonical form of current locale name. Canonical form is the
213 one that is used on UNIX systems: it is a two- or five-letter string in xx or
214 xx
\_YY format, where xx is ISO
639 code of language and YY is ISO
3166 code of
215 the country. Examples are "en", "en
\_GB", "en
\_US" or "fr
\_FR".
217 This form is internally used when looking up message catalogs.
219 Compare
\helpref{GetSysName
}{wxlocalegetsysname
}.
224 \membersection{wxLocale::GetLanguage
}\label{wxlocalegetlanguage
}
226 \constfunc{int
}{GetLanguage
}{\void}
228 Returns
\helpref{wxLanguage
}{wxlanguage
} constant of current language.
229 Note that you can call this function only if you used the form of
230 \helpref{Init
}{wxlocaleinit
} that takes wxLanguage argument.
233 \membersection{wxLocale::GetLanguageInfo
}\label{wxlocalegetlanguageinfo
}
235 \constfunc{static wxLanguageInfo *
}{GetLanguageInfo
}{\param{int
}{lang
}}
237 Returns a pointer to wxLanguageInfo structure containing information about the
238 given language or
{\tt NULL
} if this language is unknown. Note that even if the
239 returned pointer is valid, the caller should
{\it not
} delete it.
241 See
\helpref{AddLanguage
}{wxlocaleaddlanguage
} for the wxLanguageInfo
244 As with
\helpref{Init
}{wxlocaleinit
},
\texttt{wxLANGUAGE
\_DEFAULT} has the
245 special meaning if passed as an argument to this function and in this case the
246 result of
\helpref{GetSystemLanguage()
}{wxlocalegetsystemlanguage
} is used.
249 \membersection{wxLocale::GetLanguageName
}\label{wxlocalegetlanguagename
}
251 \constfunc{static wxString
}{GetLanguageName
}{\param{int
}{lang
}}
253 Returns English name of the given language or empty string if this
256 See
\helpref{GetLanguageInfo
}{wxlocalegetlanguageinfo
} for a remark about
257 special meaning of
\texttt{wxLANGUAGE
\_DEFAULT}.
260 \membersection{wxLocale::GetLocale
}\label{wxlocalegetlocale
}
262 \constfunc{const wxString\&
}{GetLocale
}{\void}
264 Returns the locale name as passed to the constructor or
265 \helpref{Init()
}{wxlocaleinit
}. This is full, human-readable name,
266 e.g. "English" or "French".
270 \membersection{wxLocale::GetName
}\label{wxlocalegetname
}
272 \constfunc{const wxString\&
}{GetName
}{\void}
274 Returns the current short name for the locale (as given to the constructor or
275 the Init() function).
278 \membersection{wxLocale::GetString
}\label{wxlocalegetstring
}
280 \constfunc{const wxString\&
}{GetString
}{\param{const wxString\&
}{origString
},
\param{const wxString\&
}{domain = wxEmptyString
}}
282 \constfunc{const wxString\&
}{GetString
}{\param{const wxString\&
}{origString
},
\param{const wxString\&
}{origString2
},
\param{size
\_t }{n
},
\param{const wxString\&
}{domain = NULL
}}
284 Retrieves the translation for a string in all loaded domains unless the szDomain
285 parameter is specified (and then only this catalog/domain is searched).
287 Returns original string if translation is not available
288 (in this case an error message is generated the first time
289 a string is not found; use
\helpref{wxLogNull
}{wxlogoverview
} to suppress it).
291 The second form is used when retrieving translation of string that has
292 different singular and plural form in English or different plural forms in some
293 other language. It takes two extra arguments:
\arg{origString
}
294 parameter must contain the singular form of the string to be converted.
295 It is also used as the key for the search in the catalog.
296 The
\arg{origString2
} parameter is the plural form (in English).
297 The parameter
\arg{n
} is used to determine the plural form. If no
298 message catalog is found
\arg{origString
} is returned if `n ==
1',
299 otherwise
\arg{origString2
}.
300 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 This method is called by the
\helpref{wxGetTranslation
}{wxgettranslation
}
303 function and
\helpref{\_()
}{underscore
} macro.
307 Domains are searched in the last to first order, i.e. catalogs
308 added later override those added before.
311 \membersection{wxLocale::GetHeaderValue
}\label{wxlocalegetheadervalue
}
313 \constfunc{wxString
}{GetHeaderValue
}{\param{const wxString\&
}{header
},
\param{const wxString\&
}{domain = wxEmptyString
}}
315 Returns the header value for header
\arg{header
}. The search for
\arg{header
} is case sensitive. If an
\arg{domain
}
316 is passed, this domain is searched. Else all domains will be searched until a header has been found.
317 The return value is the value of the header if found. Else this will be empty.
319 \membersection{wxLocale::GetSysName
}\label{wxlocalegetsysname
}
321 \constfunc{wxString
}{GetSysName
}{\void}
323 Returns current platform-specific locale name as passed to setlocale().
325 Compare
\helpref{GetCanonicalName
}{wxlocalegetcanonicalname
}.
329 \membersection{wxLocale::GetSystemEncoding
}\label{wxlocalegetsystemencoding
}
331 \constfunc{static wxFontEncoding
}{GetSystemEncoding
}{\void}
333 Tries to detect the user's default font encoding.
334 Returns
\helpref{wxFontEncoding
}{wxfont
} value or
335 {\bf wxFONTENCODING
\_SYSTEM} if it couldn't be determined.
338 \membersection{wxLocale::GetSystemEncodingName
}\label{wxlocalegetsystemencodingname
}
340 \constfunc{static wxString
}{GetSystemEncodingName
}{\void}
342 Tries to detect the name of the user's default font encoding. This string isn't
343 particularly useful for the application as its form is platform-dependent and
344 so you should probably use
345 \helpref{GetSystemEncoding
}{wxlocalegetsystemencoding
} instead.
347 Returns a user-readable string value or an empty string if it couldn't be
351 \membersection{wxLocale::GetSystemLanguage
}\label{wxlocalegetsystemlanguage
}
353 \constfunc{static int
}{GetSystemLanguage
}{\void}
355 Tries to detect the user's default language setting.
356 Returns
\helpref{wxLanguage
}{wxlanguage
} value or
357 {\bf wxLANGUAGE
\_UNKNOWN} if the language-guessing algorithm failed.
361 \membersection{wxLocale::Init
}\label{wxlocaleinit
}
364 \func{bool
}{Init
}{\param{int
}{language = wxLANGUAGE
\_DEFAULT},
\param{int
}{flags =
365 wxLOCALE
\_LOAD\_DEFAULT | wxLOCALE
\_CONV\_ENCODING}}
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
}}
369 The second form is deprecated, use the first one unless you know what you are
373 \wxheading{Parameters
}
375 \docparam{language
}{\helpref{wxLanguage
}{wxlanguage
} identifier of the locale.
376 wxLANGUAGE
\_DEFAULT has special meaning -- wxLocale will use system's default
377 language (see
\helpref{GetSystemLanguage
}{wxlocalegetsystemlanguage
}).
}
379 \docparam{flags
}{Combination of the following:
382 \begin{twocollist
}\itemsep=
0pt
383 \twocolitem{\windowstyle{wxLOCALE
\_LOAD\_DEFAULT}}{Load the message catalog
384 for the given locale containing the translations of standard wxWidgets messages
386 \twocolitem{\windowstyle{wxLOCALE
\_CONV\_ENCODING}}{Automatically convert message
387 catalogs to platform's default encoding. Note that it will do only basic
388 conversion between well-known pair like iso8859-
1 and windows-
1252 or
389 iso8859-
2 and windows-
1250. See
\helpref{Writing non-English applications
}{nonenglishoverview
} for detailed
390 description of this behaviour. Note that this flag is meaningless in Unicode build.
}
394 \docparam{name
}{The name of the locale. Only used in diagnostic messages.
}
396 \docparam{short
}{The standard
2 letter locale abbreviation; it is used as the
397 directory prefix when looking for the message catalog files.
}
399 \docparam{locale
}{The parameter for the call to setlocale(). Note that it is
402 \docparam{bLoadDefault
}{May be set to false to prevent loading of the message catalog
403 for the given locale containing the translations of standard wxWidgets messages.
404 This parameter would be rarely used in normal circumstances.
}
406 \docparam{bConvertEncoding
}{May be set to true to do automatic conversion of message
407 catalogs to platform's native encoding. Note that it will do only basic
408 conversion between well-known pair like iso8859-
1 and windows-
1252 or
409 iso8859-
2 and windows-
1250.
410 See
\helpref{Writing non-English applications
}{nonenglishoverview
} for detailed
411 description of this behaviour.
}
414 The call of this function has several global side effects which you should
415 understand: first of all, the application locale is changed - note that this
416 will affect many of standard C library functions such as printf() or strftime().
417 Second, this wxLocale object becomes the new current global locale for the
418 application and so all subsequent calls to
419 \helpref{wxGetTranslation()
}{wxgettranslation
} will try to
420 translate the messages using the message catalogs for this locale.
422 Returns true on success or false if the given locale couldn't be set.
425 \membersection{wxLocale::IsAvailable
}\label{wxlocaleisavailable
}
427 \func{static bool
}{IsAvailable
}{\param{int
}{lang
}}
429 Check whether the operating system and/or C run time environment supports
430 this locale. For example in Windows
2000 and Windows XP, support for many
431 locales is not installed by default. Returns
\true if the locale is
434 The argument
\arg{lang
} is the wxLanguage identifier. To obtain this for a
435 given a two letter ISO language code, use
436 \helpref{FindLanguageInfo
}{wxlocalefindlanguageinfo
} to obtain its
437 wxLanguageInfo structure. See
\helpref{AddLanguage
}{wxlocaleaddlanguage
} for
438 the wxLanguageInfo description.
443 \membersection{wxLocale::IsLoaded
}\label{wxlocaleisloaded
}
445 \constfunc{bool
}{IsLoaded
}{\param{const char*
}{domain
}}
447 Check if the given catalog is loaded, and returns true if it is.
449 According to GNU gettext tradition, each catalog
450 normally corresponds to 'domain' which is more or less the application name.
452 See also:
\helpref{AddCatalog
}{wxlocaleaddcatalog
}
455 \membersection{wxLocale::IsOk
}\label{wxlocaleisok
}
457 \constfunc{bool
}{IsOk
}{\void}
459 Returns true if the locale could be set successfully.