l10n: localizable upload progress messages
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. Strings with the units in strbuf_humanise_bytes(...) are marked for translation. Signed-off-by: Dimitriy Ryazantcev <dimitriy.ryazantcev@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Dimitriy Ryazantcev committed
Jul 2, 2019 at 21:22 UTC
8f354a1faedba64daf5442c12cbc605441bb60b0
3 files changed
+44
-7
progress.c
+1
-2
@@ -150,8 +150,7 @@ static void throughput_string(struct strbuf *buf, uint64_t total,
150
strbuf_addstr(buf, ", ");
151
strbuf_humanise_bytes(buf, total);
152
strbuf_addstr(buf, " | ");
153
- strbuf_humanise_bytes(buf, rate * 1024);
154
- strbuf_addstr(buf, "/s");
153
+ strbuf_humanise_rate(buf, rate * 1024);
154
}
155
156
void display_throughput(struct progress *progress, uint64_t total)
strbuf.c
+37
-5
@@ -811,25 +811,57 @@ void strbuf_addstr_urlencode(struct strbuf *sb, const char *s,
811
strbuf_add_urlencode(sb, s, strlen(s), reserved);
812
}
813
814
-void strbuf_humanise_bytes(struct strbuf *buf, off_t bytes)
814
+static void strbuf_humanise(struct strbuf *buf, off_t bytes,
815
+ int humanise_rate)
816
{
817
if (bytes > 1 << 30) {
817
- strbuf_addf(buf, "%u.%2.2u GiB",
818
+ strbuf_addf(buf,
819
+ humanise_rate == 0 ?
820
+ /* TRANSLATORS: IEC 80000-13:2008 gibibyte */
821
+ _("%u.%2.2u GiB") :
822
+ /* TRANSLATORS: IEC 80000-13:2008 gibibyte/second */
823
+ _("%u.%2.2u GiB/s"),
824
(unsigned)(bytes >> 30),
825
(unsigned)(bytes & ((1 << 30) - 1)) / 10737419);
826
} else if (bytes > 1 << 20) {
827
unsigned x = bytes + 5243; /* for rounding */
822
- strbuf_addf(buf, "%u.%2.2u MiB",
828
+ strbuf_addf(buf,
829
+ humanise_rate == 0 ?
830
+ /* TRANSLATORS: IEC 80000-13:2008 mebibyte */
831
+ _("%u.%2.2u MiB") :
832
+ /* TRANSLATORS: IEC 80000-13:2008 mebibyte/second */
833
+ _("%u.%2.2u MiB/s"),
834
x >> 20, ((x & ((1 << 20) - 1)) * 100) >> 20);
835
} else if (bytes > 1 << 10) {
836
unsigned x = bytes + 5; /* for rounding */
826
- strbuf_addf(buf, "%u.%2.2u KiB",
837
+ strbuf_addf(buf,
838
+ humanise_rate == 0 ?
839
+ /* TRANSLATORS: IEC 80000-13:2008 kibibyte */
840
+ _("%u.%2.2u KiB") :
841
+ /* TRANSLATORS: IEC 80000-13:2008 kibibyte/second */
842
+ _("%u.%2.2u KiB/s"),
843
x >> 10, ((x & ((1 << 10) - 1)) * 100) >> 10);
844
} else {
829
- strbuf_addf(buf, "%u bytes", (unsigned)bytes);
845
+ strbuf_addf(buf,
846
+ humanise_rate == 0 ?
847
+ /* TRANSLATORS: IEC 80000-13:2008 byte */
848
+ Q_("%u byte", "%u bytes", (unsigned)bytes) :
849
+ /* TRANSLATORS: IEC 80000-13:2008 byte/second */
850
+ Q_("%u byte/s", "%u bytes/s", (unsigned)bytes),
851
+ (unsigned)bytes);
852
}
853
}
854
855
+void strbuf_humanise_bytes(struct strbuf *buf, off_t bytes)
856
+{
857
+ strbuf_humanise(buf, bytes, 0);
858
+}
859
+
860
+void strbuf_humanise_rate(struct strbuf *buf, off_t bytes)
861
+{
862
+ strbuf_humanise(buf, bytes, 1);
863
+}
864
+
865
void strbuf_add_absolute_path(struct strbuf *sb, const char *path)
866
{
867
if (!*path)
strbuf.h
+6
@@ -372,6 +372,12 @@ void strbuf_addbuf_percentquote(struct strbuf *dst, const struct strbuf *src);
372
*/
373
void strbuf_humanise_bytes(struct strbuf *buf, off_t bytes);
374
375
+/**
376
+ * Append the given byte rate as a human-readable string (i.e. 12.23 KiB/s,
377
+ * 3.50 MiB/s).
378
+ */
379
+void strbuf_humanise_rate(struct strbuf *buf, off_t bytes);
380
+
381
/**
382
* Add a formatted string to the buffer.
383
*/