# wxTranslations Class Reference

`#include <wx/translation.h>`

## Detailed Description

This class allows to get translations for strings.

In wxWidgets this class manages message catalogs which contain the translations of the strings used to the current language. Unlike wxLocale, it isn't bound to locale. It can be used either independently of, or in conjunction with wxLocale. In the latter case, you should initialize wxLocale (which creates wxTranslations instance) first; in the former, you need to create a wxTranslations object and Set() it manually.

Only one wxTranslations instance is active at a time; it is set with the Set() method and obtained using Get().

Unlike wxLocale, wxTranslations' primary mean of identifying language is by its "canonical name", i.e. ISO 639 code, possibly combined with ISO 3166 country code and additional modifiers (examples include "fr", "en_GB" or "ca@valencia"; see wxLocale::GetCanonicalName() for more information). This allows apps using wxTranslations API to use even languages not recognized by the operating system or not listed in wxLanguage enum.

Since:
  2.9.1

See also:
  wxLocale

## Public Member Functions
| wxTranslations ()
| Constructor.
void | SetLoader (wxTranslationsLoader *loader)
| Changes loader use to read catalogs to a non-default one.
void | SetLanguage (wxLanguage lang)
| Sets translations language to use.
void | SetLanguage (const wxString &lang)
| Sets translations language to use.
wxArrayString | GetAvailableTranslations (const wxString &domain) const
| Returns list of all translations of domain that were found.
bool | AddStdCatalog ()
| Add standard wxWidgets catalogs ("wxstd" and possible port-specific catalogs).
bool | AddCatalog (const wxString &domain)
| Add a catalog for use with the current locale.
bool | AddCatalog (const wxString &domain, wxLanguage msgIdLanguage)
| Same as AddCatalog(const wxString&), but takes an additional argument, msgIdLanguage.
bool | AddCatalog (const wxString &domain, wxLanguage msgIdLanguage, const wxString &msgIdCharset)
| Same as AddCatalog(const wxString&, wxLanguage), but takes two additional arguments, msgIdLanguage and msgIdCharset.
bool | IsLoaded (const wxString &domain) const
| Check if the given catalog is loaded, and returns true if it is.
const wxString & | GetString (const wxString &origString, const wxString &domain=wxEmptyString) const
| Retrieves the translation for a string in all loaded domains unless the domain parameter is specified (and then only this catalog/domain is searched).
const wxString & | GetString (const wxString &origString, const wxString &origString2, unsigned n, const wxString &domain=wxEmptyString) const
| Retrieves the translation for a string in all loaded domains unless the domain parameter is specified (and then only this catalog/domain is searched).
wxString | GetHeaderValue (const wxString &header, const wxString &domain=wxEmptyString) const
| Returns the header value for header header.
## Static Public Member Functions
static wxTranslations * | Get ()
| Returns current translations object, may return NULL.
static void | Set (wxTranslations *t)
| Sets current translations object.

List of all members.

## Constructor & Destructor Documentation

wxTranslations::wxTranslations | ( |  | ) |

Constructor.

## Member Function Documentation

bool wxTranslations::AddCatalog | ( | const wxString & | domain,
|  | wxLanguage | msgIdLanguage,
|  | const wxString & | msgIdCharset |
| ) |  |  |

Same as AddCatalog(const wxString&, wxLanguage), but takes two additional arguments, msgIdLanguage and msgIdCharset.

This overload is only available in non-Unicode build.

Parameters:

  | domain | The catalog domain to add.
  | msgIdLanguage | Specifies the language of "msgid" strings in source code (i.e. arguments to GetString(), wxGetTranslation() and the _() macro). It is used if AddCatalog() cannot find any catalog for current language: if the language is same as source code language, then strings from source code are used instead.
  | msgIdCharset | Lets you specify the charset used for msgids in sources in case they use 8-bit characters (e.g. German or French strings).

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

bool wxTranslations::AddCatalog | ( | const wxString & | domain,
|  | wxLanguage | msgIdLanguage |
| ) |  |  |

