Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 3b3f093

Browse files
committed
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.
1 parent 005e5c3 commit 3b3f093

File tree

1 file changed

+23
-11
lines changed

1 file changed

+23
-11
lines changed

src/bin/pg_basebackup/pg_basebackup.c

+23-11
Original file line numberDiff line numberDiff line change
@@ -204,10 +204,20 @@ static void
204204
progress_report(int tablespacenum, const char *filename)
205205
{
206206
int percent = (int) ((totaldone / 1024) * 100 / totalsize);
207+
char totaldone_str[32];
208+
char totalsize_str[32];
207209

208210
if (percent > 100)
209211
percent = 100;
210212

213+
/*
214+
* Separate step to keep platform-dependent format code out of translatable
215+
* strings. And we only test for INT64_FORMAT availability in snprintf,
216+
* not fprintf.
217+
*/
218+
snprintf(totaldone_str, sizeof(totaldone_str), INT64_FORMAT, totaldone / 1024);
219+
snprintf(totalsize_str, sizeof(totalsize_str), INT64_FORMAT, totalsize);
220+
211221
if (verbose)
212222
{
213223
if (!filename)
@@ -217,21 +227,23 @@ progress_report(int tablespacenum, const char *filename)
217227
* call)
218228
*/
219229
fprintf(stderr,
220-
INT64_FORMAT "/" INT64_FORMAT " kB (100%%) %d/%d tablespaces %35s\r",
221-
totaldone / 1024, totalsize,
222-
tablespacenum, tablespacecount, "");
230+
ngettext("%s/%s kB (100%%), %d/%d tablespace %35s\r",
231+
"%s/%s kB (100%%), %d/%d tablespaces %35s\r",
232+
tablespacecount),
233+
totaldone_str, totalsize_str, tablespacenum, tablespacecount, "");
223234
else
224235
fprintf(stderr,
225-
INT64_FORMAT "/" INT64_FORMAT " kB (%d%%) %d/%d tablespaces (%-30.30s)\r",
226-
totaldone / 1024, totalsize,
227-
percent,
228-
tablespacenum, tablespacecount, filename);
236+
ngettext("%s/%s kB (%d%%), %d/%d tablespace (%-30.30s)\r",
237+
"%s/%s kB (%d%%), %d/%d tablespaces (%-30.30s)\r",
238+
tablespacecount),
239+
totaldone_str, totalsize_str, percent, tablespacenum, tablespacecount, filename);
229240
}
230241
else
231-
fprintf(stderr, INT64_FORMAT "/" INT64_FORMAT " kB (%d%%) %d/%d tablespaces\r",
232-
totaldone / 1024, totalsize,
233-
percent,
234-
tablespacenum, tablespacecount);
242+
fprintf(stderr,
243+
ngettext("%s/%s kB (%d%%), %d/%d tablespace\r",
244+
"%s/%s kB (%d%%), %d/%d tablespaces\r",
245+
tablespacecount),
246+
totaldone_str, totalsize_str, percent, tablespacenum, tablespacecount);
235247
}
236248

237249

0 commit comments

Comments
 (0)