phoenix_title 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 Class Hierarchy

Inheritance diagram for class Locale:

method_summary Methods Summary

__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(const String&).

AddCatalogLookupPathPrefix

Calls wx.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 wx.Translations.GetHeaderValue .

GetInfo

Get the values of the given locale-dependent datum.

GetLanguage

Returns the wx.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 wx.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).

GetOSInfo

Get the values of a locale datum in the OS locale.

GetString

Calls GetTranslation(const String&, String&).

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 locale setting.

Init

Initializes the wx.Locale instance.

IsAvailable

Check whether the operating system and/or C run time environment supports this locale.

IsLoaded

Calls wx.Translations.IsLoaded .

IsOk

Returns True if the locale could be set successfully.

__bool__

__nonzero__


api Class API

class 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.


Methods

__init__(self, *args, **kw)

overload 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
  • 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.

Parameters
  • name (string) –

  • shortName (string) –

  • locale (string) –

  • bLoadDefault (bool) –





AddCatalog(self, *args, **kw)

overload Overloaded Implementations:



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) –



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) –



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

wx.LanguageInfo

See also

GetLanguageInfo



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 .

Return type

string



GetHeaderValue(self, header, domain="")

Calls wx.Translations.GetHeaderValue .

Parameters
  • header (string) –

  • domain (string) –

Return type

string



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

string

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 of LANGUAGE_DEFAULT .

Parameters

lang (int) –

Return type

string

New 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 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

wx.LanguageInfo



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 of LANGUAGE_DEFAULT .

Parameters

lang (int) –

Return type

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”.

Return type

string



GetName(self)

Returns the current short name for the locale (as given to the constructor or the Init function).

Return type

string



static GetOSInfo(index, cat=LOCALE_CAT_DEFAULT)

Get the values of a locale datum in the OS locale.

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
Return type

string

New in version 4.1/wxWidgets-3.1.0.



GetString(self, *args, **kw)

overload Overloaded Implementations:



GetString (self, origString, domain=””)

Calls GetTranslation(const String&, String&).

Parameters
  • origString (string) –

  • domain (string) –

Return type

string



GetString (self, origString, origString2, n, domain=””)

Calls GetTranslation(const String&, String&, unsigned, String&).

Parameters
  • origString (string) –

  • origString2 (string) –

  • n

  • domain (string) –

Return type

string





GetSysName(self)

Returns current platform-specific locale name as passed to setlocale().

Compare GetCanonicalName .

Return type

string



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

wx.FontEncoding



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

string



static GetSystemLanguage()

Tries to detect the user’s default locale setting.

Returns the wx.Language value or LANGUAGE_UNKNOWN if the language-guessing algorithm failed.

Return type

int

Note

This function works with locales and returns the user’s default locale. This may be, and usually is, the same as their preferred UI language, but it’s not the same thing. Use Translation to obtain language information.



Init(self, *args, **kw)

overload Overloaded Implementations:



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. LANGUAGE_DEFAULT has special meaning – wx.Locale will use system’s default language (see GetSystemLanguage ).

  • 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.

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
  • 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, use FindLanguageInfo to obtain its wx.LanguageInfo structure. See AddLanguage for the wx.LanguageInfo description.

Parameters

lang (int) –

Return type

bool

New 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

int



__nonzero__(self)
Return type

int


Properties

CanonicalName

See GetCanonicalName



Language

See GetLanguage



Locale

See GetLocale



Name

See GetName



SysName

See GetSysName