wxWidgets: interface/wx/translation.h File Reference

| Version: 3.1.5

Loading...
Searching...
No Matches
Classes | Macros | Functions
translation.h File Reference

## Classes
class | wxTranslations
| This class allows getting translations for strings. More...
class | wxTranslationsLoader
| Abstraction of translations discovery and loading. More...
class | wxFileTranslationsLoader
| Standard wxTranslationsLoader implementation. More...
class | wxResourceTranslationsLoader
| This loader makes it possible to load translations from Windows resources. More...
class | wxMsgCatalog
| Represents a loaded translations message catalog. More...

## Macros
#define | wxPLURAL(string, plural, n)
| This macro is identical to _() but for the plural variant of wxGetTranslation().
#define | wxGETTEXT_IN_CONTEXT(context, string)
| Similar to _() but translates the string in the given context.
#define | wxGETTEXT_IN_CONTEXT_PLURAL(context, string, plural, n)
| Similar to wxPLURAL() but translates the string in the given context.
#define | wxTRANSLATE(string)
| This macro doesn't do anything in the program code – it simply expands to the value of its argument.

## Functions
const wxString & | wxGetTranslation (const wxString &string, const wxString &domain=wxEmptyString, const wxString &context=wxEmptyString)
| This function returns the translation of string in the current `locale()`.
const wxString & | wxGetTranslation (const wxString &string, const wxString &plural, unsigned n, const wxString &domain=wxEmptyString, const wxString &context=wxEmptyString)
| This is an overloaded version of wxGetTranslation(const wxString&, const wxString&), please see its documentation for general information.
const wxString & | _ (const wxString &string)
| Macro to be used around all literal strings that should be translated.

## Macro Definition Documentation

## ◆ wxGETTEXT_IN_CONTEXT

#define wxGETTEXT_IN_CONTEXT | ( |  | context,
|  |  | string )

Similar to _() but translates the string in the given context.

See the description of `context` argument of wxGetTranslation().

See also
  wxGETTEXT_IN_CONTEXT_PLURAL()

Since
  3.1.1

## ◆ wxGETTEXT_IN_CONTEXT_PLURAL

#define wxGETTEXT_IN_CONTEXT_PLURAL | ( |  | context,
|  |  | string,
|  |  | plural,
|  |  | n )

Similar to wxPLURAL() but translates the string in the given context.

See the description of `context` argument of wxGetTranslation().

See also
  wxGETTEXT_IN_CONTEXT()

Since
  3.1.1

## ◆ wxPLURAL

#define wxPLURAL | ( |  | string,
|  |  | plural,
|  |  | n )

This macro is identical to _() but for the plural variant of wxGetTranslation().

Returns
  A const wxString.

Include file:

    #include <wx/intl.h>

## ◆ wxTRANSLATE

#define wxTRANSLATE | ( |  | string | ) |

This macro doesn't do anything in the program code – it simply expands to the value of its argument.

However it does have a purpose which is to mark the literal strings for the extraction into the message catalog created by `xgettext` program. Usually this is achieved using _() but that macro not only marks the string for extraction but also expands into a wxGetTranslation() call which means that it cannot be used in some situations, notably for static array initialization.

Here is an example which should make it more clear: suppose that you have a static array of strings containing the names of chemical elements, which have to be translated. If you write:

static const char * const elements[] = { _("Hydrogen"), _("Helium"), ... };
...
// use elements[n] as usual
_
const wxString & _(const wxString &string)
Macro to be used around all literal strings that should be translated.

The code would compile and run, but there would be no translations for the strings because static variables are initialized at a very early stage of program execution; that is, before the locale and paths to message catalog files have been set up. So instead you should do this:

static const char * const elements[] = { wxTRANSLATE("Hydrogen"),
wxTRANSLATE("Helium"), ... };
...
// use wxGetTranslation(elements[n])
wxTRANSLATE
#define wxTRANSLATE(string)
This macro doesn't do anything in the program code – it simply expands to the value of its argument.
Definition translation.h:522

Note that if you simply omit wxTRANSLATE() above, those strings would not be marked for translation, and would therefore not be included in the message catalog. Consequently, wxGetTranslation() would not find translations for them.

Returns
  A const wxChar*.

Include file:

    #include <wx/intl.h>

## Function Documentation

## ◆ _()

const wxString & _ | ( | const wxString & | string | ) |

Macro to be used around all literal strings that should be translated.

This macro expands into a call to wxGetTranslation(), so it marks the message for the extraction by `xgettext` just as wxTRANSLATE() does, but also returns the translation of the string for the current locale during execution.

This macro is thread-safe.

Include file:

    #include <wx/intl.h>

## ◆ wxGetTranslation() [1/2]

const wxString & wxGetTranslation | ( | const wxString & | string,
|  | const wxString & | domain = wxEmptyString,
|  | const wxString & | context = wxEmptyString )

This function returns the translation of string in the current `locale()`.

If the string is not found in any of the loaded message catalogs (see Internationalization), the original string is returned. If you enable logging of trace messages with "i18n" mask (using wxLog::AddTraceMask()) and debug logging is enabled (see Debugging), a message is also logged in this case – which helps to find the strings which were not yet translated.

If domain is specified then only that domain/catalog is searched for a matching string. As this function is used very often, an alternative (and also common in Unix world) syntax is provided: the _() macro is defined to do the same thing as wxGetTranslation().

If context is not empty (notice that this argument is only available starting from wxWidgets 3.1.1), item translation is looked up in the specified context. This allows having different translations for the same string appearing in different contexts, e.g. it may be necessary to translate the same English "Open" verb differently depending on the object it applies to. To do this, you need to use `msgctxt` in the source message catalog and specify different contexts for the different occurrences of the string and then use the same contexts in the calls to this function (or wxGETTEXT_IN_CONTEXT() or wxGETTEXT_IN_CONTEXT_PLURAL() macros).

This function is thread-safe.

Note
  This function is not suitable for literal strings using wxT() macro since this macro is not recognised by `xgettext`, and so such strings are not extracted to the message catalog. Instead, use the _() and wxPLURAL() macro for all literal strings.

See also
  wxGetTranslation(const wxString&, const wxString&, unsigned, const wxString&)

Include file:

    #include <wx/intl.h>

## ◆ wxGetTranslation() [2/2]

const wxString & wxGetTranslation | ( | const wxString & | string,
|  | const wxString & | plural,
|  | unsigned | n,
|  | const wxString & | domain = wxEmptyString,
|  | const wxString & | context = wxEmptyString )

This is an overloaded version of wxGetTranslation(const wxString&, const wxString&), please see its documentation for general information.

This version is used when retrieving translation of string that has different singular and plural forms in English or different plural forms in some other language. Like wxGetTranslation(const wxString&,const wxString&), the string parameter must contain the singular form of the string to be converted and is used as the key for the search in the catalog. The plural parameter is the plural form (in English). The parameter n is used to determine the plural form. If no message catalog is found, string is returned if "n == 1", otherwise plural is returned.

See GNU gettext Manual for additional information on plural forms handling: http://www.gnu.org/software/gettext/manual/gettext.html#Plural-forms For a shorter alternative see the wxPLURAL() macro.

This function is thread-safe.

Include file:

    #include <wx/intl.h>