Skip to content

Commit 7189a64

Browse files
mmaxjrhugovk
authored andcommitted
Respect translated intword units across scale gaps
1 parent 934279e commit 7189a64

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

‎src/humanize/number.py‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,13 +293,18 @@ def intword(value: NumberOrString, format: str = "%.1f") -> str:
293293
# decillion to googol), so there is no unit for "1000+ of the
294294
# current one". Only bump to the next unit if the value is
295295
# close enough to actually round up to it; otherwise there is
296-
# no name for this magnitude, so fall back to the plain number.
296+
# no English name for this magnitude. Some locales translate the
297+
# current unit to a larger local scale, so allow those to keep
298+
# using the translated unit instead of falling back.
297299
next_rounded_value = float(format % (value / next_power))
298300
if next_rounded_value >= 1.0:
299301
ordinal += 1
300302
rounded_value = next_rounded_value
301303
else:
302-
return f"{negative_prefix}{value}"
304+
singular, plural = human_powers[ordinal]
305+
translated_unit = _ngettext(singular, plural, math.ceil(rounded_value))
306+
if translated_unit in (singular, plural):
307+
return f"{negative_prefix}{value}"
303308

304309
singular, plural = human_powers[ordinal]
305310
unit = _ngettext(singular, plural, math.ceil(rounded_value))

0 commit comments

Comments
 (0)