]> granicus.if.org Git - neomutt/commitdiff
I18N: Use ngettext to choose correct plural form
authorReis Radomil <reisradomil@fake-box.com>
Sun, 22 Apr 2018 04:15:57 +0000 (04:15 +0000)
committerRichard Russon <rich@flatcap.org>
Tue, 24 Apr 2018 20:27:22 +0000 (21:27 +0100)
Avoid the antipattern

   printf(n == 1 ? _("one thing") : _("%d things"), n);

instead use

   printf(ngettext("one thing", "%d things", n), n);

(note: n has to be passed to ngettext and printf)

Although most Germanic languages (including English) use the singular
form for n=1 and a (single) plural form for all other n (including n=0),
this is not the case in general. An example from the GNU gettext manual
[0] for Polish work plik (file):

1 plik
2,3,4 pliki
5-21 pliko'w
22-24 pliki
25-31 pliko'w

When using numbers in translatable strings, do not choose the translated
plural form in the code. Instead let GNU gettext capability pick the
correct translated plural (provided by a translator) depending on the
number.

[0] https://www.gnu.org/software/gettext/manual/html_chapter/gettext.html#Plural-forms

mx.c

diff --git a/mx.c b/mx.c
index 79b0cf0c912590679fed47d6357f512d95118d3a..0b9c0375b79e0d980bbf40b51a1a7cbd3320721b 100644 (file)
--- a/mx.c
+++ b/mx.c
@@ -768,7 +768,7 @@ int mx_close_mailbox(struct Context *ctx, int *index_hint)
   if (ctx->deleted && !(ctx->magic == MUTT_MAILDIR && MaildirTrash))
   {
     snprintf(buf, sizeof(buf),
-             ctx->deleted == 1 ? _("Purge %d deleted message?") : _("Purge %d deleted messages?"),
+             ngettext("Purge %d deleted message?", "Purge %d deleted messages?", ctx->deleted),
              ctx->deleted);
     purge = query_quadoption(Delete, buf);
     if (purge == MUTT_ABORT)
@@ -1074,7 +1074,7 @@ int mx_sync_mailbox(struct Context *ctx, int *index_hint)
     char buf[SHORT_STRING];
 
     snprintf(buf, sizeof(buf),
-             ctx->deleted == 1 ? _("Purge %d deleted message?") : _("Purge %d deleted messages?"),
+             ngettext("Purge %d deleted message?", "Purge %d deleted messages?", ctx->deleted),
              ctx->deleted);
     purge = query_quadoption(Delete, buf);
     if (purge == MUTT_ABORT)