{"thread":{"id":"51376","subject":"[PATCH v5] l10n: localizable upload progress messages","startedAt":"2019-06-25T06:26:41Z","lastAt":"2019-06-26T17:58:44Z","messageCount":4,"participants":["Dimitriy Ryazantcev","Junio C Hamano","Dimitriy"],"isPatch":true,"patchVersion":5,"patchTotal":null},"messages":[{"id":"377941","messageId":"20190625062540.88973-2-dimitriy.ryazantcev@gmail.com","threadId":"51376","inReplyTo":null,"subject":"[PATCH v5] l10n: localizable upload progress messages","fromName":"Dimitriy Ryazantcev","fromEmail":"dimitriy.ryazantcev@gmail.com","sentAt":"2019-06-25T06:25:40Z","receivedAt":"2019-06-25T06:26:41Z","isPatch":true,"sender":{"key":"dimitriy.ryazantcev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1285934?v=4"},"body":"Currenly the data rate in throughput_string(...) method is\noutput by simple strbuf_humanise_bytes(...) call and '/s' append.\nBut for proper translation of such string the translator needs\nfull context.\n\nAdd strbuf_humanise_rate(...) method to properly print out\nlocalizable version of data rate ('3.5 MiB/s' etc) with full context.\n\nStrings with the units in strbuf_humanise_bytes(...) are marked\nfor translation.\n\nSigned-off-by: Dimitriy Ryazantcev <dimitriy.ryazantcev@gmail.com>\n---\n progress.c |  3 +--\n strbuf.c   | 37 +++++++++++++++++++++++++++++++++----\n strbuf.h   |  6 ++++++\n 3 files changed, 40 insertions(+), 6 deletions(-)\n\ndiff --git a/progress.c b/progress.c\nindex a2e8cf64a8..951f7c7461 100644\n--- a/progress.c\n+++ b/progress.c\n@@ -150,8 +150,7 @@ static void throughput_string(struct strbuf *buf, uint64_t total,\n \tstrbuf_addstr(buf, \", \");\n \tstrbuf_humanise_bytes(buf, total);\n \tstrbuf_addstr(buf, \" | \");\n-\tstrbuf_humanise_bytes(buf, rate * 1024);\n-\tstrbuf_addstr(buf, \"/s\");\n+\tstrbuf_humanise_rate(buf, rate * 1024);\n }\n \n void display_throughput(struct progress *progress, uint64_t total)\ndiff --git a/strbuf.c b/strbuf.c\nindex 0e18b259ce..785c9e5b55 100644\n--- a/strbuf.c\n+++ b/strbuf.c\n@@ -814,19 +814,48 @@ void strbuf_addstr_urlencode(struct strbuf *sb, const char *s,\n void strbuf_humanise_bytes(struct strbuf *buf, off_t bytes)\n {\n \tif (bytes > 1 << 30) {\n-\t\tstrbuf_addf(buf, \"%u.%2.2u GiB\",\n+\t\t/* TRANSLATORS: IEC 80000-13:2008 gibibyte */\n+\t\tstrbuf_addf(buf, _(\"%u.%2.2u GiB\"),\n \t\t\t    (unsigned)(bytes >> 30),\n \t\t\t    (unsigned)(bytes & ((1 << 30) - 1)) / 10737419);\n \t} else if (bytes > 1 << 20) {\n \t\tunsigned x = bytes + 5243;  /* for rounding */\n-\t\tstrbuf_addf(buf, \"%u.%2.2u MiB\",\n+\t\t/* TRANSLATORS: IEC 80000-13:2008 mebibyte */\n+\t\tstrbuf_addf(buf, _(\"%u.%2.2u MiB\"),\n \t\t\t    x >> 20, ((x & ((1 << 20) - 1)) * 100) >> 20);\n+\t\tstrbuf_addstr(buf, _(\"\"));\n \t} else if (bytes > 1 << 10) {\n \t\tunsigned x = bytes + 5;  /* for rounding */\n-\t\tstrbuf_addf(buf, \"%u.%2.2u KiB\",\n+\t\t/* TRANSLATORS: IEC 80000-13:2008 kibibyte */\n+\t\tstrbuf_addf(buf, _(\"%u.%2.2u KiB\"),\n \t\t\t    x >> 10, ((x & ((1 << 10) - 1)) * 100) >> 10);\n \t} else {\n-\t\tstrbuf_addf(buf, \"%u bytes\", (unsigned)bytes);\n+\t\t/* TRANSLATORS: IEC 80000-13:2008 byte */\n+\t\tstrbuf_addf(buf, Q_(\"%u byte\", \"%u bytes\", (unsigned)bytes), (unsigned)bytes);\n+\t}\n+}\n+\n+void strbuf_humanise_rate(struct strbuf *buf, off_t bytes)\n+{\n+\tif (bytes > 1 << 30) {\n+\t\t/* TRANSLATORS: IEC 80000-13:2008 gibibyte/second */\n+\t\tstrbuf_addf(buf, _(\"%u.%2.2u GiB/s\"),\n+\t\t\t    (unsigned)(bytes >> 30),\n+\t\t\t    (unsigned)(bytes & ((1 << 30) - 1)) / 10737419);\n+\t} else if (bytes > 1 << 20) {\n+\t\tunsigned x = bytes + 5243;  /* for rounding */\n+\t\t/* TRANSLATORS: IEC 80000-13:2008 mebibyte/second */\n+\t\tstrbuf_addf(buf, _(\"%u.%2.2u MiB/s\"),\n+\t\t\t    x >> 20, ((x & ((1 << 20) - 1)) * 100) >> 20);\n+\t\tstrbuf_addstr(buf, _(\"\"));\n+\t} else if (bytes > 1 << 10) {\n+\t\tunsigned x = bytes + 5;  /* for rounding */\n+\t\t/* TRANSLATORS: IEC 80000-13:2008 kibibyte/second */\n+\t\tstrbuf_addf(buf, _(\"%u.%2.2u KiB/s\"),\n+\t\t\t    x >> 10, ((x & ((1 << 10) - 1)) * 100) >> 10);\n+\t} else {\n+\t\t/* TRANSLATORS: IEC 80000-13:2008 byte/second */\n+\t\tstrbuf_addf(buf, Q_(\"%u byte/s\", \"%u bytes/s\", (unsigned)bytes), (unsigned)bytes);\n \t}\n }\n \ndiff --git a/strbuf.h b/strbuf.h\nindex c8d98dfb95..f62278a0be 100644\n--- a/strbuf.h\n+++ b/strbuf.h\n@@ -372,6 +372,12 @@ void strbuf_addbuf_percentquote(struct strbuf *dst, const struct strbuf *src);\n  */\n void strbuf_humanise_bytes(struct strbuf *buf, off_t bytes);\n \n+/**\n+ * Append the given byte rate as a human-readable string (i.e. 12.23 KiB/s,\n+ * 3.50 MiB/s).\n+ */\n+void strbuf_humanise_rate(struct strbuf *buf, off_t bytes);\n+\n /**\n  * Add a formatted string to the buffer.\n  */\n-- \n2.22.0\n\n"},{"id":"378039","messageId":"xmqqzhm5e8p9.fsf@gitster-ct.c.googlers.com","threadId":"51376","inReplyTo":"20190625062540.88973-2-dimitriy.ryazantcev@gmail.com","subject":"Re: [PATCH v5] l10n: localizable upload progress messages","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2019-06-25T20:00:50Z","receivedAt":"2019-06-25T20:01:01Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Dimitriy Ryazantcev <dimitriy.ryazantcev@gmail.com> writes:\n\n> Currenly the data rate in throughput_string(...) method is\n> output by simple strbuf_humanise_bytes(...) call and '/s' append.\n> But for proper translation of such string the translator needs\n> full context.\n>\n> Add strbuf_humanise_rate(...) method to properly print out\n> localizable version of data rate ('3.5 MiB/s' etc) with full context.\n\nHmph, so idea is that appending translation of \"/s\" to translation\nof \"1.4MiB\" may not be a good enough translation of \"1.4MiB/s\"?\n\nThat does sounds like a good idea, but looking at the heavy\nduplication of implementation, I would have to say \"Yuck\" to it.\n\nI wonder if an approach like the following illustration would work\nbetter?  I am not sure how well Q_() and N_() would interact with\neach other, though.\n\n-- >8 --\n\nstruct human_format {\n\tconst char *giga;\n\tconst char *mega;\n\tconst char *kilo;\n\tconst char *byte;\n\tconst char *bytes;\n};\n\nstatic void strbuf_humanise(struct strbuf *buf, off_t bytes, struct human_format *fmt)\n{\n\tif (bytes > 1 << 30) {\n\t\tstrbuf_addf(buf, _(fmt->giga), \n\t\t\t    (unsigned)(bytes >> 30),\n\t\t\t    (unsigned)(bytes & ((1 << 30) - 1)) / 10737419);\n\t} else if (bytes > 1 << 20) {\n\t\tunsigned x = bytes + 5243;  /* for rounding */\n\t\tstrbuf_addf(buf, _(fmt->mega),\n\t\t\t    x >> 20, ((x & ((1 << 20) - 1)) * 100) >> 20);\n\t\tstrbuf_addstr(buf, _(\"\"));\n\t} else if (bytes > 1 << 10) {\n\t\tunsigned x = bytes + 5;  /* for rounding */\n\t\tstrbuf_addf(buf, _(fmt->kilo),\n\t\t\t    x >> 10, ((x & ((1 << 10) - 1)) * 100) >> 10);\n\t} else {\n\t\tstrbuf_addf(buf, Q_(fmt->byte, fmt->bytes,\n\t\t\t\t    (unsigned)bytes), (unsigned)bytes);\n\t}\n}\n\nvoid strbuf_humanise_bytes(struct strbuf *buf, off_t bytes)\n{\n\tstruct human_format bytes_fmt = {\n\t\t.giga = N_(\"%u.%2.2u GiB\"),\n\t\t.mega = N_(\"%u.%2.2u MiB\"),\n\t\t.kilo = N_(\"%u.%2.2u KiB\"),\n\t\t.byte = N_(\"%u byte\"),\n\t\t.bytes = N_(\"%u bytes\"),\n\t};\n\tstrbuf_humanise(buf, bytes, &bytes_fmt);\n}\n\nvoid strbuf_humanise_rate(struct strbuf *buf, off_t bytes)\n{\n\tstruct human_format rate_fmt = {\n\t\t.giga = N_(\"%u.%2.2u GiB/s\"),\n\t\t.mega = N_(\"%u.%2.2u MiB/s\"),\n\t\t.kilo = N_(\"%u.%2.2u KiB/s\"),\n\t\t.byte = N_(\"%u byte/s\"),\n\t\t.bytes = N_(\"%u bytes/s\"),\n\t};\n\tstrbuf_humanise(buf, bytes, &rate_fmt);\n}\n"},{"id":"378058","messageId":"CAPUT4mR7B1nS8x=S0UW6PQmw0XjjxvJ8nxsXz2n77fodBPaurw@mail.gmail.com","threadId":"51376","inReplyTo":"xmqqzhm5e8p9.fsf@gitster-ct.c.googlers.com","subject":"Re: [PATCH v5] l10n: localizable upload progress messages","fromName":"Dimitriy","fromEmail":"dimitriy.ryazantcev@gmail.com","sentAt":"2019-06-26T08:59:06Z","receivedAt":"2019-06-26T08:59:19Z","isPatch":true,"sender":{"key":"dimitriy.ryazantcev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1285934?v=4"},"body":"Junio C Hamano <gitster@pobox.com> writes:\n>\n> Dimitriy Ryazantcev <dimitriy.ryazantcev@gmail.com> writes:\n>\n> > Currenly the data rate in throughput_string(...) method is\n> > output by simple strbuf_humanise_bytes(...) call and '/s' append.\n> > But for proper translation of such string the translator needs\n> > full context.\n> >\n> > Add strbuf_humanise_rate(...) method to properly print out\n> > localizable version of data rate ('3.5 MiB/s' etc) with full context.\n>\n> Hmph, so idea is that appending translation of \"/s\" to translation\n> of \"1.4MiB\" may not be a good enough translation of \"1.4MiB/s\"?\n>\n> That does sounds like a good idea, but looking at the heavy\n> duplication of implementation, I would have to say \"Yuck\" to it.\n>\n> I wonder if an approach like the following illustration would work\n> better?  I am not sure how well Q_() and N_() would interact with\n> each other, though.\n\nGood idea!\nBut unfortunately this will not work properly as xgettext will unable\nto extract byte/bytes to one plural msgid in *.pot file.\nSeems it can extract plural forms only from Q_ (ngettext() call) and\ncannot from _N (gettext_noop() call) in current configuration[0].\nMaybe in this case we can try to forward already translated string\nto strbuf_humanise():\n\nstatic void strbuf_humanise(struct strbuf *buf, off_t bytes, struct\nhuman_format *fmt)\n{\n....\n        } else {\n                strbuf_addf(buf, fmt->byte, (unsigned)bytes);\n....\n}\n\nvoid strbuf_humanise_bytes(struct strbuf *buf, off_t bytes)\n{\n        struct human_format bytes_fmt = {\n                .giga = _(\"%u.%2.2u GiB\"),\n                .mega = _(\"%u.%2.2u MiB\"),\n                .kilo = _(\"%u.%2.2u KiB\"),\n                .byte = Q_(\"%u byte\", \"%u bytes\", (unsigned)bytes),\n        };\n        strbuf_humanise(buf, bytes, &bytes_fmt);\n}\n\nWhat do you think?\n\n[0] https://github.com/git/git/blob/master/Makefile#L2498\n\n\n>\n> -- >8 --\n>\n> struct human_format {\n>         const char *giga;\n>         const char *mega;\n>         const char *kilo;\n>         const char *byte;\n>         const char *bytes;\n> };\n>\n> static void strbuf_humanise(struct strbuf *buf, off_t bytes, struct human_format *fmt)\n> {\n>         if (bytes > 1 << 30) {\n>                 strbuf_addf(buf, _(fmt->giga),\n>                             (unsigned)(bytes >> 30),\n>                             (unsigned)(bytes & ((1 << 30) - 1)) / 10737419);\n>         } else if (bytes > 1 << 20) {\n>                 unsigned x = bytes + 5243;  /* for rounding */\n>                 strbuf_addf(buf, _(fmt->mega),\n>                             x >> 20, ((x & ((1 << 20) - 1)) * 100) >> 20);\n>                 strbuf_addstr(buf, _(\"\"));\n>         } else if (bytes > 1 << 10) {\n>                 unsigned x = bytes + 5;  /* for rounding */\n>                 strbuf_addf(buf, _(fmt->kilo),\n>                             x >> 10, ((x & ((1 << 10) - 1)) * 100) >> 10);\n>         } else {\n>                 strbuf_addf(buf, Q_(fmt->byte, fmt->bytes,\n>                                     (unsigned)bytes), (unsigned)bytes);\n>         }\n> }\n>\n> void strbuf_humanise_bytes(struct strbuf *buf, off_t bytes)\n> {\n>         struct human_format bytes_fmt = {\n>                 .giga = N_(\"%u.%2.2u GiB\"),\n>                 .mega = N_(\"%u.%2.2u MiB\"),\n>                 .kilo = N_(\"%u.%2.2u KiB\"),\n>                 .byte = N_(\"%u byte\"),\n>                 .bytes = N_(\"%u bytes\"),\n>         };\n>         strbuf_humanise(buf, bytes, &bytes_fmt);\n> }\n>\n> void strbuf_humanise_rate(struct strbuf *buf, off_t bytes)\n> {\n>         struct human_format rate_fmt = {\n>                 .giga = N_(\"%u.%2.2u GiB/s\"),\n>                 .mega = N_(\"%u.%2.2u MiB/s\"),\n>                 .kilo = N_(\"%u.%2.2u KiB/s\"),\n>                 .byte = N_(\"%u byte/s\"),\n>                 .bytes = N_(\"%u bytes/s\"),\n>         };\n>         strbuf_humanise(buf, bytes, &rate_fmt);\n> }\n\n\n\n--\nSincerely,\nDimitriy Ryazantcev\n"},{"id":"378071","messageId":"xmqq1rzgdy9g.fsf@gitster-ct.c.googlers.com","threadId":"51376","inReplyTo":"CAPUT4mR7B1nS8x=S0UW6PQmw0XjjxvJ8nxsXz2n77fodBPaurw@mail.gmail.com","subject":"Re: [PATCH v5] l10n: localizable upload progress messages","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2019-06-26T17:58:35Z","receivedAt":"2019-06-26T17:58:44Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Dimitriy <dimitriy.ryazantcev@gmail.com> writes:\n\n> Seems it can extract plural forms only from Q_ (ngettext() call) and\n> cannot from _N (gettext_noop() call) in current configuration[0].\n> Maybe in this case we can try to forward already translated string\n> to strbuf_humanise():\n>\n> static void strbuf_humanise(struct strbuf *buf, off_t bytes, struct\n> human_format *fmt)\n> {\n> ....\n>         } else {\n>                 strbuf_addf(buf, fmt->byte, (unsigned)bytes);\n> ....\n> }\n>\n> void strbuf_humanise_bytes(struct strbuf *buf, off_t bytes)\n> {\n>         struct human_format bytes_fmt = {\n>                 .giga = _(\"%u.%2.2u GiB\"),\n>                 .mega = _(\"%u.%2.2u MiB\"),\n>                 .kilo = _(\"%u.%2.2u KiB\"),\n>                 .byte = Q_(\"%u byte\", \"%u bytes\", (unsigned)bytes),\n>         };\n>         strbuf_humanise(buf, bytes, &bytes_fmt);\n> }\n>\n> What do you think?\n\nWell, I was trying to avoid making Q_() call when we did not have\nto, but if we are running with gettext, we cannot avoid calling Q_()\nevery time this helper is called, as .byte field has to depend on\nthe value of bytes, so...\n\n\n"}]}