wx.Locale¶
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
.
Class Hierarchy¶
Methods Summary¶
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 |
|
Properties Summary¶
See |
|
See |
|
See |
|
See |
|
See |
Class API¶
- class wx.Locale(object)¶
Possible constructors:
Locale() -> None Locale(language, flags=LOCALE_LOAD_DEFAULT) -> None Locale(name, shortName='', locale='', bLoadDefault=True) -> None
Locale class encapsulates all language-dependent settings and is a generalization of the C locale concept.
Methods¶
- __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.- Return type:
None
__init__ (self, language, flags=LOCALE_LOAD_DEFAULT)
See
Init
for parameters description.- Parameters:
language (int)
flags (int)
- Return type:
None
__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.- Parameters:
name (string)
shortName (string)
locale (string)
bLoadDefault (bool)
- Return type:
None
- AddCatalog(self, *args, **kw)¶
-
AddCatalog (self, domain)
Calls Translations.AddCatalog(const String&).
- Parameters:
domain (string)
- Return type:
bool
AddCatalog (self, domain, msgIdLanguage)
Calls
wx.Translations.AddCatalog
.- Parameters:
domain (string)
msgIdLanguage (Language)
- Return type:
bool
AddCatalog (self, domain, msgIdLanguage, msgIdCharset)
Calls
wx.Translations.AddCatalog
.- Parameters:
domain (string)
msgIdLanguage (Language)
msgIdCharset (string)
- Return type:
bool
- static AddCatalogLookupPathPrefix(prefix)¶
Calls
wx.FileTranslationsLoader.AddCatalogLookupPathPrefix
.- Parameters:
prefix (string)
- Return type:
None
- static 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
.- Parameters:
info (wx.LanguageInfo)
- Return type:
None
- static 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.- Parameters:
locale (string)
- Return type:
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 isISO
639 code of language andYY
isISO
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. CompareGetSysName
.- Return type:
str
- GetHeaderValue(self, header, domain='')¶
Calls
wx.Translations.GetHeaderValue
.- Parameters:
header (string)
domain (string)
- Return type:
str
- static 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.
- Parameters:
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.
- Return type:
str
- Returns:
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.- Return type:
int
- static 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 ofLANGUAGE_DEFAULT
.- Parameters:
lang (int)
- Return type:
str
Added in version 2.9.1.
- static 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 withInit
,LANGUAGE_DEFAULT
has the special meaning if passed as an argument to this function and in this case the result ofGetSystemLanguage
is used.- Parameters:
lang (int)
- Return type:
- static 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 ofLANGUAGE_DEFAULT
.- Parameters:
lang (int)
- Return type:
str
- 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”.
- Return type:
str
- GetName(self)¶
Returns the current short name for the locale (as given to the constructor or the
Init
function).- Return type:
str
- static 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.- Parameters:
index (LocaleInfo)
cat (LocaleCategory)
- Return type:
str
Added in version 4.1/wxWidgets-3.1.0.
- GetString(self, *args, **kw)¶
-
GetString (self, origString, domain=’’)
Calls GetTranslation(const String&, String&).
- Parameters:
origString (string)
domain (string)
- Return type:
str
GetString (self, origString, origString2, n, domain=’’)
Calls GetTranslation(const String&, String&, unsigned, String&).
- Parameters:
origString (string)
origString2 (string)
n
domain (string)
- Return type:
str
- GetSysName(self)¶
Returns current platform-specific locale name as passed to setlocale().
Compare
GetCanonicalName
.- Return type:
str
- static GetSystemEncoding()¶
Tries to detect the user’s default font encoding.
Returns wx.FontEncoding value or
FONTENCODING_SYSTEM
if it couldn’t be determined.- Return type:
- static 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.
- Return type:
str
- static 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.- Return type:
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.- Parameters:
language (int) – wx.Language identifier of the locale. It can be either some concrete language, e.g.
LANGUAGE_ESPERANTO
, or a special valueLANGUAGE_DEFAULT
which means that wx.Locale should use system’s default language (seeGetSystemLanguage
). Notice that the valueLANGUAGE_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 ofwx.LOCALE_LOAD_DEFAULT
.
- Return type:
bool
- Returns:
True
on success orFalse
if the given locale couldn’t be set.
Init (self, name, shortName=’’, locale=’’, bLoadDefault=True)
- Parameters:
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.
- Return type:
bool
Deprecated
This form is deprecated, use the other one unless you know what you are doing.
- static 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, useFindLanguageInfo
to obtain its wx.LanguageInfo structure. SeeAddLanguage
for the wx.LanguageInfo description.- Parameters:
lang (int)
- Return type:
bool
Added in version 2.7.1..
- IsLoaded(self, domain)¶
Calls
wx.Translations.IsLoaded
.- Parameters:
domain (string)
- Return type:
bool
- IsOk(self)¶
Returns
True
if the locale could be set successfully.- Return type:
bool
- __bool__(self)¶
- Return type:
bool
- __nonzero__(self)¶
- Return type:
bool
Properties¶
- CanonicalName¶
See
GetCanonicalName
- Language¶
See
GetLanguage
- SysName¶
See
GetSysName