Commit 3b3f0935 authored by Peter Eisentraut's avatar Peter Eisentraut

Make pg_basebackup progress report translatable

Also fix a potential portability bug, because INT64_FORMAT is only
guaranteed to be available with snprintf, not fprintf.
parent 005e5c30
...@@ -204,10 +204,20 @@ static void ...@@ -204,10 +204,20 @@ static void
progress_report(int tablespacenum, const char *filename) progress_report(int tablespacenum, const char *filename)
{ {
int percent = (int) ((totaldone / 1024) * 100 / totalsize); int percent = (int) ((totaldone / 1024) * 100 / totalsize);
char totaldone_str[32];
char totalsize_str[32];
if (percent > 100) if (percent > 100)
percent = 100; percent = 100;
/*
* Separate step to keep platform-dependent format code out of translatable
* strings. And we only test for INT64_FORMAT availability in snprintf,
* not fprintf.
*/
snprintf(totaldone_str, sizeof(totaldone_str), INT64_FORMAT, totaldone / 1024);
snprintf(totalsize_str, sizeof(totalsize_str), INT64_FORMAT, totalsize);
if (verbose) if (verbose)
{ {
if (!filename) if (!filename)
...@@ -217,21 +227,23 @@ progress_report(int tablespacenum, const char *filename) ...@@ -217,21 +227,23 @@ progress_report(int tablespacenum, const char *filename)
* call) * call)
*/ */
fprintf(stderr, fprintf(stderr,
INT64_FORMAT "/" INT64_FORMAT " kB (100%%) %d/%d tablespaces %35s\r", ngettext("%s/%s kB (100%%), %d/%d tablespace %35s\r",
totaldone / 1024, totalsize, "%s/%s kB (100%%), %d/%d tablespaces %35s\r",
tablespacenum, tablespacecount, ""); tablespacecount),
totaldone_str, totalsize_str, tablespacenum, tablespacecount, "");
else else
fprintf(stderr, fprintf(stderr,
INT64_FORMAT "/" INT64_FORMAT " kB (%d%%) %d/%d tablespaces (%-30.30s)\r", ngettext("%s/%s kB (%d%%), %d/%d tablespace (%-30.30s)\r",
totaldone / 1024, totalsize, "%s/%s kB (%d%%), %d/%d tablespaces (%-30.30s)\r",
percent, tablespacecount),
tablespacenum, tablespacecount, filename); totaldone_str, totalsize_str, percent, tablespacenum, tablespacecount, filename);
} }
else else
fprintf(stderr, INT64_FORMAT "/" INT64_FORMAT " kB (%d%%) %d/%d tablespaces\r", fprintf(stderr,
totaldone / 1024, totalsize, ngettext("%s/%s kB (%d%%), %d/%d tablespace\r",
percent, "%s/%s kB (%d%%), %d/%d tablespaces\r",
tablespacenum, tablespacecount); tablespacecount),
totaldone_str, totalsize_str, percent, tablespacenum, tablespacecount);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment