diff --git a/glib/glibintl.h b/glib/glibintl.h index 6d79a268e..3164a0a89 100644 --- a/glib/glibintl.h +++ b/glib/glibintl.h @@ -5,7 +5,9 @@ #error "config.h must be included prior to glibintl.h" #endif -G_CONST_RETURN gchar *glib_gettext (const gchar *str) G_GNUC_FORMAT(1); +G_CONST_RETURN gchar *glib_gettext (const gchar *str) G_GNUC_FORMAT(1); +G_CONST_RETURN gchar *glib_pgettext (const gchar *msgctxtid, + gsize msgidoffset) G_GNUC_FORMAT(1); #ifdef ENABLE_NLS @@ -13,7 +15,7 @@ G_CONST_RETURN gchar *glib_gettext (const gchar *str) G_GNUC_FORMAT(1); #define _(String) glib_gettext(String) /* Split out this in the code, but keep it in the same domain for now */ #define P_(String) glib_gettext(String) -#define C_(Context,String) g_dpgettext (NULL, Context "\004" String, strlen (Context) + 1) +#define C_(Context,String) glib_pgettext (Context "\004" String, strlen (Context) + 1) #ifdef gettext_noop #define N_(String) gettext_noop(String) diff --git a/glib/gutils.c b/glib/gutils.c index 5bea93fc3..6d9dbe961 100644 --- a/glib/gutils.c +++ b/glib/gutils.c @@ -3611,18 +3611,8 @@ _glib_get_locale_dir (void) #endif /* G_OS_WIN32 */ -/** - * glib_gettext: - * @str: The string to be translated - * - * Returns the translated string from the glib translations. - * This is an internal function and should only be used by - * the internals of glib (such as libgio). - * - * Returns: the transation of @str to the current locale - */ -G_CONST_RETURN gchar * -glib_gettext (const gchar *str) +static void +ensure_gettext_initialized(void) { static gboolean _glib_gettext_initialized = FALSE; @@ -3640,10 +3630,50 @@ glib_gettext (const gchar *str) # endif _glib_gettext_initialized = TRUE; } - +} + +/** + * glib_gettext: + * @str: The string to be translated + * + * Returns the translated string from the glib translations. + * This is an internal function and should only be used by + * the internals of glib (such as libgio). + * + * Returns: the transation of @str to the current locale + */ +G_CONST_RETURN gchar * +glib_gettext (const gchar *str) +{ + ensure_gettext_initialized(); + return g_dgettext (GETTEXT_PACKAGE, str); } +/** + * glib_pgettext: + * @msgctxtid: a combined message context and message id, separated + * by a \004 character + * @msgidoffset: the offset of the message id in @msgctxid + * + * This function is a variant of glib_gettext() which supports + * a disambiguating message context. See g_dpgettext() for full + * details. + * + * This is an internal function and should only be used by + * the internals of glib (such as libgio). + * + * Returns: the transation of @str to the current locale + */ +G_CONST_RETURN gchar * +glib_pgettext(const gchar *msgctxtid, + gsize msgidoffset) +{ + ensure_gettext_initialized(); + + return g_dpgettext (GETTEXT_PACKAGE, msgctxtid, msgidoffset); +} + #if defined (G_OS_WIN32) && !defined (_WIN64) /* Binary compatibility versions. Not for newly compiled code. */