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 Translations object that manages message catalogs.
For a list of the supported languages, please see Language enum values. These constants may be used to specify the language in Locale.Init and are returned by Locale.GetSystemLanguage .
If you need to translate a lot of strings, then adding gettext( ) around each one is a long task ( that is why _ was introduced ), so just choose a shorter name for gettext:
See also
Internationalization, XLocale, Translations
__init__ | This is the default constructor and it does nothing to initialize the object: Init must be used to do that. |
AddCatalog | Calls Translations.AddCatalog . |
AddCatalogLookupPathPrefix | Calls FileTranslationsLoader.AddCatalogLookupPathPrefix . |
AddLanguage | Adds custom, user-defined language to the database of known languages. |
FindLanguageInfo | 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”). |
GetCanonicalName | Returns the canonical form of current locale name. |
GetHeaderValue | Calls Translations.GetHeaderValue . |
GetInfo | Get the values of the given locale-dependent datum. |
GetLanguage | Returns the Language constant of current language. |
GetLanguageCanonicalName | Returns canonical name (see GetCanonicalName ) of the given language or empty string if this language is unknown. |
GetLanguageInfo | Returns a pointer to LanguageInfo structure containing information about the given language or None if this language is unknown. |
GetLanguageName | Returns English name of the given language or empty string if this language is unknown. |
GetLocale | Returns the locale name as passed to the constructor or Init . |
GetName | Returns the current short name for the locale (as given to the constructor or the Init function). |
GetString | Calls Translations.GetString . |
GetSysName | Returns current platform-specific locale name as passed to setlocale(). |
GetSystemEncoding | Tries to detect the user’s default font encoding. |
GetSystemEncodingName | Tries to detect the name of the user’s default font encoding. |
GetSystemLanguage | Tries to detect the user’s default language setting. |
Init | Initializes the Locale instance. |
IsAvailable | Check whether the operating system and/or C run time environment supports this locale. |
IsLoaded | Calls Translations.IsLoaded . |
IsOk | Returns True if the locale could be set successfully. |
__nonzero__ |
CanonicalName | See GetCanonicalName |
Language | See GetLanguage |
Locale | See GetLocale |
Name | See GetName |
SysName | See GetSysName |
Locale class encapsulates all language-dependent settings and is a generalization of the C locale concept.
Possible constructors:
Locale()
Locale(language, flags=LOCALE_LOAD_DEFAULT)
Locale(name, shortName='', locale='',
bLoadDefault=True)
Overloaded Implementations:
__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.
Parameters: |
|
---|
__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 Locale object becomes the new current global locale for the application and so all subsequent calls to GetTranslation will try to translate the messages using the message catalogs for this locale.
Parameters: |
|
---|
Calls Translations.AddCatalog .
Overloaded Implementations:
AddCatalog (self, domain)
Parameters: | domain (string) – |
---|---|
Return type: | bool |
AddCatalog (self, domain, msgIdLanguage)
Parameters: |
|
---|---|
Return type: | bool |
AddCatalog (self, domain, msgIdLanguage, msgIdCharset)
Parameters: |
|
---|---|
Return type: | bool |
Calls FileTranslationsLoader.AddCatalogLookupPathPrefix .
Parameters: | prefix (string) – |
---|
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 (LanguageInfo) – |
---|
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: | LanguageInfo |
See also
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 .
Return type: | string |
---|
Calls Translations.GetHeaderValue .
Parameters: |
|
---|---|
Return type: | string |
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: |
|
---|---|
Return type: | string |
Returns: | The option value or empty string if the function failed. |
Returns the Language constant of current language.
Note that you can call this function only if you used the form of Init that takes Language argument.
Return type: | int |
---|
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 .
Parameters: | lang (int) – |
---|---|
Return type: | string |
New in version 2.9.1.
Returns a pointer to 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 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.
Parameters: | lang (int) – |
---|---|
Return type: | LanguageInfo |
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 .
Parameters: | lang (int) – |
---|---|
Return type: | string |
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: | string |
---|
Returns the current short name for the locale (as given to the constructor or the Init function).
Return type: | string |
---|
Calls Translations.GetString .
Overloaded Implementations:
GetString (self, origString, domain=’‘)
Parameters: |
|
---|---|
Return type: | string |
GetString (self, origString, origString2, n, domain=’‘)
Parameters: |
|
---|---|
Return type: | string |
Returns current platform-specific locale name as passed to setlocale().
Compare GetCanonicalName .
Return type: | string |
---|
Tries to detect the user’s default font encoding.
Returns FontEncoding value or FONTENCODING_SYSTEM if it couldn’t be determined.
Return type: | FontEncoding |
---|
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: | string |
---|
Tries to detect the user’s default language setting.
Returns the Language value or LANGUAGE_UNKNOWN if the language-guessing algorithm failed.
Return type: | int |
---|
Overloaded Implementations:
Init (self, language=LANGUAGE_DEFAULT, flags=LOCALE_LOAD_DEFAULT)
Initializes the 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 Locale object becomes the new current global locale for the application and so all subsequent calls to GetTranslation will try to translate the messages using the message catalogs for this locale.
Parameters: |
|
---|---|
Return type: | bool |
Returns: | True on success or False if the given locale couldn’t be set. |
Init (self, name, shortName=’‘, locale=’‘, bLoadDefault=True)
Parameters: |
|
---|
The standard 2 letter locale abbreviation; it is used as the directory prefix when looking for the message catalog files.
Return type: | bool |
---|
Deprecated since version 2.9.4: This form is deprecated, use the other one unless you know what you are doing.
Check whether the operating system and/or C run time environment supports this locale.
For example in Windows 2000 and Windows XP, support for many locales is not installed by default. Returns True if the locale is supported.
The argument lang is the Language identifier. To obtain this for a given a two letter ISO language code, use FindLanguageInfo to obtain its LanguageInfo structure. See AddLanguage for the LanguageInfo description.
Parameters: | lang (int) – |
---|---|
Return type: | bool |
New in version 2.7.1..
Calls Translations.IsLoaded .
Parameters: | domain (string) – |
---|---|
Return type: | bool |
Returns True if the locale could be set successfully.
Return type: | bool |
---|
Return type: | int |
---|
See GetCanonicalName
See GetLanguage
See GetSysName