Edgewall Software

Opened 8 years ago

Closed 8 years ago

#159 closed defect (fixed)

Babel bungles msgctxt parsing if there are no comments before the msgctxt

Reported by: babel+2009-01-27@… Owned by: cmlenz
Priority: major Milestone: 1.0
Component: PO and MO Files Version: devel
Keywords: Cc:

Description

(This is against svn trunk.)

In a simple test of a PO file with two entries, each with its own msgctxt, Babel fails to parse the catalog properly. It manages to fail to register an entry for the second message ID at all.

I'm attaching a test that shows this. You'll see that:

message = catalog.get('bar')

yields None, rather than the actual message....

Attachments (2)

test_that_fails.patch (1.2 KB) - added by anonymous 8 years ago.
A patch providing a test that fails
fixed_patch.patch (1.7 KB) - added by babel+2009-01-27@… 8 years ago.
A patch that fixes msgctxt parsing when the PO file has no comments

Download all attachments as: .zip

Change History (8)

Changed 8 years ago by anonymous

A patch providing a test that fails

comment:1 Changed 8 years ago by babel+2009-01-27@…

I think that the problem lies in improper handling of msgctxt in babel/messages/pofile.py 's function, read_po.

In particular, I belive that _process_message_line is not properly starting a new message when msgctxt is seen.

I just spent a few hours trying to work on this, but I didn't get very far. I may try again later, but really I hope someone actually familiar with _process_message_line can just read through it and see if I'm right.

comment:2 Changed 8 years ago by babel+2009-01-27@…

  • Summary changed from Babel bungles msgctxt parsing to Babel bungles msgctxt parsing if there are no comments before the msgctxt

First of all, I messed up the test that fails. (When searching for the message using .get(), I neglected to pass in the context. So of course the catalog object could not find the message I was requesting.)

I'm attaching a new patch with a test that properly calls .get() with both the message ID and the message context.

This test fails against svn trunk. In current svn trunk, Babel's read_po() only calls _add_message() at a comment or at new msgid stanza. If Babel hits a msgctxt, this should always mean a new message has started.

However, if Babel hits a msgctxt block that is not preceded by a comment, Babel will not call _add_message() until the following msgid block. This means that in this case:

msgctxt "Menu" msgid "foo" msgstr "Voh"

msgctxt "Mannu" msgid "bar" msgstr "Bahr"

the first message created has two context lines associated with it: ["Menu", "Mannu"]. The second message has zero context associated with it.

In the attached patch (entitled fixed_patch.patch), I have added a two-line fix to make sure that a msgctxt block causes Babel to flush the message it was formerly working on.

comment:3 Changed 8 years ago by babel+2009-01-27@…

The sample failing PO snippet should be:

msgctxt "Menu"
msgid "foo"
msgstr "Voh"

msgctxt "Mannu"
msgid "bar"
msgstr "Bahr"

(Same rules for copyright apply as before. I'm Asheesh Laroia, and this work is (C) 2009, Creative Commons. Permission is granted to redistribute this under the same terms as Babel.)

Changed 8 years ago by babel+2009-01-27@…

A patch that fixes msgctxt parsing when the PO file has no comments

comment:4 Changed 8 years ago by palgarvio

Seems like a simple fix. For me it's good, still, I'd have Chris have a look at it too.

comment:5 Changed 8 years ago by cmlenz

Patch looks good to me.

comment:6 Changed 8 years ago by cmlenz

  • Resolution set to fixed
  • Status changed from new to closed

Applied in [470]. Thanks!

Note: See TracTickets for help on using tickets.