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
22 changes: 17 additions & 5 deletions babel/messages/pofile.py
Original file line number Diff line number Diff line change
Expand Up @@ -665,10 +665,19 @@ def _format_message(message, prefix=''):
yield f"{prefix}msgid {normalize(message.id, prefix=prefix, width=width)}\n"
yield f"{prefix}msgstr {normalize(message.string or '', prefix=prefix, width=width)}\n"

first_message = True

for message in _sort_messages(catalog, sort_by=sort_by):
if not message.id: # This is the header "message"
if omit_header:
continue
is_header = not message.id
if is_header and omit_header:
continue

if first_message:
first_message = False
else:
yield '\n'

if is_header:
comment_header = catalog.header_comment
if width and width > 0:
lines = []
Expand Down Expand Up @@ -718,17 +727,20 @@ def _format_message(message, prefix=''):
yield from _format_comment(f'msgid_plural {norm_previous_id}', prefix='|')

yield from _format_message(message)
yield '\n'

if not ignore_obsolete:
for message in _sort_messages(
catalog.obsolete.values(),
sort_by=sort_by,
):
if first_message:
first_message = False
else:
yield '\n'

for comment in message.user_comments:
yield from _format_comment(comment)
yield from _format_message(message, prefix='#~ ')
yield '\n'


