From: Jonathan Nieder Date: Thu, 10 Mar 2011 03:17:58 +0000 (-0600) Subject: i18n: add stub Q_() wrapper for ngettext X-Git-Tag: v1.7.5-rc0~54^2~2 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=0c9ea33b90f6ed73b9c9151c2cad9ce341d6778b;p=git.git 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 Signed-off-by: Junio C Hamano --- diff --git a/gettext.h b/gettext.h index 04b5958e2..1b253b7e7 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)