Hi,

apparently gettext can't properly identify strings when 64bit values
formatted with macros like INT64_FORMAT and UINT64_FORMAT. I did
some research and found out that gettext can work with PRId64 and
PRIu64. My suggestion is to use these macro for such strings.

The problem is here that PRIu64 is not accessible on all platforms but
this is easy solvable if it will be specified using INT64_MODIFIER in
c.h.

I attached a sample patch that adds PRIu64, PRId64 and makes few strings
translatable.

Using PRId64 will simplify the code like this:

                char            bufv[100],
                                        bufm[100],
                                        bufx[100];

                snprintf(bufv, sizeof(bufv), INT64_FORMAT, next);
                snprintf(bufm, sizeof(bufm), INT64_FORMAT, minv);
                snprintf(bufx, sizeof(bufx), INT64_FORMAT, maxv);
                ereport(ERROR,
                                (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
                                 errmsg("setval: value %s is out of
                bounds for sequence \"%s\" (%s..%s)", bufv,
                RelationGetRelationName(seqrel), bufm, bufx)));


To:

        if ((next < minv) || (next > maxv))
                ereport(ERROR,
                                (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
                                 errmsg("setval: value %s is out of
        bounds for sequence \"%" PRId64 "\" (%" PRId64 "..%" PRId64
        ")", next, RelationGetRelationName(seqrel), minv, maxv)));

In result:

#: commands/sequence.c:944
#, fuzzy, c-format
#| msgid "setval: value %s is out of bounds for sequence
\"%s\" (%s..%s)"
msgid "setval: value %s is out of bounds for sequence
\"%<PRId64>\" (%<PRId64>..%<PRId64>)"
msgstr "setval передано значение %s вне пределов последовательности
\"%s\" (%s..%s)"

And still this string will be translatable. I found a bunch of places
when PRIx64 macros can simplify the code. 

-- 
---
Ildus Kurbangaliev
Postgres Professional: http://www.postgrespro.com
Russian Postgres Company
diff --git a/src/bin/pg_controldata/pg_controldata.c b/src/bin/pg_controldata/pg_controldata.c
index 7d435ffa57..8f1ac7816f 100644
--- a/src/bin/pg_controldata/pg_controldata.c
+++ b/src/bin/pg_controldata/pg_controldata.c
@@ -97,7 +97,6 @@ main(int argc, char *argv[])
 	time_t		time_tmp;
 	char		pgctime_str[128];
 	char		ckpttime_str[128];
-	char		sysident_str[32];
 	char		mock_auth_nonce_str[MOCK_AUTH_NONCE_LEN * 2 + 1];
 	const char *strftime_fmt = "%c";
 	const char *progname;
@@ -219,8 +218,6 @@ main(int argc, char *argv[])
 	 * keep platform-dependent format code out of the translatable message
 	 * string.
 	 */
-	snprintf(sysident_str, sizeof(sysident_str), UINT64_FORMAT,
-			 ControlFile->system_identifier);
 	for (i = 0; i < MOCK_AUTH_NONCE_LEN; i++)
 		snprintf(&mock_auth_nonce_str[i * 2], 3, "%02x",
 				 (unsigned char) ControlFile->mock_authentication_nonce[i]);
@@ -229,8 +226,8 @@ main(int argc, char *argv[])
 		   ControlFile->pg_control_version);
 	printf(_("Catalog version number:               %u\n"),
 		   ControlFile->catalog_version_no);
-	printf(_("Database system identifier:           %s\n"),
-		   sysident_str);
+	printf(_("Database system identifier:           %" PRIu64 "\n"),
+		   ControlFile->system_identifier);
 	printf(_("Database cluster state:               %s\n"),
 		   dbState(ControlFile->state));
 	printf(_("pg_control last modified:             %s\n"),
diff --git a/src/include/c.h b/src/include/c.h
index 95e9aeded9..8009bcc0c5 100644
--- a/src/include/c.h
+++ b/src/include/c.h
@@ -364,8 +364,11 @@ typedef unsigned long long int uint64;
 #endif
 
 /* snprintf format strings to use for 64-bit integers */
-#define INT64_FORMAT "%" INT64_MODIFIER "d"
-#define UINT64_FORMAT "%" INT64_MODIFIER "u"
+#define PRId64 INT64_MODIFIER "d"
+#define PRIu64 INT64_MODIFIER "u"
+
+#define INT64_FORMAT "%" PRId64
+#define UINT64_FORMAT "%" PRIu64
 
 /*
  * 128-bit signed and unsigned integers

Reply via email to