wx.Locale class encapsulates all language-dependent settings and is a generalization of the C locale concept.
In wxWidgets this class manages current locale. It also initializes and activates wx.Translations object that manages message catalogs.
For a list of the supported languages, please see wx.Language enum values. These constants may be used to specify the language in wx.Locale.Init
and are returned by wx.Locale.GetSystemLanguage
.
This is the default constructor and it does nothing to initialize the object: |
|
Calls Translations.AddCatalog(const String&). |
|
Calls |
|
Adds custom, user-defined language to the database of known languages. |
|
This function may be used to find the language description structure for the given locale, specified either as a two letter |
|
Returns the canonical form of current locale name. |
|
Calls |
|
Get the values of the given locale-dependent datum. |
|
Returns the wx.Language constant of current language. |
|
Returns canonical name (see |
|
Returns a pointer to wx.LanguageInfo structure containing information about the given language or |
|
Returns English name of the given language or empty string if this language is unknown. |
|
Returns the locale name as passed to the constructor or |
|
Returns the current short name for the locale (as given to the constructor or the |
|
Get the values of a locale datum in the OS locale. |
|
Calls GetTranslation(const String&, String&). |
|
Returns current platform-specific locale name as passed to setlocale(). |
|
Tries to detect the user’s default font encoding. |
|
Tries to detect the name of the user’s default font encoding. |
|
Tries to detect the user’s default locale setting. |
|
Initializes the wx.Locale instance. |
|
Check whether the operating system and/or C run time environment supports this locale. |
|
Calls |
|
Returns |
|
See |
|
See |
|
See |
|
See |
|
See |
wx.
Locale
(object)¶Possible constructors:
Locale()
Locale(language, flags=LOCALE_LOAD_DEFAULT)
Locale(name, shortName="", locale="",
bLoadDefault=True)
Locale class encapsulates all language-dependent settings and is a generalization of the C locale concept.
__init__
(self, *args, **kw)¶__init__ (self)
This is the default constructor and it does nothing to initialize the object: Init
must be used to do that.
__init__ (self, language, flags=LOCALE_LOAD_DEFAULT)
See Init
for parameters description.
language (int) –
flags (int) –
__init__ (self, name, shortName=””, locale=””, bLoadDefault=True)
See Init
for parameters description.
The call of this function has several global side effects which you should understand: first of all, the application locale is changed - note that this will affect many of standard C library functions such as printf() or strftime(). Second, this wx.Locale object becomes the new current global locale for the application and so all subsequent calls to wx.GetTranslation
will try to translate the messages using the message catalogs for this locale.
name (string) –
shortName (string) –
locale (string) –
bLoadDefault (bool) –
AddCatalog
(self, *args, **kw)¶AddCatalog (self, domain)
Calls Translations.AddCatalog(const String&).
domain (string) –
bool
AddCatalog (self, domain, msgIdLanguage)
Calls wx.Translations.AddCatalog
.
domain (string) –
msgIdLanguage (Language) –
bool
AddCatalog (self, domain, msgIdLanguage, msgIdCharset)
Calls wx.Translations.AddCatalog
.
domain (string) –
msgIdLanguage (Language) –
msgIdCharset (string) –
bool
AddCatalogLookupPathPrefix
(prefix)¶Calls wx.FileTranslationsLoader.AddCatalogLookupPathPrefix
.
prefix (string) –
AddLanguage
(info)¶Adds custom, user-defined language to the database of known languages.
This database is used in conjunction with the first form of Init
.
info (wx.LanguageInfo) –
FindLanguageInfo
(locale)¶This function may be used to find the language description structure for the given locale, specified either as a two letter ISO
language code (for example, “pt”), a language code followed by the country code (“pt_BR”) or a full, human readable, language description (“Portuguese_Brazil”).
Returns the information for the given language or None
if this language is unknown. Note that even if the returned pointer is valid, the caller should not delete it.
locale (string) –
See also
GetCanonicalName
(self)¶Returns the canonical form of current locale name.
Canonical form is the one that is used on UNIX
systems: it is a two- or five-letter string in xx or xx_YY format, where xx is ISO
639 code of language and YY
is ISO
3166 code of the country. Examples are “en”, “en_GB”, “en_US” or “fr_FR”. This form is internally used when looking up message catalogs. Compare GetSysName
.
string
GetHeaderValue
(self, header, domain="")¶Calls wx.Translations.GetHeaderValue
.
header (string) –
domain (string) –
string
GetInfo
(index, cat=LOCALE_CAT_DEFAULT)¶Get the values of the given locale-dependent datum.
This function returns the value of the locale-specific option specified by the given index.
index (LocaleInfo) – One of the elements of LocaleInfo enum.
cat (LocaleCategory) – The category to use with the given index or wx.LOCALE_CAT_DEFAULT
if the index can only apply to a single category.
string
The option value or empty string if the function failed.
GetLanguage
(self)¶Returns the wx.Language constant of current language.
Note that you can call this function only if you used the form of Init
that takes wx.Language argument.
int
GetLanguageCanonicalName
(lang)¶Returns canonical name (see GetCanonicalName
) of the given language or empty string if this language is unknown.
See GetLanguageInfo
for a remark about special meaning of LANGUAGE_DEFAULT
.
lang (int) –
string
New in version 2.9.1.
GetLanguageInfo
(lang)¶Returns a pointer to wx.LanguageInfo structure containing information about the given language or None
if this language is unknown.
Note that even if the returned pointer is valid, the caller should not delete it.
See AddLanguage
for the wx.LanguageInfo description. As with Init
, LANGUAGE_DEFAULT
has the special meaning if passed as an argument to this function and in this case the result of GetSystemLanguage
is used.
lang (int) –
GetLanguageName
(lang)¶Returns English name of the given language or empty string if this language is unknown.
See GetLanguageInfo
for a remark about special meaning of LANGUAGE_DEFAULT
.
lang (int) –
string
GetLocale
(self)¶Returns the locale name as passed to the constructor or Init
.
This is a full, human-readable name, e.g. “English” or “French”.
string
GetName
(self)¶Returns the current short name for the locale (as given to the constructor or the Init
function).
string
GetOSInfo
(index, cat=LOCALE_CAT_DEFAULT)¶Get the values of a locale datum in the OS locale.
This function shouldn’t be used in the new code, use UILocale.GetInfo
instead.
This function is similar to GetInfo
and, in fact, identical to it under non-MSW systems. Under MSW it differs from it when no locale had been explicitly set: GetInfo
returns the values corresponding to the “C” locale used by the standard library functions, while this method returns the values used by the OS which, in Windows case, correspond to the user settings in the control panel.
index (LocaleInfo) –
cat (LocaleCategory) –
string
New in version 4.1/wxWidgets-3.1.0.
GetString
(self, *args, **kw)¶GetString (self, origString, domain=””)
Calls GetTranslation(const String&, String&).
origString (string) –
domain (string) –
string
GetString (self, origString, origString2, n, domain=””)
Calls GetTranslation(const String&, String&, unsigned, String&).
origString (string) –
origString2 (string) –
n –
domain (string) –
string
GetSysName
(self)¶Returns current platform-specific locale name as passed to setlocale().
Compare GetCanonicalName
.
string
GetSystemEncoding
()¶Tries to detect the user’s default font encoding.
Returns wx.FontEncoding value or FONTENCODING_SYSTEM
if it couldn’t be determined.
GetSystemEncodingName
()¶Tries to detect the name of the user’s default font encoding.
This string isn’t particularly useful for the application as its form is platform-dependent and so you should probably use GetSystemEncoding
instead.
Returns a user-readable string value or an empty string if it couldn’t be determined.
string
GetSystemLanguage
()¶Tries to detect the user’s default locale setting.
Returns the wx.Language value or LANGUAGE_UNKNOWN
if the locale is not recognized, as can notably happen when combining any language with a region where this language is not typically spoken.
int
Note
This function is somewhat misleading, as it uses the default system locale to determine its return value, and not just the system language. It is preserved for backwards compatibility, but to actually get the language, and not locale, used by the system by default, call UILocale.GetSystemLanguage
instead.
See also
Init
(self, *args, **kw)¶Init (self, language=LANGUAGE_DEFAULT, flags=LOCALE_LOAD_DEFAULT)
Initializes the wx.Locale instance.
The call of this function has several global side effects which you should understand: first of all, the application locale is changed - note that this will affect many of standard C library functions such as printf() or strftime(). Second, this wx.Locale object becomes the new current global locale for the application and so all subsequent calls to wx.GetTranslation
will try to translate the messages using the message catalogs for this locale.
language (int) – wx.Language identifier of the locale. It can be either some concrete language, e.g. LANGUAGE_ESPERANTO
, or a special value LANGUAGE_DEFAULT
which means that wx.Locale should use system’s default language (see GetSystemLanguage
). Notice that the value LANGUAGE_UNKNOWN
is not allowed here.
flags (int) – Combination of the following:
wx.LOCALE_LOAD_DEFAULT
: Load the message catalog for the given locale containing the translations of standard wxWidgets messages automatically.
wx.LOCALE_DONT_LOAD_DEFAULT
: Negation of wx.LOCALE_LOAD_DEFAULT
.
bool
True
on success or False
if the given locale couldn’t be set.
Init (self, name, shortName=””, locale=””, bLoadDefault=True)
name (string) – The name of the locale. Only used in diagnostic messages.
shortName (string) – The standard 2 letter locale abbreviation; it is used as the directory prefix when looking for the message catalog files.
locale (string) – The parameter for the call to setlocale(). Note that it is platform-specific.
bLoadDefault (bool) – May be set to False
to prevent loading of the message catalog for the given locale containing the translations of standard wxWidgets messages. This parameter would be rarely used in normal circumstances.
bool
Deprecated
This form is deprecated, use the other one unless you know what you are doing.
IsAvailable
(lang)¶Check whether the operating system and/or C run time environment supports this locale.
For example in Windows, support for many locales is not installed by default. Returns True
if the locale is supported.
The argument lang is the wx.Language identifier. To obtain this for a given a two letter ISO
language code, use FindLanguageInfo
to obtain its wx.LanguageInfo structure. See AddLanguage
for the wx.LanguageInfo description.
lang (int) –
bool
New in version 2.7.1..
IsLoaded
(self, domain)¶Calls wx.Translations.IsLoaded
.
domain (string) –
bool
IsOk
(self)¶Returns True
if the locale could be set successfully.
bool
__bool__
(self)¶int
__nonzero__
(self)¶int
CanonicalName
¶See GetCanonicalName
Language
¶See GetLanguage
SysName
¶See GetSysName