Skip to content

Commit 0c9ea33

Browse files
jrngitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3095522 commit 0c9ea33

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

gettext.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
#ifndef GETTEXT_H
1010
#define GETTEXT_H
1111

12-
#ifdef _
13-
#error "namespace conflict: '_' is pre-defined?"
12+
#if defined(_) || defined(Q_)
13+
#error "namespace conflict: '_' or 'Q_' is pre-defined?"
1414
#endif
1515

1616
#define FORMAT_PRESERVING(n) __attribute__((format_arg(n)))
@@ -26,6 +26,14 @@ static inline FORMAT_PRESERVING(1) const char *_(const char *msgid)
2626
return use_gettext_poison() ? "# GETTEXT POISON #" : msgid;
2727
}
2828

29+
static inline FORMAT_PRESERVING(1) FORMAT_PRESERVING(2)
30+
const char *Q_(const char *msgid, const char *plu, unsigned long n)
31+
{
32+
if (use_gettext_poison())
33+
return "# GETTEXT POISON #";
34+
return n == 1 ? msgid : plu;
35+
}
36+
2937
/* Mark msgid for translation but do not translate it. */
3038
#define N_(msgid) (msgid)
3139

0 commit comments

Comments
 (0)