Skip to content

Remove the leftover format placeholder from intword units - #382

Open
VenishPaneliya wants to merge 1 commit into
python-humanize:mainfrom
VenishPaneliya:intword-unit-placeholders
Open

Remove the leftover format placeholder from intword units#382
VenishPaneliya wants to merge 1 commit into
python-humanize:mainfrom
VenishPaneliya:intword-unit-placeholders

Conversation

@VenishPaneliya

Copy link
Copy Markdown

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.
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