After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: general
unspecified
Other All
: Normal enhancement
: ---
Assigned To: gtk-bugs
gtk-bugs
Depends on:
Blocks:
 
 
Reported: 2004-05-17 17:25 UTC by Morten Welinder
Modified: 2007-11-23 07:53 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
a patch (4.56 KB, patch)
2007-07-08 16:46 UTC, Matthias Clasen
committed Details | Review

Description Morten Welinder 2004-05-17 17:25:04 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.)
Comment 1 Matthias Clasen 2004-05-18 21:01:05 UTC
GTK+ uses the GLib definition of Q_() now, so I'm moving this bug there.
Comment 2 Morten Welinder 2004-05-18 21:09:47 UTC
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.
Comment 3 Matthias Clasen 2004-05-18 21:17:50 UTC
Thats why I kept the bug open. I guess should wait for problematic compilers to
show up.
Comment 4 Emil Mikulic 2006-02-01 05:55:57 UTC
A problematic compiler: Sun C 5.8 on Solaris 10 (sun4u)
Adding -xstrconst to CFLAGS fixes the problem.
Comment 5 Emil Mikulic 2006-02-01 06:00:06 UTC
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.
Comment 6 Matthias Clasen 2006-02-01 19:03:36 UTC
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")

Comment 7 Matthias Clasen 2007-05-30 16:11:04 UTC
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.
Comment 8 Matthias Clasen 2007-07-08 16:46:40 UTC
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
Comment 9 Matthias Clasen 2007-11-23 07:53:26 UTC
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().