Context in translations, Q_() and gettext

I just learned that GNU gettext will soon have official support for
disambiguating context in translations. 

This is great. However, Bruno decided to not implement the somewhat
ad-hoc solution which has been recommended for years in the gettext
manual, and implemented in glib using Q_(), which is to embed the
context as a prefix in the msgid, separated by |. Instead, gettext
will introduce new macros, 

pgettext (context, msgid)
npgettext (context, msgid, msgid_pural, n)

and the context will appear in .po files as

msgctxt "context"
msgid "msgid"
msgstr "..."

Translators can hope that tools will learn about this new syntax and
support disambiguating context better. 

Unfortunately, xgettext will only be able to create .po files with the
new syntax if the context and the msgid appear as two separate string
literals in the source. Which is not the case for Q_(). Therefore, I
think we should consider deprecating the single-argument Q_() macro
in favor of a Q2_() macro which takes context and msgid as separate
arguments. It should be easy to detect the presence of a sufficently
new gettext and implement Q2_() by falling back to the Q_()
implementation in the absence of pgettext():

#define Q2_(context,msgid) pgettext(context,msgid)
#define Q2_(context,msgid) Q_(context ## "|" ## msgid)

The name Q2_() is certainly not perfect. Well, at least one
can interpret the 2 as a subtle hint that the macro takes 2 arguments...

What do you think ?


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]