Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the way obsolete messages are stored #1132

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion babel/messages/pofile.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ def _add_message(self) -> None:
context=msgctxt)
if self.obsolete:
if not self.ignore_obsolete:
self.catalog.obsolete[msgid] = message
self.catalog.obsolete[self.catalog._key_for(msgid, msgctxt)] = message
else:
self.catalog[msgid] = message
self.counter += 1
Expand Down
31 changes: 29 additions & 2 deletions tests/messages/test_pofile.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,10 +299,37 @@ def test_obsolete_message_with_context(self):
catalog = pofile.read_po(buf)
assert len(catalog) == 2
assert len(catalog.obsolete) == 1
message = catalog.obsolete["foo"]
message = catalog.obsolete[("foo", "other")]
assert message.context == 'other'
assert message.string == 'Voh'

def test_obsolete_messages_with_context(self):
buf = StringIO('''
# This is an obsolete message
#~ msgctxt "apple"
#~ msgid "foo"
#~ msgstr "Foo"

# This is an obsolete message with the same id but different context
#~ msgctxt "orange"
#~ msgid "foo"
#~ msgstr "Bar"
''')
catalog = pofile.read_po(buf)
assert len(catalog) == 0
assert len(catalog.obsolete) == 2
assert 'foo' not in catalog.obsolete

apple_msg = catalog.obsolete[('foo', 'apple')]
assert apple_msg.id == 'foo'
assert apple_msg.string == 'Foo'
assert apple_msg.user_comments == ['This is an obsolete message']

orange_msg = catalog.obsolete[('foo', 'orange')]
assert orange_msg.id == 'foo'
assert orange_msg.string == 'Bar'
assert orange_msg.user_comments == ['This is an obsolete message with the same id but different context']

def test_multiline_context(self):
buf = StringIO('''
msgctxt "a really long "
Expand Down Expand Up @@ -394,7 +421,7 @@ def test_obsolete_plural_with_square_brackets(self):
assert len(catalog) == 0
assert len(catalog.obsolete) == 1
assert catalog.num_plurals == 2
message = catalog.obsolete[('foo', 'foos')]
message = catalog.obsolete['foo']
assert len(message.string) == 2
assert message.string[0] == 'Voh [text]'
assert message.string[1] == 'Vohs [text]'
Expand Down