>From 6d6c6c51251893bcbfc72edc6002580278b59c5b Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter_e@gmx.net>
Date: Sat, 15 Oct 2016 12:00:00 -0400
Subject: [PATCH 5/7] pg_xlogdump: Add NLS

---
 src/bin/pg_xlogdump/nls.mk        |  6 ++++
 src/bin/pg_xlogdump/pg_xlogdump.c | 75 ++++++++++++++++++++-------------------
 2 files changed, 44 insertions(+), 37 deletions(-)
 create mode 100644 src/bin/pg_xlogdump/nls.mk

diff --git a/src/bin/pg_xlogdump/nls.mk b/src/bin/pg_xlogdump/nls.mk
new file mode 100644
index 0000000..2b254c3
--- /dev/null
+++ b/src/bin/pg_xlogdump/nls.mk
@@ -0,0 +1,6 @@
+# src/bin/pg_xlogdump/nls.mk
+CATALOG_NAME     = pg_xlogdump
+AVAIL_LANGUAGES  =
+GETTEXT_FILES    = pg_xlogdump.c
+GETTEXT_TRIGGERS = fatal_error
+GETTEXT_FLAGS    = fatal_error:1:c-format
diff --git a/src/bin/pg_xlogdump/pg_xlogdump.c b/src/bin/pg_xlogdump/pg_xlogdump.c
index 7490398..d070312 100644
--- a/src/bin/pg_xlogdump/pg_xlogdump.c
+++ b/src/bin/pg_xlogdump/pg_xlogdump.c
@@ -79,9 +79,9 @@ fatal_error(const char *fmt,...)
 
 	fflush(stdout);
 
-	fprintf(stderr, "%s: FATAL:  ", progname);
+	fprintf(stderr, _("%s: FATAL:  "), progname);
 	va_start(args, fmt);
-	vfprintf(stderr, fmt, args);
+	vfprintf(stderr, _(fmt), args);
 	va_end(args);
 	fputc('\n', stderr);
 
