## wxLocale

wxLocale class encapsulates all language-dependent settings and is a generalization of the C locale concept.

In wxWindows this class manages message catalogs which contain the translations of the strings used to the current language.

Derived from

No base class

See also

I18n overview

Include files

<wx/intl.h>

Members

wxLocale::wxLocale
wxLocale::~wxLocale
wxLocale::AddCatalog
wxLocale::AddCatalogLookupPathPrefix
wxLocale::GetLocale
wxLocale::GetName
wxLocale::GetString
wxLocale::Init
wxLocale::IsLoaded
wxLocale::IsOk

### wxLocale::wxLocale

wxLocale()

This is the default constructor and it does nothing to initialize the object: Init() must be used to do that.

wxLocale(const char *szName, const char *szShort = NULL, const char *szLocale = NULL, bool bLoadDefault = TRUE, bool bConvertEncoding = FALSE)

The parameters have the following meaning:

- szName is the name of the locale and is only used in diagnostic messages
- szShort is the standard 2 letter locale abbreviation and is used as the directory prefix when looking for the message catalog files
- szLocale is the parameter for the call to setlocale()
- bLoadDefault may be set to FALSE to prevent loading of the message catalog for the given locale containing the translations of standard wxWindows messages. This parameter would be rarely used in normal circumstances.
- bConvertEncoding may be set to TRUE to do automatic conversion of message catalogs to platform's native encoding. Note that it will do only basic conversion between well-known pair like iso8859-1 and windows-1252 or iso8859-2 and windows-1250. See Writing non-English applications for detailed description of this behaviour.

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 wxLocale object becomes the new current global locale for the application and so all subsequent calls to wxGetTranslation() will try to translate the messages using the message catalogs for this locale. Finally, unless bLoadDefault parameter is FALSE, the method also loads the wxstd.mo catalog (which is looked for in all the usual places and, additionally, under the location specified bythe environment variable WXDIR if it is set) which will allow to translate all the messages generated by the library itself.

### wxLocale::~wxLocale

~wxLocale()

The destructor, like the constructor, also has global side effects: the previously set locale is restored and so the changes described in Init documentation are rolled back.

### wxLocale::AddCatalog

bool AddCatalog(const char *szDomain)

Add a catalog for use with the current locale: it is searched for in standard places (current directory first, then the system one), but you may also prepend additional directories to the search path with AddCatalogLookupPathPrefix().

All loaded catalogs will be used for message lookup by GetString() for the current locale.

Returns TRUE if catalog was successfully loaded, FALSE otherwise (which might mean that the catalog is not found or that it isn't in the correct format).

### wxLocale::AddCatalogLookupPathPrefix

void AddCatalogLookupPathPrefix(const wxString& prefix)

Add a prefix to the catalog lookup path: the message catalog files will be looked up under prefix/<lang>/LC_MESSAGES, prefix/LC_MESSAGES and prefix (in this order).

This only applies to subsequent invocations of AddCatalog()!

### wxLocale::GetLocale

const char* GetLocale() const

Returns the locale name as passed to the constructor or Init().

### wxLocale::GetName

const wxString& GetName() const

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

### wxLocale::GetString

const char* GetString(const char *szOrigString, const char *szDomain = NULL) const

Retrieves the translation for a string in all loaded domains unless the szDomain parameter is specified (and then only this catalog/domain is searched).

Returns original string if translation is not available (in this case an error message is generated the first time a string is not found; use wxLogNull to suppress it).

Remarks

Domains are searched in the last to first order, i.e. catalogs added later override those added before.

### wxLocale::Init

bool Init(const char *szName, const char *szShort = NULL, const char *szLocale = NULL, bool bLoadDefault = TRUE)

The parameters have the following meaning:

- szName is the name of the locale and is only used in diagnostic messages
- szShort is the standard 2 letter locale abbreviation and is used as the directory prefix when looking for the message catalog files
- szLocale is the parameter for the call to setlocale()
- bLoadDefault may be set to FALSE to prevent loading of the message catalog for the given locale containing the translations of standard wxWindows messages. This parameter would be rarely used in normal circumstances.

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 wxLocale object becomes the new current global locale for the application and so all subsequent calls to wxGetTranslation() will try to translate the messages using the message catalogs for this locale.

Returns TRUE on success or FALSE if the given locale couldn't be set.

### wxLocale::IsLoaded

bool IsLoaded(const char* domain) const

Check if the given catalog is loaded, and returns TRUE if it is.

According to GNU gettext tradition, each catalog normally corresponds to 'domain' which is more or less the application name.

See also: AddCatalog

### wxLocale::IsOk

bool IsOk() const

Returns TRUE if the locale could be set successfully.