GNOME Bugzilla – Bug 142676
Q_
Last modified: 2007-11-23 07:53:26 UTC
The non-NLS Q_ is wrong. It needs to be something like... #define Q_(String) g_strip_context_NO_NLS ((String)) where g_strip_context_NO_NLS does the obvious context stripping. (Note: g_strip_context compares pointers so we cannot simply duplicate String in the macro as the compiler might allocate two different strings.)
GTK+ uses the GLib definition of Q_() now, so I'm moving this bug there.
As Owen mentioned, even the normal definition of Q_ will not work unless the compiler guarantees that the two string instances evaluate to the same pointer value. In other words, Q_ needs to be a function.
Thats why I kept the bug open. I guess should wait for problematic compilers to show up.
A problematic compiler: Sun C 5.8 on Solaris 10 (sun4u) Adding -xstrconst to CFLAGS fixes the problem.
Sorry, I should mention that the problem I was seeing was that every keyboard accelerator label in the menus started with the string "keyboard label|". As far as I can tell, I wasn't using NLS in any way. The LANG and LC_ALL env vars were unset. I was seeing this problem in (at least) a locally compiled GIMP 2.2.10, and the binary package of Adobe Acrobat Reader 7.0.1 for Solaris/SPARC. Rebuilding GTK+ with -xstrconst made the prefixes go away.
I think the longterm fix here will be to move to a 2 argument version for specifying the prefix, since this has upstream support in GNU gettext now. Something like Q2_("prefix", "msgid") instead of Q_("prefix|msgid")
For the record, the definitions for this would be #define Q2_(ctx,id) pgettext (ctx, id) #define Q2_(ctx, id) dpgettext (GETTEXT_PACKAGE, ctx, id) And apps using this would have to add --keyword=Q2_:1c,2 to their xgettext invokation. I haven't found a good way to make this work transparently with older gettext. While #define Q2_(ctx,id) Q_(ctx "|" id) works as far as the compiler is concerned, I have not found a way to make xgettext extract this as msgid "ctx|id" My current proposal would be to just document that Q2_ is only supported if your gettext is new enough, >= 0.15. I'm not comfortable with requiring gettext 0.15 yet.
Created attachment 91438 [details] [review] a patch Here is a patch which adds a C_(context,msgid) macro. It also contains changes that will allow Q_() to continue working after everything has been converted to msgctxt
2007-11-23 Matthias Clasen <mclasen@redhat.com> * glib/gi18n-lib.h: * glib/gi18n.h: Define a two-argument macro C_() for marking translatable strings with context and implement C_() and Q_() using g_dpgettext(). (#142676, Morten Welinder) * glib/glib.symbols: * glib/gstrfuncs.[hc]: Implement g_dpgettext().