From: Junio C Hamano <gitster@pobox.com>
To: Dimitriy Ryazantcev <dimitriy.ryazantcev@gmail.com>
Cc: git@vger.kernel.org, "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>,
"Jeff King" <peff@peff.net>,
"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Subject: Re: [PATCH v5] l10n: localizable upload progress messages
Date: Tue, 25 Jun 2019 13:00:50 -0700 [thread overview]
Message-ID: <xmqqzhm5e8p9.fsf@gitster-ct.c.googlers.com> (raw)
In-Reply-To: <20190625062540.88973-2-dimitriy.ryazantcev@gmail.com> (Dimitriy Ryazantcev's message of "Tue, 25 Jun 2019 09:25:40 +0300")
Dimitriy Ryazantcev <dimitriy.ryazantcev@gmail.com> 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);
}
next prev parent reply other threads:[~2019-06-25 20:01 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-25 6:25 [PATCH v5] l10n: localizable upload progress messages Dimitriy Ryazantcev
2019-06-25 20:00 ` Junio C Hamano [this message]
2019-06-26 8:59 ` Dimitriy
2019-06-26 17:58 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqqzhm5e8p9.fsf@gitster-ct.c.googlers.com \
--to=gitster@pobox.com \
--cc=avarab@gmail.com \
--cc=dimitriy.ryazantcev@gmail.com \
--cc=git@vger.kernel.org \
--cc=pclouds@gmail.com \
--cc=peff@peff.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).