1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of wxLocale
4 // Author: wxWidgets team
5 // Licence: wxWindows licence
6 /////////////////////////////////////////////////////////////////////////////
9 This is the layout direction stored in wxLanguageInfo and returned by
10 wxApp::GetLayoutDirection(), wxWindow::GetLayoutDirection(),
11 wxDC::GetLayoutDirection() for RTL (right-to-left) languages support.
13 enum wxLayoutDirection
21 Encapsulates a ::wxLanguage identifier together with OS-specific information
22 related to that language.
25 In wxPerl @c Wx::LanguageInfo has only one method:
26 - Wx::LanguageInfo->new(language, canonicalName, WinLang, WinSubLang, Description)
32 /// It should be greater than @c wxLANGUAGE_USER_DEFINED when defining your own
33 /// language info structure.
36 /// Canonical name of the language, e.g. @c fr_FR.
37 wxString CanonicalName
;
41 Win32 language identifiers (LANG_xxxx, SUBLANG_xxxx).
45 wxUint32 WinLang
, WinSublang
;
48 /// Human-readable name of the language.
51 /// The layout direction used for this language.
52 wxLayoutDirection LayoutDirection
;
54 /// Return the LCID corresponding to this language.
56 wxUint32
GetLCID() const;
58 /// Return the locale name corresponding to this language usable with
59 /// @c setlocale() on the current system.
60 wxString
GetLocaleName() const;
65 The category of locale settings.
67 @see wxLocale::GetInfo()
71 /// Number formatting.
74 /// Date/time formatting.
77 /// Monetary values formatting.
81 Default category for the wxLocaleInfo value.
83 This category can be used for values which only make sense for a single
84 category, e.g. wxLOCALE_SHORT_DATE_FMT which can only be used with
85 wxLOCALE_CAT_DATE. As this is the default value of the second parameter
86 of wxLocale::GetInfo(), wxLOCALE_CAT_DATE can be omitted when asking
87 for wxLOCALE_SHORT_DATE_FMT value.
95 The values understood by wxLocale::GetInfo().
97 Note that for the @c wxLOCALE_*_FMT constants (the date and time formats),
98 the strings returned by wxLocale::GetInfo() use strftime() or,
99 equivalently, wxDateTime::Format() format. If the relevant format
100 couldn't be determined, an empty string is returned -- there is no
101 fallback value so that the application could determine the best course
102 of actions itself in such case.
104 All of these values are used with @c wxLOCALE_CAT_DATE in wxLocale::GetInfo() or,
105 more typically, with @c wxLOCALE_CAT_DEFAULT as they only apply to a single category.
110 The thousands separator.
112 This value can be used with either wxLOCALE_CAT_NUMBER or
113 wxLOCALE_CAT_MONEY categories.
115 wxLOCALE_THOUSANDS_SEP
,
118 The character used as decimal point.
120 This value can be used with either wxLOCALE_CAT_NUMBER or
121 wxLOCALE_CAT_MONEY categories.
123 wxLOCALE_DECIMAL_POINT
,
128 Notice that short and long date formats may be the same under POSIX
129 systems currently but may, and typically are, different under MSW or OS X.
133 wxLOCALE_SHORT_DATE_FMT
,
140 wxLOCALE_LONG_DATE_FMT
,
143 Date and time format.
147 wxLOCALE_DATE_TIME_FMT
,
161 wxLocale class encapsulates all language-dependent settings and is a
162 generalization of the C locale concept.
164 In wxWidgets this class manages current locale. It also initializes and
165 activates wxTranslations object that manages message catalogs.
167 For a list of the supported languages, please see ::wxLanguage enum values.
168 These constants may be used to specify the language in wxLocale::Init and
169 are returned by wxLocale::GetSystemLanguage.
172 In wxPerl you can't use the '_' function name, so
173 the @c Wx::Locale module can export the @c gettext and
174 @c gettext_noop under any given name.
177 # this imports gettext ( equivalent to Wx::GetTranslation
178 # and gettext_noop ( a noop )
180 use Wx::Locale qw(:default);
185 print gettext( "Panic!" );
187 button = Wx::Button-new( window, -1, gettext( "Label" ) );
190 If you need to translate a lot of strings, then adding gettext( ) around
191 each one is a long task ( that is why _( ) was introduced ), so just choose
192 a shorter name for gettext:
195 use Wx::Locale 'gettext' = 't',
196 'gettext_noop' = 'gettext_noop';
201 print t( "Panic!!" );
210 @see @ref overview_i18n, @ref page_samples_internat, wxXLocale, wxTranslations
216 This is the default constructor and it does nothing to initialize the object:
217 Init() must be used to do that.
222 See Init() for parameters description.
224 wxLocale(int language
, int flags
= wxLOCALE_LOAD_DEFAULT
);
227 See Init() for parameters description.
229 The call of this function has several global side effects which you should
230 understand: first of all, the application locale is changed - note that this
231 will affect many of standard C library functions such as printf() or strftime().
232 Second, this wxLocale object becomes the new current global locale for the
233 application and so all subsequent calls to ::wxGetTranslation() will try to
234 translate the messages using the message catalogs for this locale.
236 wxLocale(const wxString
& name
,
237 const wxString
& shortName
= wxEmptyString
,
238 const wxString
& locale
= wxEmptyString
,
239 bool bLoadDefault
= true);
242 The destructor, like the constructor, also has global side effects: the
243 previously set locale is restored and so the changes described in
244 Init() documentation are rolled back.
249 Calls wxTranslations::AddCatalog(const wxString&).
251 bool AddCatalog(const wxString
& domain
);
254 Calls wxTranslations::AddCatalog(const wxString&, wxLanguage).
256 bool AddCatalog(const wxString
& domain
, wxLanguage msgIdLanguage
);
259 Calls wxTranslations::AddCatalog(const wxString&, wxLanguage, const wxString&).
261 bool AddCatalog(const wxString
& domain
, wxLanguage msgIdLanguage
,
262 const wxString
& msgIdCharset
);
265 Calls wxFileTranslationsLoader::AddCatalogLookupPathPrefix().
267 static void AddCatalogLookupPathPrefix(const wxString
& prefix
);
270 Adds custom, user-defined language to the database of known languages.
271 This database is used in conjunction with the first form of Init().
273 static void AddLanguage(const wxLanguageInfo
& info
);
276 This function may be used to find the language description structure for the
277 given locale, specified either as a two letter ISO language code (for example,
278 "pt"), a language code followed by the country code ("pt_BR") or a full, human
279 readable, language description ("Portuguese-Brazil").
281 Returns the information for the given language or @NULL if this language
282 is unknown. Note that even if the returned pointer is valid, the caller
283 should @e not delete it.
285 @see GetLanguageInfo()
287 static const wxLanguageInfo
* FindLanguageInfo(const wxString
& locale
);
290 Returns the canonical form of current locale name. Canonical form is the
291 one that is used on UNIX systems: it is a two- or five-letter string in xx or
292 xx_YY format, where xx is ISO 639 code of language and YY is ISO 3166 code of
293 the country. Examples are "en", "en_GB", "en_US" or "fr_FR".
294 This form is internally used when looking up message catalogs.
295 Compare GetSysName().
297 wxString
GetCanonicalName() const;
300 Calls wxTranslations::GetHeaderValue().
302 wxString
GetHeaderValue(const wxString
& header
,
303 const wxString
& domain
= wxEmptyString
) const;
306 Returns the ::wxLanguage constant of current language.
308 Note that you can call this function only if you used the form of
309 Init() that takes ::wxLanguage argument.
311 int GetLanguage() const;
314 Returns a pointer to wxLanguageInfo structure containing information about
315 the given language or @NULL if this language is unknown. Note that even if
316 the returned pointer is valid, the caller should @e not delete it.
318 See AddLanguage() for the wxLanguageInfo description.
319 As with Init(), @c wxLANGUAGE_DEFAULT has the special meaning if passed
320 as an argument to this function and in this case the result of
321 GetSystemLanguage() is used.
323 static const wxLanguageInfo
* GetLanguageInfo(int lang
);
326 Returns English name of the given language or empty string if this
329 See GetLanguageInfo() for a remark about special meaning of @c wxLANGUAGE_DEFAULT.
331 static wxString
GetLanguageName(int lang
);
334 Returns canonical name (see GetCanonicalName()) of the given language
335 or empty string if this language is unknown.
337 See GetLanguageInfo() for a remark about special meaning of @c wxLANGUAGE_DEFAULT.
341 static wxString
GetLanguageCanonicalName(int lang
);
344 Returns the locale name as passed to the constructor or Init().
346 This is a full, human-readable name, e.g. "English" or "French".
348 const wxString
& GetLocale() const;
351 Returns the current short name for the locale (as given to the constructor or
352 the Init() function).
354 const wxString
& GetName() const;
357 Calls wxTranslations::GetString(const wxString&, const wxString&) const.
359 virtual const wxString
& GetString(const wxString
& origString
,
360 const wxString
& domain
= wxEmptyString
) const;
363 Calls wxTranslations::GetString(const wxString&, const wxString&, unsigned, const wxString&) const.
365 virtual const wxString
& GetString(const wxString
& origString
,
366 const wxString
& origString2
, unsigned n
,
367 const wxString
& domain
= wxEmptyString
) const;
370 Returns current platform-specific locale name as passed to setlocale().
371 Compare GetCanonicalName().
373 wxString
GetSysName() const;
376 Tries to detect the user's default font encoding.
377 Returns wxFontEncoding() value or @c wxFONTENCODING_SYSTEM if it
378 couldn't be determined.
380 static wxFontEncoding
GetSystemEncoding();
383 Tries to detect the name of the user's default font encoding.
384 This string isn't particularly useful for the application as its form is
385 platform-dependent and so you should probably use GetSystemEncoding() instead.
387 Returns a user-readable string value or an empty string if it couldn't be
390 static wxString
GetSystemEncodingName();
393 Tries to detect the user's default locale setting.
395 Returns the ::wxLanguage value or @c wxLANGUAGE_UNKNOWN if the language-guessing
398 @note This function works with @em locales and returns the user's default
399 locale. This may be, and usually is, the same as their preferred UI
400 language, but it's not the same thing. Use wxTranslation to obtain
401 @em language information.
403 @see wxTranslations::GetBestTranslation().
405 static int GetSystemLanguage();
408 Get the values of the given locale-dependent datum.
410 This function returns the value of the locale-specific option specified
411 by the given @a index.
414 One of the elements of wxLocaleInfo enum.
416 The category to use with the given index or wxLOCALE_CAT_DEFAULT if
417 the index can only apply to a single category.
419 The option value or empty string if the function failed.
421 static wxString
GetInfo(wxLocaleInfo index
,
422 wxLocaleCategory cat
= wxLOCALE_CAT_DEFAULT
);
425 Initializes the wxLocale instance.
427 The call of this function has several global side effects which you should
428 understand: first of all, the application locale is changed - note that
429 this will affect many of standard C library functions such as printf()
431 Second, this wxLocale object becomes the new current global locale for
432 the application and so all subsequent calls to wxGetTranslation() will
433 try to translate the messages using the message catalogs for this locale.
436 ::wxLanguage identifier of the locale.
437 @c wxLANGUAGE_DEFAULT has special meaning -- wxLocale will use system's
438 default language (see GetSystemLanguage()).
440 Combination of the following:
441 - wxLOCALE_LOAD_DEFAULT: Load the message catalog for the given locale
442 containing the translations of standard wxWidgets messages
444 - wxLOCALE_DONT_LOAD_DEFAULT: Negation of wxLOCALE_LOAD_DEFAULT.
446 @return @true on success or @false if the given locale couldn't be set.
448 bool Init(int language
= wxLANGUAGE_DEFAULT
,
449 int flags
= wxLOCALE_LOAD_DEFAULT
);
453 This form is deprecated, use the other one unless you know what you are doing.
456 The name of the locale. Only used in diagnostic messages.
458 The standard 2 letter locale abbreviation; it is used as the
459 directory prefix when looking for the message catalog files.
461 The parameter for the call to setlocale().
462 Note that it is platform-specific.
464 May be set to @false to prevent loading of the message catalog for the
465 given locale containing the translations of standard wxWidgets messages.
466 This parameter would be rarely used in normal circumstances.
468 bool Init(const wxString
& name
, const wxString
& shortName
= wxEmptyString
,
469 const wxString
& locale
= wxEmptyString
, bool bLoadDefault
= true);
472 Check whether the operating system and/or C run time environment supports
473 this locale. For example in Windows 2000 and Windows XP, support for many
474 locales is not installed by default. Returns @true if the locale is
477 The argument @a lang is the ::wxLanguage identifier. To obtain this for a
478 given a two letter ISO language code, use FindLanguageInfo() to obtain its
479 wxLanguageInfo structure.
480 See AddLanguage() for the wxLanguageInfo description.
484 static bool IsAvailable(int lang
);
487 Calls wxTranslations::IsLoaded().
489 bool IsLoaded(const wxString
& domain
) const;
492 Returns @true if the locale could be set successfully.