Skip to content

Allow catalog updates without new fuzzy flags - #1418

Open
ada-wh525 wants to merge 2 commits into
python-babel:masterfrom
ada-wh525:ada-wh525/update-without-fuzzy
Open

ada-wh525 wants to merge 2 commits into
python-babel:masterfrom
ada-wh525:ada-wh525/update-without-fuzzy

Conversation

@ada-wh525

Copy link
Copy Markdown

Updating a source message to correct a spelling mistake currently marks its reused translation as fuzzy, even when the translation remains valid. Disabling fuzzy matching also prevents that translation from being reused.

Add pybabel update --no-fuzzy-flags and the corresponding Catalog.update(no_fuzzy_flags=True) option. This allows translations to be reused without adding a fuzzy flag solely because the message ID changed.

Default behavior remains unchanged. Existing fuzzy flags and checks for changes to singular/plural structure are preserved.

Includes CLI documentation and tests covering singular/plural messages, contexts, existing flags, previous IDs, and PO file updates.

Validation:

  • Python 3.14 full suite: 7,962 passed, 7 skipped, 2 xfailed.
  • All pre-commit checks passed.
  • Source distribution and wheel builds succeeded.

Closes #1030

Add an opt-in update option for source spelling corrections whose
translations remain valid. Keep existing fuzzy flags and plural-shape
checks, and cover both the catalog API and PO file updates.

Closes python-babel#1030

@chrikrah chrikrah left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ada-wh525, reverting catalog.py:991 fails 5 of your 22 cases. Nothing here blocks a merge.

$ python -m pytest -q -p no:cacheprovider tests/messages   # head 08d80b5, git archive export, babel.__file__ from the export, CLDR data from the 2.18.0 wheel, Python 3.12
1 failed, 468 passed   # test_checkers.py::test_4_num_plurals_checkers, UnknownLocaleError from the older CLDR data, not this change

$ python -m pytest -q -p no:cacheprovider tests/messages -k no_fuzzy_flags
22 passed, 1 skipped, 443 deselected

$ sed -i '991s/fuzzy = not no_fuzzy_flags/fuzzy = True/' babel/messages/catalog.py   # only the behavioural line reverted
$ python -m pytest -q -p no:cacheprovider tests/messages -k no_fuzzy_flags
5 failed, 17 passed, 1 skipped, 443 deselected

$ python3 -I -c "from difflib import SequenceMatcher as S; print(S(None, 'enable notifications', 'disable notifications', autojunk=False).ratio())"
0.878   # above get_close_matches cutoff=0.6, catalog.py:44

non-blocking: the flag is run-wide, so "Disable notifications" keeps "Enable" unflagged. Note that in cmdline.rst?

@ada-wh525

Copy link
Copy Markdown
Author

@ada-wh525, reverting catalog.py:991 fails 5 of your 22 cases. Nothing here blocks a merge.

$ python -m pytest -q -p no:cacheprovider tests/messages   # head 08d80b5, git archive export, babel.__file__ from the export, CLDR data from the 2.18.0 wheel, Python 3.12
1 failed, 468 passed   # test_checkers.py::test_4_num_plurals_checkers, UnknownLocaleError from the older CLDR data, not this change

$ python -m pytest -q -p no:cacheprovider tests/messages -k no_fuzzy_flags
22 passed, 1 skipped, 443 deselected

$ sed -i '991s/fuzzy = not no_fuzzy_flags/fuzzy = True/' babel/messages/catalog.py   # only the behavioural line reverted
$ python -m pytest -q -p no:cacheprovider tests/messages -k no_fuzzy_flags
5 failed, 17 passed, 1 skipped, 443 deselected

$ python3 -I -c "from difflib import SequenceMatcher as S; print(S(None, 'enable notifications', 'disable notifications', autojunk=False).ratio())"
0.878   # above get_close_matches cutoff=0.6, catalog.py:44

non-blocking: the flag is run-wide, so "Disable notifications" keeps "Enable" unflagged. Note that in cmdline.rst?

Added a note in ba1aa84 to explain that.

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.

Feature request: Update catalogs with fuzzy matching, but don't add fuzzy flags

2 participants