Skip to content

Commit f77241e

Browse files
committed
Interpolate the number into ordinal, intword and filesize translations
1 parent 392aef7 commit f77241e

39 files changed

Lines changed: 4485 additions & 3315 deletions

File tree

‎src/humanize/filesize.py‎

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,31 +5,32 @@
55
__lazy_modules__ = {"humanize.i18n"}
66

77
from humanize.i18n import _gettext as _
8+
from humanize.i18n import _gettext_noop as N_
89

910
suffixes = {
1011
"decimal": (
11-
"kB",
12-
"MB",
13-
"GB",
14-
"TB",
15-
"PB",
16-
"EB",
17-
"ZB",
18-
"YB",
19-
"RB",
20-
"QB",
12+
N_("%s kB"),
13+
N_("%s MB"),
14+
N_("%s GB"),
15+
N_("%s TB"),
16+
N_("%s PB"),
17+
N_("%s EB"),
18+
N_("%s ZB"),
19+
N_("%s YB"),
20+
N_("%s RB"),
21+
N_("%s QB"),
2122
),
2223
"binary": (
23-
"KiB",
24-
"MiB",
25-
"GiB",
26-
"TiB",
27-
"PiB",
28-
"EiB",
29-
"ZiB",
30-
"YiB",
31-
"RiB",
32-
"QiB",
24+
N_("%s KiB"),
25+
N_("%s MiB"),
26+
N_("%s GiB"),
27+
N_("%s TiB"),
28+
N_("%s PiB"),
29+
N_("%s EiB"),
30+
N_("%s ZiB"),
31+
N_("%s YiB"),
32+
N_("%s RiB"),
33+
N_("%s QiB"),
3334
),
3435
"gnu": "KMGTPEZYRQ",
3536
}
@@ -105,6 +106,7 @@ def naturalsize(
105106
# suffix is available, step up one suffix so the result reads "1.0 MB".
106107
if exp < len(suffix) and abs(float(format % (abs_bytes / (base**exp)))) >= base:
107108
exp += 1
108-
space = "" if gnu else " "
109-
ret: str = format % (bytes_ / (base**exp)) + space + _(suffix[exp - 1])
110-
return ret
109+
number: str = format % (bytes_ / (base**exp))
110+
if gnu:
111+
return number + _(suffix[exp - 1])
112+
return _(suffix[exp - 1]) % number

0 commit comments

Comments
 (0)