Same as AddCatalog(const wxString&), but takes an additional argument, msgIdLanguage.

Parameters:

  | domain | The catalog domain to add.
  | msgIdLanguage | Specifies the language of "msgid" strings in source code (i.e. arguments to GetString(), wxGetTranslation() and the _() macro). It is used if AddCatalog() cannot find any catalog for current language: if the language is same as source code language, then strings from source code are used instead.

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

bool wxTranslations::AddCatalog | ( | const wxString & | domain | ) |

Add a catalog for use with the current locale.

By default, it is searched for in standard places (see wxFileTranslationsLoader), but you may also prepend additional directories to the search path with wxFileTranslationsLoader::AddCatalogLookupPathPrefix().

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

In this overload, `msgid` strings are assumed to be in English and written only using 7-bit ASCII characters. If you have to deal with non-English strings or 8-bit characters in the source code, see the instructions in Writing Non-English Applications.

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

bool wxTranslations::AddStdCatalog | ( |  | ) |

Add standard wxWidgets catalogs ("wxstd" and possible port-specific catalogs).

Returns:
  true if a suitable catalog was found, false otherwise

See also:
  AddCatalog()

static wxTranslations* wxTranslations::Get | ( |  | ) | `[static]`

Returns current translations object, may return NULL.

You must either call this early in app initialization code, or let wxLocale do it for you.

wxArrayString wxTranslations::GetAvailableTranslations | ( | const wxString & | domain | ) | const

Returns list of all translations of domain that were found.

This method can be used e.g. to populate list of application's translations offered to the user. To do this, pass the app's main catalog as domain.

wxString wxTranslations::GetHeaderValue | ( | const wxString & | header,
|  | const wxString & | domain = `wxEmptyString` |
| ) |  |  | const

Returns the header value for header header.

The search for header is case sensitive. If an domain is passed, this domain is searched. Else all domains will be searched until a header has been found.

The return value is the value of the header if found. Else this will be empty.

const wxString& wxTranslations::GetString | ( | const wxString & | origString,
|  | const wxString & | origString2,
|  | unsigned | n,
|  | const wxString & | domain = `wxEmptyString` |
| ) |  |  | const

Retrieves the translation for a string in all loaded domains unless the domain 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).

This form is used when retrieving translation of string that has different singular and plural form in English or different plural forms in some other language. It takes two extra arguments: origString parameter must contain the singular form of the string to be converted.

It is also used as the key for the search in the catalog. The origString2 parameter is the plural form (in English).

The parameter n is used to determine the plural form. If no message catalog is found origString is returned if 'n == 1', otherwise origString2.

See GNU gettext manual for additional information on plural forms handling. This method is called by the wxGetTranslation() function and _() macro.

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

const wxString& wxTranslations::GetString | ( | const wxString & | origString,
|  | const wxString & | domain = `wxEmptyString` |
| ) |  |  | const

Retrieves the translation for a string in all loaded domains unless the domain 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.

bool wxTranslations::IsLoaded | ( | const wxString & | 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()

static void wxTranslations::Set | ( | wxTranslations * | t | ) | `[static]`

Sets current translations object.

Deletes previous translation object and takes ownership of t.

void wxTranslations::SetLanguage | ( | const wxString & | lang | ) |

Sets translations language to use.

Empty lang string has the same meaning as wxLANGUAGE_DEFAULT in SetLanguage(wxLanguage): best suitable translation, given user's preference and available translations, will be used.

void wxTranslations::SetLanguage | ( | wxLanguage | lang | ) |

Sets translations language to use.

wxLANGUAGE_DEFAULT has special meaning: best suitable translation, given user's preference and available translations, will be used.

void wxTranslations::SetLoader | ( | wxTranslationsLoader * | loader | ) |

Changes loader use to read catalogs to a non-default one.

Deletes previous loader and takes ownership of loader.

See also:
  wxTranslationsLoader, wxFileTranslationsLoader, wxResourceTranslationsLoader

|  | [ top ]