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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Dimitriy Ryazantcev <dimitriy.ryazantcev@xxxxxxxxx> writes:

> 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);
}



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux