bug-gnu-utils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Bug report: msgfmt -c doesn't fail for some incorrect C format plura


From: Bruno Haible
Subject: Re: Bug report: msgfmt -c doesn't fail for some incorrect C format plural forms
Date: Tue, 4 Oct 2005 15:20:00 +0200
User-agent: KMail/1.5

Farzaneh Sarafraz wrote:
> Consider the following (incorrect) translation from fa.po:
>
> #: ../same-gnome/ui.c:73
> #, c-format
> msgid "%d point"
> msgid_plural "%d points"
> msgstr[0] "امتیاز"
>
> in Persian translation of gnome-games, where we have"Plural-Forms:
> nplurals=1; plural=0;\n" for Persian. Notice that %d is missing in the
> translation string, so the C format specification of msgid and msgstr do
> not match.
>
> How to reproduce the bug:
> msgfmt -cv fa.po
>
> What was expected:
> gnome-games.gnome-2-12.fa.po:4597: number of format specifications in
> 'msgid' and 'msgstr[0]' does not match msgfmt: found 1 fatal error

> For more information, this is the correct translation of the above string:
> msgstr[0] "%Id امتیاز"

Thanks for the report. The appended patch fixes it.

> In general, at least one of the plural forms must contain the C format
> specifier; otherwise msgfmt -c should fail.

It is a little bit complicated to fix this also for the case nplurals > 1.
Therefore I'm fixing the problem only for nplurals = 1 (your case).

Bruno


*** gettext-tools/src/format.c  19 Sep 2005 16:10:25 -0000      1.14
--- gettext-tools/src/format.c  4 Oct 2005 13:20:13 -0000
***************
*** 23,28 ****
--- 23,29 ----
  /* Specification.  */
  #include "format.h"
  
+ #include <stdbool.h>
  #include <stdio.h>
  #include <stdlib.h>
  
***************
*** 98,103 ****
--- 99,113 ----
          {
            char buf[18+1];
            const char *pretty_msgstr = "msgstr";
+           /* Use strict checking (require same number of format directives
+              on both sides) if the message has no plurals, or if msgid_plural
+              exists but on the msgstr[] side there is only msgstr[0].
+              Use relaxed checking when there are at least two msgstr[] forms.
+              We are too lazy to check which of the plural forms applies to
+              infinitely many values of N.  */
+           bool has_plural_translations = (strlen (msgstr) + 1 < msgstr_len);
+           bool strict_checking =
+             (msgid_plural == NULL || !has_plural_translations);
            const char *p_end = msgstr + msgstr_len;
            const char *p;
  
***************
*** 116,122 ****
                if (msgstr_descr != NULL)
                  {
                    if (parser->check (msgid_descr, msgstr_descr,
!                                      msgid_plural == NULL,
                                       error_logger, pretty_msgstr))
                      err = true;
  
--- 126,132 ----
                if (msgstr_descr != NULL)
                  {
                    if (parser->check (msgid_descr, msgstr_descr,
!                                      strict_checking,
                                       error_logger, pretty_msgstr))
                      err = true;
  





reply via email to

[Prev in Thread] Current Thread [Next in Thread]