From: Jonathan Nieder <jrnieder@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org, "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Subject: [PATCH v2] i18n: add stub Q_() wrapper for ngettext
Date: Wed, 9 Mar 2011 21:17:58 -0600 [thread overview]
Message-ID: <20110310031734.GA24781@elie> (raw)
In-Reply-To: <7v7hc89fp7.fsf@alter.siamese.dyndns.org>
From: Junio C Hamano <gitster@pobox.com>
Date: Sun, 6 Mar 2011 14:40:05 -0800
Subject: i18n: add stub Q_() wrapper for ngettext
The Q_ function translates a string representing some pharse with an
alternative plural form and uses the 'count' argument to choose which
form to return. Use of Q_ solves the "%d noun(s)" problem in a way
that is portable to languages outside the Germanic and Romance
families.
In English, the semantics of Q_(sing, plur, count) are roughly
equivalent to
count == 1 ? _(sing) : _(plur)
while in other languages there can be more variants (count == 0; more
random-looking rules based on the historical pronunciation of the
number). Behind the scenes, the singular form is used to look up a
family of translations and the plural form is ignored unless no
translation is available.
Define such a Q_ in gettext.h with the English semantics so C code can
start using it to mark phrases with a count for translation.
The name "Q_" is taken from subversion and stands for "quantity".
Many projects just use ngettext directly without a wrapper analogous
to _; we should not do so because git's gettext.h is meant not to
conflict with system headers that might include libintl.h.
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
Junio C Hamano wrote:
> Yeah, I am aware of that. Is there a similar convention for [dn]gettext?
> Perhaps not....
subversion uses Q_. Though it does not seem to be standard --- e.g.,
glib uses:
_() for gettext
Q_() for a variant on gettext that allows a string of the form
"context|message" as its argument;
C_() for a nicer version of Q_() that takes the context and message
as distinct arguments;
N_() to mark a string for translation without translating it;
NC_() to mark a string with context for translation without
translating it.
I suppose Q_ is as good a name as any.
Hopefully veterans from glib would not be used to glib's alternative
meaning of Q_, preferring to use C_ for messages with flags.
gettext.h | 12 ++++++++++--
1 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/gettext.h b/gettext.h
index 04b5958..1b253b7 100644
--- a/gettext.h
+++ b/gettext.h
@@ -9,8 +9,8 @@
#ifndef GETTEXT_H
#define GETTEXT_H
-#ifdef _
-#error "namespace conflict: '_' is pre-defined?"
+#if defined(_) || defined(Q_)
+#error "namespace conflict: '_' or 'Q_' is pre-defined?"
#endif
#define FORMAT_PRESERVING(n) __attribute__((format_arg(n)))
@@ -26,6 +26,14 @@ static inline FORMAT_PRESERVING(1) const char *_(const char *msgid)
return use_gettext_poison() ? "# GETTEXT POISON #" : msgid;
}
+static inline FORMAT_PRESERVING(1) FORMAT_PRESERVING(2)
+const char *Q_(const char *msgid, const char *plu, unsigned long n)
+{
+ if (use_gettext_poison())
+ return "# GETTEXT POISON #";
+ return n == 1 ? msgid : plu;
+}
+
/* Mark msgid for translation but do not translate it. */
#define N_(msgid) (msgid)
--
1.7.4.1
next prev parent reply other threads:[~2011-03-10 3:18 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-03-04 13:40 [BUG] git-am silently applying patches incorrectly Colin Guthrie
2011-03-04 16:17 ` Drew Northup
2011-03-04 16:41 ` Colin Guthrie
2011-03-04 17:27 ` Junio C Hamano
2011-03-04 17:49 ` Junio C Hamano
2011-03-04 18:37 ` Junio C Hamano
2011-03-04 19:05 ` Junio C Hamano
2011-03-04 19:18 ` Linus Torvalds
2011-03-04 19:31 ` Junio C Hamano
2011-03-04 20:14 ` Alexander Miseler
2011-03-04 21:33 ` Junio C Hamano
2011-03-04 22:20 ` Colin Guthrie
2011-03-04 22:34 ` Junio C Hamano
2011-03-04 22:42 ` Junio C Hamano
2011-03-05 11:51 ` Colin Guthrie
2011-03-06 22:15 ` Junio C Hamano
2011-03-06 22:40 ` Junio C Hamano
2011-03-06 22:56 ` Jonathan Nieder
[not found] ` <AANLkTikctSrfqKCdeYUyvUmAZjr=i7kaFhPeB-LfwgUz@mail.gmail.com>
2011-03-09 10:31 ` [RFC/PATCH 0/2] i18n: add ngettext stub Jonathan Nieder
2011-03-09 10:46 ` [PATCH 1/2] i18n: add stub ngettext implementation Jonathan Nieder
2011-03-09 10:52 ` [PATCH 2/2] i18n: avoid conflict with ngettext from libintl Jonathan Nieder
2011-03-09 20:43 ` Junio C Hamano
2011-03-09 20:51 ` Jonathan Nieder
2011-03-09 20:55 ` Junio C Hamano
2011-03-10 3:17 ` Jonathan Nieder [this message]
2011-03-10 7:59 ` [PATCH v2] i18n: add stub Q_() wrapper for ngettext Junio C Hamano
2011-03-10 9:24 ` Ævar Arnfjörð Bjarmason
2011-03-10 9:21 ` [PATCH 2/2] i18n: avoid conflict with ngettext from libintl Ævar Arnfjörð Bjarmason
2011-03-06 22:15 ` [BUG] git-am silently applying patches incorrectly Junio C Hamano
2011-03-07 9:37 ` Colin Guthrie
2011-03-04 23:09 ` Alexander Miseler
2011-03-05 0:05 ` Junio C Hamano
2011-03-04 22:58 ` Junio C Hamano
2011-03-04 21:49 ` Drew Northup
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20110310031734.GA24781@elie \
--to=jrnieder@gmail.com \
--cc=avarab@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.