From d0d19f0dbaf45f8d999902dbf962adf08511c184 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Mon, 10 Dec 2007 05:24:36 +0000 Subject: [PATCH] Change prototype to take msgctxtid + offset instead of two strings, to 2007-12-10 Matthias Clasen * glib/gstrfuncs.h: * glib/gstrfuncs.c (g_dpgettext): Change prototype to take msgctxtid + offset instead of two strings, to avoid duplication of string constants if the compiler/linker don't perform constant suffix merging. (#502590, Christian Persch) * glib/gi18n.h: * glib/gi18n-lib.h: Adapt the definitions of C_() and Q_(). svn path=/trunk/; revision=6081 --- ChangeLog | 11 +++++++++++ glib/gi18n-lib.h | 4 ++-- glib/gi18n.h | 4 ++-- glib/gstrfuncs.c | 21 +++++++++++---------- glib/gstrfuncs.h | 2 +- 5 files changed, 27 insertions(+), 15 deletions(-) diff --git a/ChangeLog b/ChangeLog index c4cfff0..e97ff2e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2007-12-10 Matthias Clasen + + * glib/gstrfuncs.h: + * glib/gstrfuncs.c (g_dpgettext): Change prototype to take + msgctxtid + offset instead of two strings, to avoid duplication + of string constants if the compiler/linker don't perform constant + suffix merging. (#502590, Christian Persch) + + * glib/gi18n.h: + * glib/gi18n-lib.h: Adapt the definitions of C_() and Q_(). + 2007-12-09 Hans Breuer * tests/gio-ls.c : (new file) a test program emulating some of 'ls' diff --git a/glib/gi18n-lib.h b/glib/gi18n-lib.h index e5d1cd9..9ba1f51 100644 --- a/glib/gi18n-lib.h +++ b/glib/gi18n-lib.h @@ -28,9 +28,9 @@ #endif #define _(String) dgettext (GETTEXT_PACKAGE, String) -#define Q_(String) g_dpgettext (GETTEXT_PACKAGE, String, NULL) +#define Q_(String) g_dpgettext (GETTEXT_PACKAGE, String, 0) #define N_(String) (String) -#define C_(Context,String) g_dpgettext (GETTEXT_PACKAGE, Context "\004" String, String) +#define C_(Context,String) g_dpgettext (GETTEXT_PACKAGE, Context "\004" String, strlen (Context) + 1) #endif /* __G_I18N_LIB_H__ */ diff --git a/glib/gi18n.h b/glib/gi18n.h index b208db0..a5c829b 100644 --- a/glib/gi18n.h +++ b/glib/gi18n.h @@ -23,9 +23,9 @@ #include #define _(String) gettext (String) -#define Q_(String) g_dpgettext (NULL, String, NULL) +#define Q_(String) g_dpgettext (NULL, String, 0) #define N_(String) (String) -#define C_(Context,String) g_dpgettext (NULL, Context "\004" String, String) +#define C_(Context,String) g_dpgettext (NULL, Context "\004" String, strlen (Context) + 1) #endif /* __G_I18N_H__ */ diff --git a/glib/gstrfuncs.c b/glib/gstrfuncs.c index badac77..6d60381 100644 --- a/glib/gstrfuncs.c +++ b/glib/gstrfuncs.c @@ -2849,19 +2849,20 @@ g_strv_length (gchar **str_array) * g_dpgettext: * @domain: the translation domain to use, or %NULL to use * the domain set with textdomain() - * @msgctxtid: a combined message context and message id - * @msgid: the message id, or %NULL + * @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 dgettext() which supports * a disambiguating message context. GNU gettext uses the * '\004' character to separate the message context and - * message id in @msgctxtid. If %NULL is passed as @msgid, - * this function also supports the older convention of using - * '|' as a separator. + * message id in @msgctxtid. + * If 0 is passed as @msgidoffset, this function will fall back to + * trying to use the deprecated convention of using "|" as a separation + * character. * * Applications should normally not use this function directly, - * but use the C_() or Q_() macros for translations with - * context. + * but use the C_() macro for translations with context. * * Returns: The translated string * @@ -2870,7 +2871,7 @@ g_strv_length (gchar **str_array) const gchar * g_dpgettext (const gchar *domain, const gchar *msgctxtid, - const gchar *msgid) + gsize msgidoffset) { const gchar *translation; gchar *sep; @@ -2879,8 +2880,8 @@ g_dpgettext (const gchar *domain, if (translation == msgctxtid) { - if (msgid) - return msgid; + if (msgidoffset > 0) + return msgctxtid + msgidoffset; sep = strchr (msgctxtid, '|'); diff --git a/glib/gstrfuncs.h b/glib/gstrfuncs.h index aac58f3..bf35326 100644 --- a/glib/gstrfuncs.h +++ b/glib/gstrfuncs.h @@ -245,7 +245,7 @@ G_CONST_RETURN gchar *g_strip_context (const gchar *msgid, G_CONST_RETURN gchar *g_dpgettext (const gchar *domain, const gchar *msgctxtid, - const gchar *msgid); + gsize msgidoffset); G_END_DECLS -- 2.7.4