git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v5] l10n: localizable upload progress messages

From
Junio C Hamano <gitster@pobox.com>
Date
Jun 25, 2019, 20:00 UTC
Message-ID
<xmqqzhm5e8p9.fsf@gitster-ct.c.googlers.com>
In-Reply-To
<20190625062540.88973-2-dimitriy.ryazantcev@gmail.com>
Dimitriy Ryazantcev <dimitriy.ryazantcev@gmail.com> writes:
Show 7 quoted lines
> Currenly the data rate in throughput_string(...) method is
> output by simple strbuf_humanise_bytes(...) call and '/s' append.
> But for proper translation of such string the translator needs
> full context.
>
> Add strbuf_humanise_rate(...) method to properly print out
> localizable version of data rate ('3.5 MiB/s' etc) with full context.

Hmph, so idea is that appending translation of "/s" to translation of "1.4MiB" may not be a good enough translation of "1.4MiB/s"?

That does sounds like a good idea, but looking at the heavy duplication of implementation, I would have to say "Yuck" to it.

I wonder if an approach like the following illustration would work better? I am not sure how well Q_() and N_() would interact with each other, though.

-- >8 --
struct human_format {
	const char *giga;
	const char *mega;
	const char *kilo;
	const char *byte;
	const char *bytes;
};
static void strbuf_humanise(struct strbuf *buf, off_t bytes, struct human_format *fmt)
{
	if (bytes > 1 << 30) {
		strbuf_addf(buf, _(fmt->giga), 
			    (unsigned)(bytes >> 30),
			    (unsigned)(bytes & ((1 << 30) - 1)) / 10737419);
	} else if (bytes > 1 << 20) {
		unsigned x = bytes + 5243;  /* for rounding */
		strbuf_addf(buf, _(fmt->mega),
			    x >> 20, ((x & ((1 << 20) - 1)) * 100) >> 20);
		strbuf_addstr(buf, _(""));
	} else if (bytes > 1 << 10) {
		unsigned x = bytes + 5;  /* for rounding */
		strbuf_addf(buf, _(fmt->kilo),
			    x >> 10, ((x & ((1 << 10) - 1)) * 100) >> 10);
	} else {
		strbuf_addf(buf, Q_(fmt->byte, fmt->bytes,
				    (unsigned)bytes), (unsigned)bytes);
	}
}
void strbuf_humanise_bytes(struct strbuf *buf, off_t bytes)
{
	struct human_format bytes_fmt = {
		.giga = N_("%u.%2.2u GiB"),
		.mega = N_("%u.%2.2u MiB"),
		.kilo = N_("%u.%2.2u KiB"),
		.byte = N_("%u byte"),
		.bytes = N_("%u bytes"),
	};
	strbuf_humanise(buf, bytes, &bytes_fmt);
}
void strbuf_humanise_rate(struct strbuf *buf, off_t bytes)
{
	struct human_format rate_fmt = {
		.giga = N_("%u.%2.2u GiB/s"),
		.mega = N_("%u.%2.2u MiB/s"),
		.kilo = N_("%u.%2.2u KiB/s"),
		.byte = N_("%u byte/s"),
		.bytes = N_("%u bytes/s"),
	};
	strbuf_humanise(buf, bytes, &rate_fmt);
}
Previous: Dimitriy RyazantcevNext: Dimitriy
Message 2 of 4 in “l10n: localizable upload progress messages”
  1. l10n: localizable upload progress messagesDimitriy Ryazantcev, Jun 25, 2019
  2. Junio C HamanoJun 25, 2019
  3. DimitriyJun 26, 2019
  4. Junio C HamanoJun 26, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.