diff --git a/babel/messages/catalog.py b/babel/messages/catalog.py index 9f215cf18..ecf6f91d4 100644 --- a/babel/messages/catalog.py +++ b/babel/messages/catalog.py @@ -479,7 +479,11 @@ def _set_mime_headers(self, headers: Iterable[tuple[str, str]]) -> None: self.last_translator = value elif name == 'language': value = value.replace('-', '_') - self._set_locale(value) + # The `or None` makes sure that the locale is set to None + # if the header's value is an empty string, which is what + # some tools generate (instead of eliding the empty Language + # header altogether). + self._set_locale(value or None) elif name == 'language-team': self.language_team = value elif name == 'content-type': diff --git a/tests/messages/test_pofile.py b/tests/messages/test_pofile.py index 99958b7b7..d1a3e2d11 100644 --- a/tests/messages/test_pofile.py +++ b/tests/messages/test_pofile.py @@ -893,3 +893,12 @@ def test_iterable_of_strings(): catalog = pofile.read_po(['msgid "foo"', b'msgstr "Voh"'], locale="en_US") assert catalog.locale == Locale("en", "US") assert catalog.get("foo").string == "Voh" + + +def test_issue_1087(): + buf = StringIO(r''' +msgid "" +msgstr "" +"Language: \n" +''') + assert pofile.read_po(buf).locale is None