Skip to content

Commit ff2ea39

Browse files
committed
Merge branch 'dr/progress-i18n'
Progress messages have been made localizable. * dr/progress-i18n: l10n: localizable upload progress messages
2 parents 4ad01a4 + 8f354a1 commit ff2ea39

File tree

3 files changed

+44
-7
lines changed

3 files changed

+44
-7
lines changed

progress.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,7 @@ static void throughput_string(struct strbuf *buf, uint64_t total,
144144
strbuf_addstr(buf, ", ");
145145
strbuf_humanise_bytes(buf, total);
146146
strbuf_addstr(buf, " | ");
147-
strbuf_humanise_bytes(buf, rate * 1024);
148-
strbuf_addstr(buf, "/s");
147+
strbuf_humanise_rate(buf, rate * 1024);
149148
}
150149

151150
void display_throughput(struct progress *progress, uint64_t total)

strbuf.c

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -811,25 +811,57 @@ void strbuf_addstr_urlencode(struct strbuf *sb, const char *s,
811811
strbuf_add_urlencode(sb, s, strlen(s), reserved);
812812
}
813813

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)
815816
{
816817
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"),
818824
(unsigned)(bytes >> 30),
819825
(unsigned)(bytes & ((1 << 30) - 1)) / 10737419);
820826
} else if (bytes > 1 << 20) {
821827
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"),
823834
x >> 20, ((x & ((1 << 20) - 1)) * 100) >> 20);
824835
} else if (bytes > 1 << 10) {
825836
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"),
827843
x >> 10, ((x & ((1 << 10) - 1)) * 100) >> 10);
828844
} 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);
830852
}
831853
}
832854

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+
833865
void strbuf_add_absolute_path(struct strbuf *sb, const char *path)
834866
{
835867
if (!*path)

strbuf.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,12 @@ void strbuf_addbuf_percentquote(struct strbuf *dst, const struct strbuf *src);
372372
*/
373373
void strbuf_humanise_bytes(struct strbuf *buf, off_t bytes);
374374

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+
375381
/**
376382
* Add a formatted string to the buffer.
377383
*/

0 commit comments

Comments
 (0)