Skip to content
Merged
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
4 changes: 2 additions & 2 deletions babel/messages/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -1084,8 +1084,8 @@ def is_identical(self, other: Catalog) -> bool:
"""
assert isinstance(other, Catalog)
for key in self._messages.keys() | other._messages.keys():
message_1 = self.get(key)
message_2 = other.get(key)
message_1 = self._messages.get(key)
message_2 = other._messages.get(key)
if message_1 is None or message_2 is None or not message_1.is_identical(message_2):
return False
return dict(self.mime_headers) == dict(other.mime_headers)
31 changes: 31 additions & 0 deletions tests/messages/test_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -601,3 +601,34 @@ def test_catalog_tz_pickleable():
msgstr ""
"POT-Creation-Date: 2007-04-01 15:30+0200\n"
"""))))


def test_catalog_is_identical_with_context():
"""A catalog holding a context-specific message must compare equal to itself."""
cat = catalog.Catalog(locale='en')
cat.add('Guide', 'Guide', context='navigation')
assert cat.is_identical(cat)

same = catalog.Catalog(locale='en')
same.add('Guide', 'Guide', context='navigation')
assert cat.is_identical(same)

translated_differently = catalog.Catalog(locale='en')
translated_differently.add('Guide', 'Manual', context='navigation')
assert not cat.is_identical(translated_differently)

# The same msgid under a different context is a different message.
other_context = catalog.Catalog(locale='en')
other_context.add('Guide', 'Guide', context='footer')
assert not cat.is_identical(other_context)


def test_catalog_is_identical_with_pluralizable_context():
"""The same, for a context-specific *pluralizable* message."""
cat = catalog.Catalog(locale='en')
cat.add(('%d page', '%d pages'), ('%d page', '%d pages'), context='report')
assert cat.is_identical(cat)

same = catalog.Catalog(locale='en')
same.add(('%d page', '%d pages'), ('%d page', '%d pages'), context='report')
assert cat.is_identical(same)
Loading