Skip to content

Read previous msgids (#|) from PO files and keep them on update - #1466

Open
jayhemnani9910 wants to merge 1 commit into
python-babel:masterfrom
jayhemnani9910:fix/read-previous-msgid
Open

jayhemnani9910 wants to merge 1 commit into
python-babel:masterfrom
jayhemnani9910:fix/read-previous-msgid

Conversation

@jayhemnani9910

Copy link
Copy Markdown
Contributor

pybabel update --previous writes the old msgid of a fuzzy message as #| msgid ..., but read_po doesn't parse #| lines and stores them as user comments. The next update --previous writes them back as translator comments:

# first run                      # every later run
#, fuzzy                         # | msgid "Save the file"
#| msgid "Save the file"         #: app.py:2
msgid "Save this file"           #, fuzzy
msgstr "Datei speichern"         msgid "Save this file"
                                 msgstr "Datei speichern"

The # | msgid line then stays in the catalog as a translator comment even after the string is fixed. The same happens to #| lines written by GNU msgmerge --previous.

Two changes:

  • read_po parses #| msgid / #| msgid_plural (and their continuation lines) into Message.previous_id. Message has no field for a previous msgctxt, so a #| msgctxt line is dropped instead of becoming a comment.
  • Catalog.update keeps previous_id for a message that matches exactly but is still fuzzy, so a second run keeps the #| line, like msgmerge.
  • write_po wrapped a long previous msgid with the comment wrapper, which splits it in the middle of the quoted strings (#| msgid "" "Save the file ... window so / #| " "nothing is lost"). It now writes one #| line per line of the normalized string, the way msgmerge does, so it reads back unchanged.

With both, three pybabel update --previous runs on the example above keep #| msgid "Save the file".

test_previous_msgid_roundtrip, test_long_previous_msgid_roundtrip and test_catalog_update_keeps_previous_id_of_fuzzy_message fail without the change. pytest tests/messages: the only failure is test_4_num_plurals_checkers, which fails the same way on master here (my locale data comes from the installed Babel 2.17.0, as the checkout has none).

@codspeed

codspeed Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 88 untouched benchmarks


Comparing jayhemnani9910:fix/read-previous-msgid (ee8f557) with master (aeca9fa)

Open in CodSpeed

read_po stored "#| msgid ..." lines as user comments, so the next
write_po turned them into "# | msgid ..." translator comments that
stay forever. Parse them into Message.previous_id, and keep the
previous_id of a message that is still fuzzy in Catalog.update, so
repeated "pybabel update --previous" runs keep the #| lines like
msgmerge does.

write_po wrapped a long previous msgid like a comment, splitting its
quoted strings; write one "#| " line per normalized line instead, so
it reads back unchanged.
@jayhemnani9910
jayhemnani9910 force-pushed the fix/read-previous-msgid branch from 09cd25b to ee8f557 Compare November 20, 2026 06:06
@codecov

codecov Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.69%. Comparing base (aeca9fa) to head (ee8f557).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1466      +/-   ##
==========================================
+ Coverage   93.67%   93.69%   +0.01%     
==========================================
  Files          27       27              
  Lines        4983     4998      +15     
==========================================
+ Hits         4668     4683      +15     
  Misses        315      315              
Flag Coverage Δ
macos-26-3.10 92.77% <100.00%> (+0.02%) ⬆️
macos-26-3.11 92.71% <100.00%> (+0.02%) ⬆️
macos-26-3.12 92.97% <100.00%> (+0.02%) ⬆️
macos-26-3.13 92.97% <100.00%> (+0.02%) ⬆️
macos-26-3.14 92.95% <100.00%> (+0.02%) ⬆️
macos-26-3.15 92.95% <100.00%> (+0.02%) ⬆️
macos-26-3.9 92.71% <100.00%> (+0.02%) ⬆️
macos-26-pypy3.11 92.71% <100.00%> (+0.02%) ⬆️
macos-26-pypy3.12 92.97% <100.00%> (+0.02%) ⬆️
ubuntu-24.04-3.10 92.79% <100.00%> (+0.02%) ⬆️
ubuntu-24.04-3.11 92.73% <100.00%> (+0.02%) ⬆️
ubuntu-24.04-3.12 92.99% <100.00%> (+0.02%) ⬆️
ubuntu-24.04-3.13 92.99% <100.00%> (+0.02%) ⬆️
ubuntu-24.04-3.14 92.97% <100.00%> (+0.02%) ⬆️
ubuntu-24.04-3.15 92.97% <100.00%> (+0.02%) ⬆️
ubuntu-24.04-3.9 92.73% <100.00%> (+0.02%) ⬆️
ubuntu-24.04-pypy3.11 92.73% <100.00%> (+0.02%) ⬆️
ubuntu-24.04-pypy3.12 92.99% <100.00%> (+0.02%) ⬆️
windows-2025-3.10 92.78% <100.00%> (+0.02%) ⬆️
windows-2025-3.11 92.72% <100.00%> (+0.02%) ⬆️
windows-2025-3.12 92.99% <100.00%> (+0.02%) ⬆️
windows-2025-3.13 92.99% <100.00%> (+0.02%) ⬆️
windows-2025-3.14 92.97% <100.00%> (+0.02%) ⬆️
windows-2025-3.15 92.97% <100.00%> (+0.02%) ⬆️
windows-2025-3.9 92.72% <100.00%> (+0.02%) ⬆️
windows-2025-pypy3.11 92.72% <100.00%> (+0.02%) ⬆️
windows-2025-pypy3.12 92.99% <100.00%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant