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

Submitted by:  anatoly techtonik <techtonik>
Submitted on:  Thu 02 Oct 2008 03:52:29 PM UTC  
 
Category: Plural formsSeverity: 3 - Normal
Item Group: NoneStatus: Fixed
Privacy: PublicAssigned to: Bruno Haible <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>
Project AdministratorIn charge of this item.
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>
Project AdministratorIn charge of this item.
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>

 

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
  • -unavailable- added by haible (Posted a comment)
  • -unavailable- added by techtonik (Submitted the item)
  •  

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follow 6 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Sun 27 Nov 2016 12:04:13 AM UTChaibleCategoryNone=>Plural forms
    Sat 04 Oct 2008 03:00:37 PM UTChaibleStatusNeed Info=>Fixed
      Open/ClosedOpen=>Closed
    Fri 03 Oct 2008 12:32:26 AM UTChaibleStatusNone=>Need Info
      Assigned toNone=>haible
    Thu 02 Oct 2008 03:52:29 PM UTCtechtonikAttached File-=>Added ru.po, #16601

    Back to the top


    Powered by Savane 3.1-cleanup1