Thread (3 messages) flat view 3 messages, 1 author, 2016-06-15
DORMANTno replies

[PATCH 1/2] i18n: add stub ngettext implementation

From: Jonathan Nieder <hidden>
Date: 2016-06-15 22:50:44
Subsystem: the rest · Maintainer: Linus Torvalds

From: Junio C Hamano <redacted>
Date: Sun, 6 Mar 2011 14:40:05 -0800

The ngettext 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 ngettext 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 ngettext(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.

Add a simple wrapper with the English semantics so C code can start
using it to mark phrases with a count for translation.

Signed-off-by: Jonathan Nieder <redacted>
---
This is based against a version of gettext.h with the fixup
(s/# GETTEXT POISON #/ GETTEXT POISON /) from
http://thread.gmane.org/gmane.comp.version-control.git/167661/focus=167878
Applying that substitution to the patch should be enough for it to
apply to a gettext.h without that change.

 gettext.h |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)
diff --git a/gettext.h b/gettext.h
index 73831aa..03fb340 100644
--- a/gettext.h
+++ b/gettext.h
@@ -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 *ngettext(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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help