@@ -670,27 +670,27 @@ XLogDumpDisplayStats(XLogDumpConfig *config, XLogDumpStats *stats)
 static void
 usage(void)
 {
-	printf("%s decodes and displays PostgreSQL transaction logs for debugging.\n\n",
+	printf(_("%s decodes and displays PostgreSQL transaction logs for debugging.\n\n"),
 		   progname);
-	printf("Usage:\n");
-	printf("  %s [OPTION]... [STARTSEG [ENDSEG]] \n", progname);
-	printf("\nOptions:\n");
-	printf("  -b, --bkp-details      output detailed information about backup blocks\n");
-	printf("  -e, --end=RECPTR       stop reading at log position RECPTR\n");
-	printf("  -f, --follow           keep retrying after reaching end of WAL\n");
-	printf("  -n, --limit=N          number of records to display\n");
-	printf("  -p, --path=PATH        directory in which to find log segment files\n");
-	printf("                         (default: ./pg_wal)\n");
-	printf("  -r, --rmgr=RMGR        only show records generated by resource manager RMGR\n");
-	printf("                         use --rmgr=list to list valid resource manager names\n");
-	printf("  -s, --start=RECPTR     start reading at log position RECPTR\n");
-	printf("  -t, --timeline=TLI     timeline from which to read log records\n");
-	printf("                         (default: 1 or the value used in STARTSEG)\n");
-	printf("  -V, --version          output version information, then exit\n");
-	printf("  -x, --xid=XID          only show records with TransactionId XID\n");
-	printf("  -z, --stats[=record]   show statistics instead of records\n");
-	printf("                         (optionally, show per-record statistics)\n");
-	printf("  -?, --help             show this help, then exit\n");
+	printf(_("Usage:\n"));
+	printf(_("  %s [OPTION]... [STARTSEG [ENDSEG]] \n"), progname);
+	printf(_("\nOptions:\n"));
+	printf(_("  -b, --bkp-details      output detailed information about backup blocks\n"));
+	printf(_("  -e, --end=RECPTR       stop reading at log position RECPTR\n"));
+	printf(_("  -f, --follow           keep retrying after reaching end of WAL\n"));
+	printf(_("  -n, --limit=N          number of records to display\n"));
+	printf(_("  -p, --path=PATH        directory in which to find log segment files\n"
+			 "                         (default: ./pg_wal)\n"));
+	printf(_("  -r, --rmgr=RMGR        only show records generated by resource manager RMGR\n"
+			 "                         use --rmgr=list to list valid resource manager names\n"));
+	printf(_("  -s, --start=RECPTR     start reading at log position RECPTR\n"));
+	printf(_("  -t, --timeline=TLI     timeline from which to read log records\n"
+			 "                         (default: 1 or the value used in STARTSEG)\n"));
+	printf(_("  -V, --version          output version information, then exit\n"));
+	printf(_("  -x, --xid=XID          only show records with TransactionId XID\n"));
+	printf(_("  -z, --stats[=record]   show statistics instead of records\n"
+			 "                         (optionally, show per-record statistics)\n"));
+	printf(_("  -?, --help             show this help, then exit\n"));
 }
 
 int
@@ -725,6 +725,7 @@ main(int argc, char **argv)
 	int			option;
 	int			optindex = 0;
 
+	set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pg_xlogdump"));
 	progname = get_progname(argv[0]);
 
 	memset(&private, 0, sizeof(XLogDumpPrivate));
@@ -748,7 +749,7 @@ main(int argc, char **argv)
 
 	if (argc <= 1)
 	{
-		fprintf(stderr, "%s: no arguments specified\n", progname);
+		fprintf(stderr, _("%s: no arguments specified\n"), progname);
 		goto bad_argument;
 	}
 
@@ -763,7 +764,7 @@ main(int argc, char **argv)
 			case 'e':
 				if (sscanf(optarg, "%X/%X", &xlogid, &xrecoff) != 2)
 				{
-					fprintf(stderr, "%s: could not parse end log position \"%s\"\n",
+					fprintf(stderr, _("%s: could not parse end log position \"%s\"\n"),
 							progname, optarg);
 					goto bad_argument;
 				}
@@ -779,7 +780,7 @@ main(int argc, char **argv)
 			case 'n':
 				if (sscanf(optarg, "%d", &config.stop_after_records) != 1)
 				{
-					fprintf(stderr, "%s: could not parse limit \"%s\"\n",
+					fprintf(stderr, _("%s: could not parse limit \"%s\"\n"),
 							progname, optarg);
 					goto bad_argument;
 				}
@@ -808,7 +809,7 @@ main(int argc, char **argv)
 
 					if (config.filter_by_rmgr == -1)
 					{
-						fprintf(stderr, "%s: resource manager \"%s\" does not exist\n",
+						fprintf(stderr, _("%s: resource manager \"%s\" does not exist\n"),
 								progname, optarg);
 						goto bad_argument;
 					}
@@ -817,7 +818,7 @@ main(int argc, char **argv)
 			case 's':
 				if (sscanf(optarg, "%X/%X", &xlogid, &xrecoff) != 2)
 				{
-					fprintf(stderr, "%s: could not parse start log position \"%s\"\n",
+					fprintf(stderr, _("%s: could not parse start log position \"%s\"\n"),
 							progname, optarg);
 					goto bad_argument;
 				}
@@ -827,7 +828,7 @@ main(int argc, char **argv)
 			case 't':
 				if (sscanf(optarg, "%d", &private.timeline) != 1)
 				{
-					fprintf(stderr, "%s: could not parse timeline \"%s\"\n",
+					fprintf(stderr, _("%s: could not parse timeline \"%s\"\n"),
 							progname, optarg);
 					goto bad_argument;
 				}
@@ -839,7 +840,7 @@ main(int argc, char **argv)
 			case 'x':
 				if (sscanf(optarg, "%u", &config.filter_by_xid) != 1)
 				{
-					fprintf(stderr, "%s: could not parse \"%s\" as a valid xid\n",
+					fprintf(stderr, _("%s: could not parse \"%s\" as a valid xid\n"),
 							progname, optarg);
 					goto bad_argument;
 				}
@@ -854,7 +855,7 @@ main(int argc, char **argv)
 						config.stats_per_record = true;
 					else if (strcmp(optarg, "rmgr") != 0)
 					{
-						fprintf(stderr, "%s: unrecognised argument to --stats: %s\n",
+						fprintf(stderr, _("%s: unrecognised argument to --stats: %s\n"),
 								progname, optarg);
 						goto bad_argument;
 					}
@@ -868,7 +869,7 @@ main(int argc, char **argv)
 	if ((optind + 2) < argc)
 	{
 		fprintf(stderr,
-				"%s: too many command-line arguments (first is \"%s\")\n",
+				_("%s: too many command-line arguments (first is \"%s\")\n"),
 				progname, argv[optind + 2]);
 		goto bad_argument;
 	}
@@ -879,7 +880,7 @@ main(int argc, char **argv)
 		if (!verify_directory(private.inpath))
 		{
 			fprintf(stderr,
-					"%s: path \"%s\" cannot be opened: %s\n",
+					_("%s: path \"%s\" cannot be opened: %s\n"),
 					progname, private.inpath, strerror(errno));
 			goto bad_argument;
 		}
@@ -917,7 +918,7 @@ main(int argc, char **argv)
 		else if (!XLByteInSeg(private.startptr, segno))
 		{
 			fprintf(stderr,
-				  "%s: start log position %X/%X is not inside file \"%s\"\n",
+					_("%s: start log position %X/%X is not inside file \"%s\"\n"),
 					progname,
 					(uint32) (private.startptr >> 32),
 					(uint32) private.startptr,
@@ -961,7 +962,7 @@ main(int argc, char **argv)
 			private.endptr != (segno + 1) * XLogSegSize)
 		{
 			fprintf(stderr,
-					"%s: end log position %X/%X is not inside file \"%s\"\n",
+					_("%s: end log position %X/%X is not inside file \"%s\"\n"),
 					progname,
 					(uint32) (private.endptr >> 32),
 					(uint32) private.endptr,
@@ -973,7 +974,7 @@ main(int argc, char **argv)
 	/* we don't know what to print */
 	if (XLogRecPtrIsInvalid(private.startptr))
 	{
-		fprintf(stderr, "%s: no start log position given.\n", progname);
+		fprintf(stderr, _("%s: no start log position given.\n"), progname);
 		goto bad_argument;
 	}
 
@@ -998,7 +999,7 @@ main(int argc, char **argv)
 	 * a segment (e.g. we were used in file mode).
 	 */
 	if (first_record != private.startptr && (private.startptr % XLogSegSize) != 0)
-		printf("first record is after %X/%X, at %X/%X, skipping over %u bytes\n",
+		printf(_("first record is after %X/%X, at %X/%X, skipping over %u bytes\n"),
 			   (uint32) (private.startptr >> 32), (uint32) private.startptr,
 			   (uint32) (first_record >> 32), (uint32) first_record,
 			   (uint32) (first_record - private.startptr));
@@ -1057,6 +1058,6 @@ main(int argc, char **argv)
 	return EXIT_SUCCESS;
 
 bad_argument:
-	fprintf(stderr, "Try \"%s --help\" for more information.\n", progname);
+	fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname);
 	return EXIT_FAILURE;
 }
-- 
2.10.1

