{"thread":{"id":"51418","subject":"[PATCH v6] l10n: localizable upload progress messages","startedAt":"2019-07-02T18:23:13Z","lastAt":"2019-07-02T19:30:18Z","messageCount":2,"participants":["Dimitriy Ryazantcev","Junio C Hamano"],"isPatch":true,"patchVersion":6,"patchTotal":null},"messages":[{"id":"378508","messageId":"20190702182248.5322-2-dimitriy.ryazantcev@gmail.com","threadId":"51418","inReplyTo":null,"subject":"[PATCH v6] l10n: localizable upload progress messages","fromName":"Dimitriy Ryazantcev","fromEmail":"dimitriy.ryazantcev@gmail.com","sentAt":"2019-07-02T18:22:48Z","receivedAt":"2019-07-02T18:23:13Z","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   | 42 +++++++++++++++++++++++++++++++++++++-----\n strbuf.h   |  6 ++++++\n 3 files changed, 44 insertions(+), 7 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..d30f916858 100644\n--- a/strbuf.c\n+++ b/strbuf.c\n@@ -811,25 +811,57 @@ void strbuf_addstr_urlencode(struct strbuf *sb, const char *s,\n \tstrbuf_add_urlencode(sb, s, strlen(s), reserved);\n }\n \n-void strbuf_humanise_bytes(struct strbuf *buf, off_t bytes)\n+static void strbuf_humanise(struct strbuf *buf, off_t bytes,\n+\t\t\t\t int humanise_rate)\n {\n \tif (bytes > 1 << 30) {\n-\t\tstrbuf_addf(buf, \"%u.%2.2u GiB\",\n+\t\tstrbuf_addf(buf,\n+\t\t\t\thumanise_rate == 0 ?\n+\t\t\t\t\t/* TRANSLATORS: IEC 80000-13:2008 gibibyte */\n+\t\t\t\t\t_(\"%u.%2.2u GiB\") :\n+\t\t\t\t\t/* TRANSLATORS: IEC 80000-13:2008 gibibyte/second */\n+\t\t\t\t\t_(\"%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\tstrbuf_addf(buf, \"%u.%2.2u MiB\",\n+\t\tstrbuf_addf(buf,\n+\t\t\t\thumanise_rate == 0 ?\n+\t\t\t\t\t/* TRANSLATORS: IEC 80000-13:2008 mebibyte */\n+\t\t\t\t\t_(\"%u.%2.2u MiB\") :\n+\t\t\t\t\t/* TRANSLATORS: IEC 80000-13:2008 mebibyte/second */\n+\t\t\t\t\t_(\"%u.%2.2u MiB/s\"),\n \t\t\t    x >> 20, ((x & ((1 << 20) - 1)) * 100) >> 20);\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\tstrbuf_addf(buf,\n+\t\t\t\thumanise_rate == 0 ?\n+\t\t\t\t\t/* TRANSLATORS: IEC 80000-13:2008 kibibyte */\n+\t\t\t\t\t_(\"%u.%2.2u KiB\") :\n+\t\t\t\t\t/* TRANSLATORS: IEC 80000-13:2008 kibibyte/second */\n+\t\t\t\t\t_(\"%u.%2.2u KiB/s\"),\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\tstrbuf_addf(buf,\n+\t\t\t\thumanise_rate == 0 ?\n+\t\t\t\t\t/* TRANSLATORS: IEC 80000-13:2008 byte */\n+\t\t\t\t\tQ_(\"%u byte\", \"%u bytes\", (unsigned)bytes) :\n+\t\t\t\t\t/* TRANSLATORS: IEC 80000-13:2008 byte/second */\n+\t\t\t\t\tQ_(\"%u byte/s\", \"%u bytes/s\", (unsigned)bytes),\n+\t\t\t\t(unsigned)bytes);\n \t}\n }\n \n+void strbuf_humanise_bytes(struct strbuf *buf, off_t bytes)\n+{\n+\tstrbuf_humanise(buf, bytes, 0);\n+}\n+\n+void strbuf_humanise_rate(struct strbuf *buf, off_t bytes)\n+{\n+\tstrbuf_humanise(buf, bytes, 1);\n+}\n+\n void strbuf_add_absolute_path(struct strbuf *sb, const char *path)\n {\n \tif (!*path)\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":"378517","messageId":"xmqqsgro2q0q.fsf@gitster-ct.c.googlers.com","threadId":"51418","inReplyTo":"20190702182248.5322-2-dimitriy.ryazantcev@gmail.com","subject":"Re: [PATCH v6] l10n: localizable upload progress messages","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2019-07-02T19:30:13Z","receivedAt":"2019-07-02T19:30:18Z","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> -void strbuf_humanise_bytes(struct strbuf *buf, off_t bytes)\n> +static void strbuf_humanise(struct strbuf *buf, off_t bytes,\n> +\t\t\t\t int humanise_rate)\n>  {\n>  \tif (bytes > 1 << 30) {\n> -\t\tstrbuf_addf(buf, \"%u.%2.2u GiB\",\n> +\t\tstrbuf_addf(buf,\n> +\t\t\t\thumanise_rate == 0 ?\n> +\t\t\t\t\t/* TRANSLATORS: IEC 80000-13:2008 gibibyte */\n> +\t\t\t\t\t_(\"%u.%2.2u GiB\") :\n> +\t\t\t\t\t/* TRANSLATORS: IEC 80000-13:2008 gibibyte/second */\n> +\t\t\t\t\t_(\"%u.%2.2u GiB/s\"),\n>  \t\t\t    (unsigned)(bytes >> 30),\n>  \t\t\t    (unsigned)(bytes & ((1 << 30) - 1)) / 10737419);\n\nThanks.  I guess that the previous attempt to make it more table\ndriven was probably a bit overkill, and because it did not quite\nwork well for Q_(), this would probably be the \"good enough, let's\nmove on\" optimal solution ;-)\n\nWill queue.\n"}]}