Synopsis#include <glib.h> #include <glib/gi18n.h> #define Q_ (String) #define C_ (Context,String) #define N_ (String) #define NC_ (Context, String) const gchar* g_dgettext (const gchar *domain, const gchar *msgid); const gchar* g_dngettext (const gchar *domain, const gchar *msgid, const gchar *msgid_plural, gulong n); const gchar* g_dpgettext (const gchar *domain, const gchar *msgctxtid, gsize msgidoffset); const gchar* g_dpgettext2 (const gchar *domain, const gchar *context, const gchar *msgid); const gchar* g_strip_context (const gchar *msgid, const gchar *msgval); const gchar* const * g_get_language_names (void); Description
GLib doesn't force any particular localization method upon its users.
But since GLib itself is localized using the
In order to use these macros in an application, you must include
#define GETTEXT_PACKAGE "gtk20" #include <glib/gi18n-lib.h> The gettext manual covers details of how to set up message extraction with xgettext. DetailsQ_()#define Q_(String)
Like One use case given in the gettext manual is GUI translation, where one could e.g. disambiguate two "Open" menu entries as "File|Open" and "Printer|Open". Another use case is the string "Russian" which may have to be translated differently depending on whether it's the name of a character set or a language. This could be solved by using "charset|Russian" and "language|Russian".
See the Note
If you are using the
Since 2.4 C_()#define C_(Context,String)
Uses gettext to get the translation for label1 = C_("Navigation", "Back"); label2 = C_("Body part", "Back");
Note
If you are using the
Since 2.16 N_()#define N_(String)
Only marks a string for translation.
This is useful in situations where the translated strings can't
be directly used, e.g. in string array initializers.
To get the translated string, call { static const char *messages[] = { N_("some very meaningful message"), N_("and another one") }; const char *string; ... string = index > 1 ? _("a default message") : gettext (messages[index]); fputs (string); ... }
Since 2.4 NC_()#define NC_(Context, String)
Only marks a string for translation, with context.
This is useful in situations where the translated strings can't
be directly used, e.g. in string array initializers.
To get the translated string, you should call { static const char *messages[] = { NC_("some context", "some very meaningful message"), NC_("some context", "and another one") }; const char *string; ... string = index > 1 ? g_dpgettext2 (NULL, "some context", "a default message") : g_dpgettext2 (NULL, "some context", messages[index]); fputs (string); ... } Note
If you are using the
Since 2.18 g_dgettext ()const gchar* g_dgettext (const gchar *domain, const gchar *msgid);
This function is a wrapper of
The advantage of using this function over This function disables translations if and only if upon its first call all the following conditions hold:
Note that this behavior may not be desired for example if an application
has its untranslated messages in a language other than English. In those
cases the application should call
Applications should normally not use this function directly,
but use the
Since 2.18 g_dngettext ()const gchar* g_dngettext (const gchar *domain, const gchar *msgid, const gchar *msgid_plural, gulong n);
This function is a wrapper of
See
Since 2.18 g_dpgettext ()const gchar* g_dpgettext (const gchar *domain, const gchar *msgctxtid, gsize msgidoffset);
This function is a variant of
This uses
Applications should normally not use this function directly,
but use the
Since 2.16 g_dpgettext2 ()const gchar* g_dpgettext2 (const gchar *domain, const gchar *context, const gchar *msgid);
This function is a variant of
This uses
This function differs from
Since 2.18 g_strip_context ()const gchar* g_strip_context (const gchar *msgid, const gchar *msgval);
An auxiliary function for
Since 2.4 g_get_language_names ()const gchar* const * g_get_language_names (void); Computes a list of applicable locale names, which can be used to e.g. construct locale-dependent filenames or search paths. The returned list is sorted from most desirable to least desirable and always contains the default locale "C". For example, if LANGUAGE=de:en_US, then the returned list is "de", "en_US", "en", "C".
This function consults the environment variables
Since 2.6 |