bugGNU gettext - Bugs: bug #24433, missing Python format specifier is...

 
 

You are not allowed to post comments on this tracker with your current authentication level.

bug #24433: missing Python format specifier is not a fatal error

Submitter:  anatoly techtonik <techtonik>
Submitted:  Thu 02 Oct 2008 03:52:29 PM UTC
   
 
Category:  Plural forms Severity:  3 - Normal
Item Group:  None Status:  Fix Released
Privacy:  Public Assigned to:  haible
Open/Closed:  Closed

Sat 04 Oct 2008 03:00:38 PM UTC, comment #3: 

As a workaround (as a translator), you can use a plural formula
that has 4 plural forms:
  n == 1 -> 0
  n%10==1 && n%100!=11 -> 1
  n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) -> 2
  elee -> 3

But for a real fix: I've now added to gettext the support for a
'range:' declaration. The programmer can write

  # xgettext: range: 1..3
  s = self.ngettext('1 %(number)s/4 hours', '1 %(number)s/4 hours', _quarters)%{'number': _quarters))

This information about the range will make msgfmt understand that
the form applies to a single value of n in this case and that
therefore omitting the %(number) directive is ok.

Will be contained in gettext 0.18.

Bruno Haible <haible>
Group administrator
Fri 03 Oct 2008 09:00:00 AM UTC, comment #2: 

# third form ain't used
#: ../roundup/date.py:851
#, python-format
msgid "1 %(number)s/4 hours"
msgid_plural "1 %(number)s/4 hours"
msgstr[0] "час с четвертью"
msgstr[1] "час и %(number)s четверти"
msgstr[2] "час и %(number)s четвертей"



---cut date.py
...
elif self.hour == 1:
    if self.minute < 15:
       s = self._('an hour')
    elif _quarters == 2:
       s = self._('1 1/2 hours')
    else:
       s = self.ngettext('1 %(number)s/4 hours',
          '1 %(number)s/4 hours', _quarters)%{'number': _quarters
...
---cut date.py


Here the first form of plural translation for hour quarters has a fixed value in russian locale. It is the same as "hour and a quarter" in english.

I do not know which tool was used to produce this .po file and compile it, but it works with roundup just perfect.

Note, however, that if format specifier is not named - Python throws exception. Just to make sure we didn't miss the point.

anatoly techtonik <techtonik>
Fri 03 Oct 2008 12:32:26 AM UTC, comment #1: 


> if translator chooses to omit keyword format specifier, in
> current 0.17 msgfmt implementation "msgfmt -c" will fail with
> fatal error.


Yes, this is so, because the translation then does not reflect
the meaning and information that the msgid had.

> I would like to ask for addition of an explicit
> python-keyword-missing-ok flag to mark such entries as valid
> explicitly.


An interesting idea. But first, can you show the use case? A
case where the programmer wants to give the translator the choice
whether to include some information in the output or not?

Bruno Haible <haible>
Group administrator
Thu 02 Oct 2008 03:52:29 PM UTC, original submission:  

Python strings may contain keyword format specifiers like described in gettext manual http://www.gnu.org/software/gettext/manual/gettext.html#Python
--cut--
Formatting with positions
    '...%(ident)d...' % { 'ident': value }
--cut--

As you may see - 'ident' keyword should be present in arguments, but it is not an error if it is missing from format string. However, if translator chooses to omit keyword format specifier, in current 0.17 msgfmt implementation "msgfmt -c" will fail with fatal error.

The attached file is taken from Python bugtracker localization and this is the output msgfmt -c produces:
ru.po:1695: a format specification for argument 'number' doesn't exist in 'msgstr[0]'
ru.po:1729: a format specification for argument 'number' doesn't exist in 'msgstr[0]'


I would like to ask for addition of an explicit python-keyword-missing-ok flag to mark such entries as valid explicitly. Or to allow missing keyword format specifiers implicitly.

anatoly techtonik <techtonik>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attached Files
file #16601:  ru.po added by techtonik (117KiB - application/octet-stream)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by haible (Posted a comment)
  • -email is unavailable- added by techtonik (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

     

    Follow 7 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2023-01-04 haible StatusFixed Fix Released
    2016-11-27 haible CategoryNone Plural forms
    2008-10-04 haible StatusNeed Info Fixed
        Open/ClosedOpen Closed
    2008-10-03 haible StatusNone Need Info
        Assigned toNone haible
    2008-10-02 techtonik Attached File- Added ru.po, #16601

    Back to the top

    Powered by Savane 3.13-4b48.
    Corresponding source code