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

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

 



Junio C Hamano <gitster@xxxxxxxxx> writes:
>
> 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.

Good idea!
But unfortunately this will not work properly as xgettext will unable
to extract byte/bytes to one plural msgid in *.pot file.
Seems it can extract plural forms only from Q_ (ngettext() call) and
cannot from _N (gettext_noop() call) in current configuration[0].
Maybe in this case we can try to forward already translated string
to strbuf_humanise():

static void strbuf_humanise(struct strbuf *buf, off_t bytes, struct
human_format *fmt)
{
....
        } else {
                strbuf_addf(buf, fmt->byte, (unsigned)bytes);
....
}

void strbuf_humanise_bytes(struct strbuf *buf, off_t bytes)
{
        struct human_format bytes_fmt = {
                .giga = _("%u.%2.2u GiB"),
                .mega = _("%u.%2.2u MiB"),
                .kilo = _("%u.%2.2u KiB"),
                .byte = Q_("%u byte", "%u bytes", (unsigned)bytes),
        };
        strbuf_humanise(buf, bytes, &bytes_fmt);
}

What do you think?

[0] https://github.com/git/git/blob/master/Makefile#L2498


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



--
Sincerely,
Dimitriy Ryazantcev



[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