Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions babel/messages/mofile.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ def read_mo(fileobj: SupportsRead[bytes]) -> Catalog:

if b'\x04' in msg: # context
ctxt, msg = msg.split(b'\x04')
ctxt = ctxt.decode(catalog.charset)
else:
ctxt = None

Expand Down
13 changes: 13 additions & 0 deletions tests/messages/test_mofile.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,19 @@ def test_basics():
assert catalog['foobar'].string == ['Fuhstange', 'Fuhstangen']


def test_context_is_decoded():
# The message context should be decoded to a string, just like the message
# id and string, so that a written catalog round-trips back to an equal one.
catalog = Catalog(locale='en_US')
catalog.add('foo', 'Voh', context='fooctxt')
buf = BytesIO()
mofile.write_mo(buf, catalog)
buf.seek(0)
catalog = mofile.read_mo(buf)
message = catalog.get('foo', context='fooctxt')
assert message is not None
assert message.context == 'fooctxt'


def test_sorting():
# Ensure the header is sorted to the first entry so that its charset
Expand Down