From: Justin Tobler Date: Mon, 15 Dec 2025 16:47:27 GMT Subject: Re: [PATCH v2 2/7] strbuf: split out logic to humanise byte values Message-ID: In-Reply-To: On 25/12/15 05:21PM, Junio C Hamano wrote: > Justin Tobler writes: > > > +char *strbuf_humanise_bytes_value(struct strbuf *buf, off_t bytes, unsigned flags) > > { > > + int humanise_rate = flags & STRBUF_HUMANISE_RATE; > > + > > if (bytes > 1 << 30) { > > + strbuf_addf(buf, "%u.%2.2u", (unsigned)(bytes >> 30), > > (unsigned)(bytes & ((1 << 30) - 1)) / 10737419); > > + /* TRANSLATORS: IEC 80000-13:2008 gibibyte/second and gibibyte */ > > + return humanise_rate ? xstrfmt(_("GiB/s")) : xstrfmt(_("GiB")); > > ... > > } > > void strbuf_humanise_bytes(struct strbuf *buf, off_t bytes) > > { > > - strbuf_humanise(buf, bytes, 0); > > + char *unit = strbuf_humanise_bytes_value(buf, bytes, 0); > > + strbuf_addf(buf, " %s", unit); > > + free(unit); > > } > > The old "strbuf-humanise" used to treat the whole " ", > e.g., _("%u.%2.2u GiB"), as a single thing to be translated. > However, the new code requires that in all languages: > > - Decimal point in number MUST be "." (don't some Europeans prefer > comma instead?); > > - Number MUST come before the unit; > > - Between the number and the unit, there has to be one and only one > SP. > > All of which could be a severe regression from localization's point > of view. > > The first point among the above three can relatively easily > remedied. It is a bit more involved, but it is possible to fix the > other two, too. The first point could be addressed by just making "%u.%2.2u" translatable. To address the others, we could have strbuf_humanise_bytes_value() output two separate strings (value and unit) instead of appending the the value and returning the unit. Maybe something like: void humanise_bytes(off_t bytes, char **value, const char **unit) We could then have another translatable string to configure the format: void strbuf_humanise_bytes(struct strbuf *buf, off_t bytes) { char *value; const char *unit; humanise_bytes(bytes, &value, &unit); strbuf_addf(buf, _("%s %s"), value, unit); free(value); } This is certainly a bit more involved setup for translators though. But maybe it's ok? I'll move forward with something like above in the next version for now. Thanks -Justin