From 8708845f75bbba3013423e5f3ebf872115295c3e Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Tue, 6 May 2008 23:18:55 +0000 Subject: [PATCH] Explain why the number argument must be the last. --- gettext-tools/doc/ChangeLog | 6 ++++++ gettext-tools/doc/gettext.texi | 27 +++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/gettext-tools/doc/ChangeLog b/gettext-tools/doc/ChangeLog index 36f6fe830..5b11039d4 100644 --- a/gettext-tools/doc/ChangeLog +++ b/gettext-tools/doc/ChangeLog @@ -1,3 +1,9 @@ +2008-05-06 Bruno Haible + + * gettext.texi (Plural forms): Explain why the number argument must be + the last. + Reported by Benjamin Geer . + 2008-04-25 Bruno Haible * ISO_639: Remove Adangme. Update Belarusian, Scottish Gaelic, diff --git a/gettext-tools/doc/gettext.texi b/gettext-tools/doc/gettext.texi index d7dcce661..f584b42df 100644 --- a/gettext-tools/doc/gettext.texi +++ b/gettext-tools/doc/gettext.texi @@ -6025,6 +6025,33 @@ printf (ngettext ("One file removed", "%d files removed", n), n); This works because the @samp{printf} function discards excess arguments that are not consumed by the format string. +If this function is meant to yield a format string that takes two or more +arguments, you can not use it like this: + +@smallexample +printf (ngettext ("%d file removed from directory %s", + "%d files removed from directory %s", + n, dir), + n); +@end smallexample + +@noindent +because in many languages the translators want to replace the @samp{%d} +with an explicit word in the singular case, just like ``one'' in English, +and C format strings cannot consume the second argument but skip the first +argument. Instead, you have to reorder the arguments so that @samp{n} +comes last: + +@smallexample +printf (ngettext ("%$2d file removed from directory %$1s", + "%$2d files removed from directory %$1s", + dir, n), + n); +@end smallexample + +@noindent +See @ref{c-format} for details about this argument reordering syntax. + It is also possible to use this function when the strings don't contain a cardinal number: -- 2.47.2