Skip to content

Remove the leftover format placeholder from intword units - #382

Merged
hugovk merged 2 commits into
python-humanize:mainfrom
VenishPaneliya:intword-unit-placeholders
Sep 16, 2026
Merged

hugovk merged 2 commits into
python-humanize:mainfrom
VenishPaneliya:intword-unit-placeholders

Conversation

@VenishPaneliya

Copy link
Copy Markdown
Contributor

intword inserts the unit without any % substitution:

singular, plural = human_powers[ordinal]
unit = _ngettext(singular, plural, math.ceil(rounded_value))
...
return f"{negative_prefix}{number} {unit}"

so a printf placeholder left in a translated unit is printed literally. The Bengali, Korean and Vietnamese catalogues still carry %d or %(value)s on the thousandgoogol units:

humanize.i18n.activate("bn_BD"); humanize.intword(1_500_000_000)
humanize.i18n.activate("vi_VN"); humanize.intword(1_200_000)
humanize.i18n.activate("ko_KR"); humanize.intword(1_200_000)

On main:

'1.5 %d বিলিয়ন'
'1.2 %(value)s triệu'
'1.2 %(value)s million'

With this PR:

'1.5 বিলিয়ন'
'1.2 triệu'
'1.2 million'

This strips the placeholder and the separator that follows it (a plain space or U+00A0) and leaves the translated words untouched.

Scope is deliberately narrow: only the twelve intword power msgids are changed. Placeholders elsewhere in these catalogues are substituted normally and are left alone — naturaldelta's "%d day" and friends still need theirs. After the change, none of the 36 catalogues emits a placeholder for any of the twelve powers.

Added a parametrised regression test over the three locales, checking that intword never returns a % at any power. It fails 3/3 on main and passes here.

Two notes I did not act on, since both need a native speaker rather than a scripted edit:

  • ko_KR renders several powers as the English words (million, billion), and its trillion entry reads billion.
  • ko_KR and vi_VN also contain a couple of French leftovers (décillion, gogol).

Happy to split those out separately if you would like them addressed.

`intword` inserts the unit without any `%` substitution:

    return f"{negative_prefix}{number} {unit}"

so a placeholder left in a translated unit is printed literally. The
Bengali, Korean and Vietnamese catalogues still carry `%d` or
`%(value)s` on the `thousand`..`googol` units, presumably from an older
API:

    activate("bn_BD"); intword(1_500_000_000)  ->  '1.5 %d বিলিয়ন'
    activate("vi_VN"); intword(1_200_000)      ->  '1.2 %(value)s triệu'

Strip the placeholder and the separator after it, leaving the translated
words untouched. Only the `intword` power units are changed; placeholders
in other messages are substituted normally and are left alone.

After this, none of the 36 catalogues emits a placeholder for any of the
12 powers.
@hugovk hugovk added the changelog: Fixed For any bug fixes label Sep 16, 2026
@hugovk hugovk changed the title Remove the leftover format placeholder from intword units Remove the leftover format placeholder from intword units Sep 16, 2026
@codecov

codecov Bot commented Sep 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.57%. Comparing base (ce4147b) to head (0e91641).
⚠️ Report is 11 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #382      +/-   ##
==========================================
+ Coverage   99.56%   99.57%   +0.01%     
==========================================
  Files          12       12              
  Lines         916      938      +22     
==========================================
+ Hits          912      934      +22     
  Misses          4        4              
Flag Coverage Δ
macos-latest 97.44% <81.81%> (-0.16%) ⬇️
ubuntu-latest 97.44% <81.81%> (-0.16%) ⬇️
windows-latest 95.30% <81.81%> (-0.11%) ⬇️

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.

Comment thread tests/test_i18n.py Outdated
@hugovk
hugovk force-pushed the intword-unit-placeholders branch from 452e2b3 to 0e91641 Compare September 16, 2026 15:36
@hugovk
hugovk enabled auto-merge (squash) September 16, 2026 15:37
@hugovk

hugovk commented Sep 16, 2026

Copy link
Copy Markdown
Member

Thanks!

@hugovk
hugovk merged commit 14965a7 into python-humanize:main Sep 16, 2026
43 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog: Fixed For any bug fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants