wxS is a macro which can be used with character and string literals (in other words, 'x' or "foo") to convert them either to wide characters or wide strings in wchar_t-based (UTF-16) builds, or to keep them unchanged in char-based (UTF-8) builds. More...

This macro is exactly the same as wxT() and is defined in wxWidgets simply because it may be more intuitive for Windows programmers as the standard Win32 headers also define it (as well as yet another name for the same macro which is _TEXT()). More...

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

Macro Definition Documentation

#define _T

(

string

)

This macro is exactly the same as wxT() and is defined in wxWidgets simply because it may be more intuitive for Windows programmers as the standard Win32 headers also define it (as well as yet another name for the same macro which is _TEXT()).

Note that since wxWidgets 2.9.0 the use of _T() is discouraged just like for wxT() and also that this macro may conflict with identifiers defined in standard headers of some compilers (such as Sun CC) so its use should really be avoided.

wxS is a macro which can be used with character and string literals (in other words, 'x' or "foo") to convert them either to wide characters or wide strings in wchar_t-based (UTF-16) builds, or to keep them unchanged in char-based (UTF-8) builds.

Basically this macro produces characters or strings of type wxStringCharType.

The use of this macro is optional as the translation will always be done at run-time even if there is a mismatch between the kind of the literal used and the string or character type used in the current build. However using it can be beneficial in performance-sensitive code to do the conversion at compile-time instead.

This macro can be used in code which needs to compile with both wxWidgets 2 and 3 versions, in places where the wx2 API requires a Unicode string (in Unicode build) but the wx3 API only accepts a standard narrow string, as in e.g. wxCmdLineEntryDesc structure objects initializers.

Example of use:

1 const wxCmdLineEntryDesc cmdLineDesc[] =

2 {

3 { wxCMD_LINE_SWITCH, wxT_2("q"), wxT_2("quiet"),

4 wxT_2("Don't output verbose messages") },

5 wxCMD_LINE_DESC_END

6 };

Without wxT_2 the code above wouldn't compile with wxWidgets 2, but using wxT instead, it wouldn't compile with wxWidgets 3.

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:

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:

1 static const char * const elements[] = { wxTRANSLATE("Hydrogen"),

2 wxTRANSLATE("Helium"), ... };

3 ...

4 // use wxGetTranslation(elements[n])

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.

The wxUSE_UNICODE_WCHAR symbol is defined to 1 when building on Windows while it's defined to 0 when building on Unix, Linux or OS X. (Note that wxUSE_UNICODE_UTF8 symbol is defined as the opposite of wxUSE_UNICODE_WCHAR.)

Note that wxStringCharType (as the name says) is the type used by wxString for internal storage of the characters.

Function Documentation

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 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 to have 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.

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.

Concatenate all lines of the given wxArrayString object using the separator sep and returns the result as a wxString.

If the escape character is non-NULL, then it's used as prefix for each occurrence of sep in the strings contained in arr before joining them which is necessary in order to be able to recover the original array contents from the string later using wxSplit().

If the escape character is non-NULL, then the occurrences of sep immediately prefixed with escape are not considered as separators. Note that empty tokens will be generated if there are two or more adjacent separators.