1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of wxLocale
4 // Author: wxWidgets team
6 // Licence: wxWindows licence
7 /////////////////////////////////////////////////////////////////////////////
10 This is the layout direction stored in wxLanguageInfo and returned by
11 wxApp::GetLayoutDirection(), wxWindow::GetLayoutDirection(),
12 wxDC::GetLayoutDirection() for RTL (right-to-left) languages support.
14 enum wxLayoutDirection
22 Encapsulates a ::wxLanguage indentifier together with OS-specific information
23 related to that language.
26 In wxPerl @c Wx::LanguageInfo has only one method:
27 - Wx::LanguageInfo->new(language, canonicalName, WinLang, WinSubLang, Description)
30 struct WXDLLIMPEXP_BASE wxLanguageInfo
33 /// It should be greater than @c wxLANGUAGE_USER_DEFINED when defining your own
34 /// language info structure.
37 /// Canonical name of the language, e.g. @c fr_FR.
38 wxString CanonicalName
;
42 Win32 language identifiers (LANG_xxxx, SUBLANG_xxxx).
46 wxUint32 WinLang
, WinSublang
;
49 /// Human-readable name of the language.
52 /// The layout direction used for this language.
53 wxLayoutDirection LayoutDirection
;
55 /// Return the LCID corresponding to this language.
57 wxUint32
GetLCID() const;
59 /// Return the locale name corresponding to this language usable with
60 /// @c setlocale() on the current system.
61 wxString
GetLocaleName() const;
66 The category of locale settings.
68 @see wxLocale::GetInfo()
72 /// Number formatting.
75 /// Date/time formatting.
78 /// Monetary values formatting.
82 Default category for the wxLocaleInfo value.
84 This category can be used for values which only make sense for a single
85 category, e.g. wxLOCALE_SHORT_DATE_FMT which can only be used with
86 wxLOCALE_CAT_DATE. As this is the default value of the second parameter
87 of wxLocale::GetInfo(), wxLOCALE_CAT_DATE can be omitted when asking
88 for wxLOCALE_SHORT_DATE_FMT value.
96 The values understood by wxLocale::GetInfo().
98 Note that for the @c wxLOCALE_*_FMT constants (the date and time formats),
99 the strings returned by wxLocale::GetInfo() use strftime() or,
100 equivalently, wxDateTime::Format() format. If the relevant format
101 couldn't be determined, an empty string is returned -- there is no
102 fallback value so that the application could determine the best course
103 of actions itself in such case.
105 All of these values are used with @c wxLOCALE_CAT_DATE in wxLocale::GetInfo() or,
106 more typically, with @c wxLOCALE_CAT_DEFAULT as they only apply to a single category.
111 The thousands separator.
113 This value can be used with either wxLOCALE_CAT_NUMBER or
114 wxLOCALE_CAT_MONEY categories.
116 wxLOCALE_THOUSANDS_SEP
,
119 The character used as decimal point.
121 This value can be used with either wxLOCALE_CAT_NUMBER or
122 wxLOCALE_CAT_MONEY categories.
124 wxLOCALE_DECIMAL_POINT
,
129 Notice that short and long date formats may be the same under POSIX
130 systems currently but may, and typically are, different under MSW or OS X.
134 wxLOCALE_SHORT_DATE_FMT
,
141 wxLOCALE_LONG_DATE_FMT
,
144 Date and time format.
148 wxLOCALE_DATE_TIME_FMT
,
162 wxLocale class encapsulates all language-dependent settings and is a
163 generalization of the C locale concept.
165 In wxWidgets this class manages current locale. It also initializes and
166 activates wxTranslations object that manages message catalogs.
168 For a list of the supported languages, please see ::wxLanguage enum values.
169 These constants may be used to specify the language in wxLocale::Init and
170 are returned by wxLocale::GetSystemLanguage.
173 In wxPerl you can't use the '_' function name, so
174 the @c Wx::Locale module can export the @c gettext and
175 @c gettext_noop under any given name.
178 # this imports gettext ( equivalent to Wx::GetTranslation
179 # and gettext_noop ( a noop )
181 use Wx::Locale qw(:default);
186 print gettext( "Panic!" );
188 button = Wx::Button-new( window, -1, gettext( "Label" ) );
191 If you need to translate a lot of strings, then adding gettext( ) around
192 each one is a long task ( that is why _( ) was introduced ), so just choose
193 a shorter name for gettext:
196 use Wx::Locale 'gettext' = 't',
197 'gettext_noop' = 'gettext_noop';
202 print t( "Panic!!" );
211 @see @ref overview_i18n, @ref page_samples_internat, wxXLocale, wxTranslations
217 This is the default constructor and it does nothing to initialize the object:
218 Init() must be used to do that.
223 See Init() for parameters description.
225 wxLocale(int language
, int flags
= wxLOCALE_LOAD_DEFAULT
);
228 See Init() for parameters description.
230 The call of this function has several global side effects which you should
231 understand: first of all, the application locale is changed - note that this
232 will affect many of standard C library functions such as printf() or strftime().
233 Second, this wxLocale object becomes the new current global locale for the
234 application and so all subsequent calls to ::wxGetTranslation() will try to
235 translate the messages using the message catalogs for this locale.
237 wxLocale(const wxString
& name
,
238 const wxString
& shortName
= wxEmptyString
,
239 const wxString
& locale
= wxEmptyString
,
240 bool bLoadDefault
= true);
243 The destructor, like the constructor, also has global side effects: the
244 previously set locale is restored and so the changes described in
245 Init() documentation are rolled back.
250 Calls wxTranslations::AddCatalog(const wxString&).
252 bool AddCatalog(const wxString
& domain
);
255 Calls wxTranslations::AddCatalog(const wxString&, wxLanguage).
257 bool AddCatalog(const wxString
& domain
, wxLanguage msgIdLanguage
);
260 Calls wxTranslations::AddCatalog(const wxString&, wxLanguage, const wxString&).
262 bool AddCatalog(const wxString
& domain
, wxLanguage msgIdLanguage
,
263 const wxString
& msgIdCharset
);
266 Calls wxFileTranslationsLoader::AddCatalogLookupPathPrefix().
268 static void AddCatalogLookupPathPrefix(const wxString
& prefix
);
271 Adds custom, user-defined language to the database of known languages.
272 This database is used in conjunction with the first form of Init().
274 static void AddLanguage(const wxLanguageInfo
& info
);
277 This function may be used to find the language description structure for the
278 given locale, specified either as a two letter ISO language code (for example,
279 "pt"), a language code followed by the country code ("pt_BR") or a full, human
280 readable, language description ("Portuguese-Brazil").
282 Returns the information for the given language or @NULL if this language
283 is unknown. Note that even if the returned pointer is valid, the caller
284 should @e not delete it.
286 @see GetLanguageInfo()
288 static const wxLanguageInfo
* FindLanguageInfo(const wxString
& locale
);
291 Returns the canonical form of current locale name. Canonical form is the
292 one that is used on UNIX systems: it is a two- or five-letter string in xx or
293 xx_YY format, where xx is ISO 639 code of language and YY is ISO 3166 code of
294 the country. Examples are "en", "en_GB", "en_US" or "fr_FR".
295 This form is internally used when looking up message catalogs.
296 Compare GetSysName().
298 wxString
GetCanonicalName() const;
301 Calls wxTranslations::GetHeaderValue().
303 wxString
GetHeaderValue(const wxString
& header
,
304 const wxString
& domain
= wxEmptyString
) const;
307 Returns the ::wxLanguage constant of current language.
309 Note that you can call this function only if you used the form of
310 Init() that takes ::wxLanguage argument.
312 int GetLanguage() const;
315 Returns a pointer to wxLanguageInfo structure containing information about
316 the given language or @NULL if this language is unknown. Note that even if
317 the returned pointer is valid, the caller should @e not delete it.
319 See AddLanguage() for the wxLanguageInfo description.
320 As with Init(), @c wxLANGUAGE_DEFAULT has the special meaning if passed
321 as an argument to this function and in this case the result of
322 GetSystemLanguage() is used.
324 static const wxLanguageInfo
* GetLanguageInfo(int lang
);
327 Returns English name of the given language or empty string if this
330 See GetLanguageInfo() for a remark about special meaning of @c wxLANGUAGE_DEFAULT.
332 static wxString
GetLanguageName(int lang
);
335 Returns canonical name (see GetCanonicalName()) of the given language
336 or empty string if this language is unknown.
338 See GetLanguageInfo() for a remark about special meaning of @c wxLANGUAGE_DEFAULT.
342 static wxString
GetLanguageCanonicalName(int lang
);
345 Returns the locale name as passed to the constructor or Init().
347 This is a full, human-readable name, e.g. "English" or "French".
349 const wxString
& GetLocale() const;
352 Returns the current short name for the locale (as given to the constructor or
353 the Init() function).
355 const wxString
& GetName() const;
358 Calls wxTranslations::GetString(const wxString&, const wxString&) const.
360 virtual const wxString
& GetString(const wxString
& origString
,
361 const wxString
& domain
= wxEmptyString
) const;
364 Calls wxTranslations::GetString(const wxString&, const wxString&, unsigned, const wxString&) const.
366 virtual const wxString
& GetString(const wxString
& origString
,
367 const wxString
& origString2
, unsigned n
,
368 const wxString
& domain
= wxEmptyString
) const;
371 Returns current platform-specific locale name as passed to setlocale().
372 Compare GetCanonicalName().
374 wxString
GetSysName() const;
377 Tries to detect the user's default font encoding.
378 Returns wxFontEncoding() value or @c wxFONTENCODING_SYSTEM if it
379 couldn't be determined.
381 static wxFontEncoding
GetSystemEncoding();
384 Tries to detect the name of the user's default font encoding.
385 This string isn't particularly useful for the application as its form is
386 platform-dependent and so you should probably use GetSystemEncoding() instead.
388 Returns a user-readable string value or an empty string if it couldn't be
391 static wxString
GetSystemEncodingName();
394 Tries to detect the user's default language setting.
396 Returns the ::wxLanguage value or @c wxLANGUAGE_UNKNOWN if the language-guessing
399 static int GetSystemLanguage();
402 Get the values of the given locale-dependent datum.
404 This function returns the value of the locale-specific option specified
405 by the given @a index.
408 One of the elements of wxLocaleInfo enum.
410 The category to use with the given index or wxLOCALE_CAT_DEFAULT if
411 the index can only apply to a single category.
413 The option value or empty string if the function failed.
415 static wxString
GetInfo(wxLocaleInfo index
,
416 wxLocaleCategory cat
= wxLOCALE_CAT_DEFAULT
);
419 Initializes the wxLocale instance.
421 The call of this function has several global side effects which you should
422 understand: first of all, the application locale is changed - note that
423 this will affect many of standard C library functions such as printf()
425 Second, this wxLocale object becomes the new current global locale for
426 the application and so all subsequent calls to wxGetTranslation() will
427 try to translate the messages using the message catalogs for this locale.
430 ::wxLanguage identifier of the locale.
431 @c wxLANGUAGE_DEFAULT has special meaning -- wxLocale will use system's
432 default language (see GetSystemLanguage()).
434 Combination of the following:
435 - wxLOCALE_LOAD_DEFAULT: Load the message catalog for the given locale
436 containing the translations of standard wxWidgets messages
438 - wxLOCALE_DONT_LOAD_DEFAULT: Negation of wxLOCALE_LOAD_DEFAULT.
440 @return @true on success or @false if the given locale couldn't be set.
442 bool Init(int language
= wxLANGUAGE_DEFAULT
,
443 int flags
= wxLOCALE_LOAD_DEFAULT
);
447 This form is deprecated, use the other one unless you know what you are doing.
450 The name of the locale. Only used in diagnostic messages.
452 The standard 2 letter locale abbreviation; it is used as the
453 directory prefix when looking for the message catalog files.
455 The parameter for the call to setlocale().
456 Note that it is platform-specific.
458 May be set to @false to prevent loading of the message catalog for the
459 given locale containing the translations of standard wxWidgets messages.
460 This parameter would be rarely used in normal circumstances.
462 bool Init(const wxString
& name
, const wxString
& shortName
= wxEmptyString
,
463 const wxString
& locale
= wxEmptyString
, bool bLoadDefault
= true);
466 Check whether the operating system and/or C run time environment supports
467 this locale. For example in Windows 2000 and Windows XP, support for many
468 locales is not installed by default. Returns @true if the locale is
471 The argument @a lang is the ::wxLanguage identifier. To obtain this for a
472 given a two letter ISO language code, use FindLanguageInfo() to obtain its
473 wxLanguageInfo structure.
474 See AddLanguage() for the wxLanguageInfo description.
478 static bool IsAvailable(int lang
);
481 Calls wxTranslations::IsLoaded().
483 bool IsLoaded(const wxString
& domain
) const;
486 Returns @true if the locale could be set successfully.