def _sort_messages(
Expand Down
6 changes: 0 additions & 6 deletions tests/messages/frontend/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ def test_extract_with_default_mapping(cli, pot_file):
msgid_plural "FooBars"
msgstr[0] ""
msgstr[1] ""

"""
assert expected_content == pot_file.read_text()

Expand Down Expand Up @@ -213,7 +212,6 @@ def test_extract_with_mapping_file(cli, pot_file):
msgid_plural "foobars"
msgstr[0] ""
msgstr[1] ""

"""
assert expected_content == pot_file.read_text()

Expand Down Expand Up @@ -260,7 +258,6 @@ def test_extract_with_exact_file(cli, pot_file):
msgid_plural "foobars"
msgstr[0] ""
msgstr[1] ""

"""
assert expected_content == pot_file.read_text()

Expand Down Expand Up @@ -308,7 +305,6 @@ def test_init_with_output_dir(cli):
msgid_plural "foobars"
msgstr[0] ""
msgstr[1] ""

"""
with open(po_file) as f:
actual_content = f.read()
Expand Down Expand Up @@ -357,7 +353,6 @@ def test_init_singular_plural_forms(cli):
msgid "foobar"
msgid_plural "foobars"
msgstr[0] ""

"""
with open(po_file) as f:
actual_content = f.read()
Expand Down Expand Up @@ -409,7 +404,6 @@ def test_init_more_than_2_plural_forms(cli):
msgstr[0] ""
msgstr[1] ""
msgstr[2] ""

"""
with open(po_file) as f:
actual_content = f.read()
Expand Down
4 changes: 0 additions & 4 deletions tests/messages/frontend/test_extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ def test_extraction_with_default_mapping(extract_cmd, pot_file):
msgid_plural "FooBars"
msgstr[0] ""
msgstr[1] ""

"""
assert expected_content == pot_file.read_text()

Expand Down Expand Up @@ -196,7 +195,6 @@ def test_extraction_with_mapping_file(extract_cmd, pot_file):
msgid_plural "foobars"
msgstr[0] ""
msgstr[1] ""

"""
assert expected_content == pot_file.read_text()

Expand Down Expand Up @@ -250,7 +248,6 @@ def test_extraction_with_mapping_dict(extract_cmd, pot_file, ignore_pattern):
msgid_plural "foobars"
msgstr[0] ""
msgstr[1] ""

"""
assert expected_content == pot_file.read_text()

Expand Down Expand Up @@ -278,7 +275,6 @@ def test_extraction_add_location_file(extract_cmd, pot_file):
msgid_plural "foobars"
msgstr[0] ""
msgstr[1] ""

"""
assert expected_content == pot_file.read_text()

Expand Down
6 changes: 0 additions & 6 deletions tests/messages/frontend/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ def test_with_output_dir(init_cmd):
msgid_plural "foobars"
msgstr[0] ""
msgstr[1] ""

"""
with open(get_po_file_path('en_US')) as f:
actual_content = f.read()
Expand Down Expand Up @@ -150,7 +149,6 @@ def test_keeps_catalog_non_fuzzy(init_cmd):
msgid_plural "foobars"
msgstr[0] ""
msgstr[1] ""

"""
with open(get_po_file_path('en_US')) as f:
actual_content = f.read()
Expand Down Expand Up @@ -201,7 +199,6 @@ def test_correct_init_more_than_2_plurals(init_cmd):
msgstr[0] ""
msgstr[1] ""
msgstr[2] ""

"""
with open(get_po_file_path('lv_LV')) as f:
actual_content = f.read()
Expand Down Expand Up @@ -249,7 +246,6 @@ def test_correct_init_singular_plural_forms(init_cmd):
msgid "foobar"
msgid_plural "foobars"
msgstr[0] ""

"""
with open(get_po_file_path('ja_JP')) as f:
actual_content = f.read()
Expand Down Expand Up @@ -307,7 +303,6 @@ def test_supports_no_wrap(init_cmd):
msgid_plural "foobars"
msgstr[0] ""
msgstr[1] ""

"""
with open(get_po_file_path('en_US')) as f:
actual_content = f.read()
Expand Down Expand Up @@ -364,7 +359,6 @@ def test_supports_width(init_cmd):
msgid_plural "foobars"
msgstr[0] ""
msgstr[1] ""

"""
with open(get_po_file_path('en_US')) as f:
actual_content = f.read()
Expand Down
6 changes: 0 additions & 6 deletions tests/messages/test_checkers.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ def test_1_num_plurals_checkers():
msgid "foobar"
msgid_plural "foobars"
msgstr[0] ""

""").encode('utf-8')

# This test will fail for revisions <= 406 because so far
Expand Down Expand Up @@ -130,7 +129,6 @@ def test_2_num_plurals_checkers():
msgstr[0] ""
msgstr[1] ""
msgstr[2] ""

""".encode('utf-8')
# we should be adding the missing msgstr[0]

Expand Down Expand Up @@ -177,7 +175,6 @@ def test_3_num_plurals_checkers():
msgid_plural "foobars"
msgstr[0] ""
msgstr[1] ""

""".encode('utf-8')

# This test will fail for revisions <= 406 because so far
Expand Down Expand Up @@ -225,7 +222,6 @@ def test_4_num_plurals_checkers():
msgstr[0] ""
msgstr[1] ""
msgstr[2] ""

""".encode('utf-8')

# This test will fail for revisions <= 406 because so far
Expand Down Expand Up @@ -274,7 +270,6 @@ def test_5_num_plurals_checkers():
msgstr[1] ""
msgstr[2] ""
msgstr[3] ""

""".encode('utf-8')

# This test will fail for revisions <= 406 because so far
Expand Down Expand Up @@ -324,7 +319,6 @@ def test_6_num_plurals_checkers():
msgstr[2] ""
msgstr[3] ""
msgstr[4] ""

""".encode('utf-8')

# This test will fail for revisions <= 406 because so far
Expand Down
1 change: 0 additions & 1 deletion tests/messages/test_pofile_read.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,6 @@ def test_obsolete_messages_roundtrip():
#~ msgctxt "orange"
#~ msgid "foo"
#~ msgstr "Bar"

''')
generated_po_file = ''.join(pofile.generate_po(pofile.read_po(buf), omit_header=True))
assert buf.getvalue() == generated_po_file
Expand Down
2 changes: 0 additions & 2 deletions tests/messages/test_pofile_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ def test_no_wrap_and_width_behaviour_on_comments():
#: fake.py:29
msgid "pretty dam long message id, which must really be big to test this wrap behaviour, if not it won't work."
msgstr ""

"""
buf = BytesIO()
pofile.write_po(buf, catalog, width=100, omit_header=True)
Expand All @@ -149,7 +148,6 @@ def test_no_wrap_and_width_behaviour_on_comments():
"pretty dam long message id, which must really be big to test this wrap behaviour, if not it won't"
" work."
msgstr ""

"""


Expand Down