Gettext plural support

In the backend, I changed only a handful of exemplary or important-looking
instances to make use of the plural support; there is probably more work
there.  For the rest of the source, this should cover all relevant cases.
This commit is contained in:
Peter Eisentraut 2009-03-26 22:26:08 +00:00
parent 845693f70f
commit 8032d76b5b
15 changed files with 105 additions and 53 deletions

View File

@ -8,7 +8,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/catalog/dependency.c,v 1.86 2009/01/22 20:16:00 tgl Exp $
* $PostgreSQL: pgsql/src/backend/catalog/dependency.c,v 1.87 2009/03/26 22:26:06 petere Exp $
*
*-------------------------------------------------------------------------
*/
@ -885,8 +885,11 @@ reportDependentObjects(const ObjectAddresses *targetObjects,
}
if (numNotReportedClient > 0)
appendStringInfo(&clientdetail, _("\nand %d other objects "
"(see server log for list)"),
appendStringInfo(&clientdetail, ngettext("\nand %d other object "
"(see server log for list)",
"\nand %d other objects "
"(see server log for list)",
numNotReportedClient),
numNotReportedClient);
if (!ok)
@ -911,7 +914,9 @@ reportDependentObjects(const ObjectAddresses *targetObjects,
{
ereport(msglevel,
/* translator: %d always has a value larger than 1 */
(errmsg("drop cascades to %d other objects",
(errmsg(ngettext("drop cascades to %d other object",
"drop cascades to %d other objects",
numReportedClient + numNotReportedClient),
numReportedClient + numNotReportedClient),
errdetail("%s", clientdetail.data),
errdetail_log("%s", logdetail.data)));

View File

@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/catalog/pg_proc.c,v 1.161 2009/01/22 20:16:01 tgl Exp $
* $PostgreSQL: pgsql/src/backend/catalog/pg_proc.c,v 1.162 2009/03/26 22:26:06 petere Exp $
*
*-------------------------------------------------------------------------
*/
@ -112,7 +112,9 @@ ProcedureCreate(const char *procedureName,
if (parameterCount < 0 || parameterCount > FUNC_MAX_ARGS)
ereport(ERROR,
(errcode(ERRCODE_TOO_MANY_ARGUMENTS),
errmsg("functions cannot have more than %d arguments",
errmsg(ngettext("functions cannot have more than %d argument",
"functions cannot have more than %d arguments",
FUNC_MAX_ARGS),
FUNC_MAX_ARGS)));
/* note: the above is correct, we do NOT count output arguments */

View File

@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/catalog/pg_shdepend.c,v 1.31 2009/01/22 20:16:01 tgl Exp $
* $PostgreSQL: pgsql/src/backend/catalog/pg_shdepend.c,v 1.32 2009/03/26 22:26:06 petere Exp $
*
*-------------------------------------------------------------------------
*/
@ -655,12 +655,18 @@ checkSharedDependencies(Oid classId, Oid objectId,
}
if (numNotReportedDeps > 0)
appendStringInfo(&descs, _("\nand %d other objects "
"(see server log for list)"),
appendStringInfo(&descs, ngettext("\nand %d other object "
"(see server log for list)",
"\nand %d other objects "
"(see server log for list)",
numNotReportedDeps),
numNotReportedDeps);
if (numNotReportedDbs > 0)
appendStringInfo(&descs, _("\nand objects in %d other databases "
"(see server log for list)"),
appendStringInfo(&descs, ngettext("\nand objects in %d other database "
"(see server log for list)",
"\nand objects in %d other databases "
"(see server log for list)",
numNotReportedDbs),
numNotReportedDbs);
*detail_msg = descs.data;
@ -1043,7 +1049,7 @@ storeObjectDescription(StringInfo descs, objectType type,
case REMOTE_OBJECT:
/* translator: %s will always be "database %s" */
appendStringInfo(descs, _("%d objects in %s"), count, objdesc);
appendStringInfo(descs, ngettext("%d object in %s", "%d objects in %s", count), count, objdesc);
break;
default:

View File

@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/executor/execQual.c,v 1.241 2009/01/09 15:46:10 tgl Exp $
* $PostgreSQL: pgsql/src/backend/executor/execQual.c,v 1.242 2009/03/26 22:26:06 petere Exp $
*
*-------------------------------------------------------------------------
*/
@ -616,7 +616,9 @@ ExecEvalVar(ExprState *exprstate, ExprContext *econtext,
ereport(ERROR,
(errcode(ERRCODE_DATATYPE_MISMATCH),
errmsg("table row type and query-specified row type do not match"),
errdetail("Table row contains %d attributes, but query expects %d.",
errdetail(ngettext("Table row contains %d attribute, but query expects %d.",
"Table row contains %d attributes, but query expects %d.",
slot_tupdesc->natts),
slot_tupdesc->natts, var_tupdesc->natts)));
else if (var_tupdesc->natts < slot_tupdesc->natts)
needslow = true;
@ -1041,7 +1043,9 @@ init_fcache(Oid foid, FuncExprState *fcache,
if (list_length(fcache->args) > FUNC_MAX_ARGS)
ereport(ERROR,
(errcode(ERRCODE_TOO_MANY_ARGUMENTS),
errmsg("cannot pass more than %d arguments to a function",
errmsg(ngettext("cannot pass more than %d argument to a function",
"cannot pass more than %d arguments to a function",
FUNC_MAX_ARGS),
FUNC_MAX_ARGS)));
/* Set up the primary fmgr lookup information */
@ -1310,7 +1314,9 @@ tupledesc_match(TupleDesc dst_tupdesc, TupleDesc src_tupdesc)
ereport(ERROR,
(errcode(ERRCODE_DATATYPE_MISMATCH),
errmsg("function return row and query-specified return row do not match"),
errdetail("Returned row contains %d attributes, but query expects %d.",
errdetail(ngettext("Returned row contains %d attribute, but query expects %d.",
"Returned row contains %d attributes, but query expects %d.",
src_tupdesc->natts),
src_tupdesc->natts, dst_tupdesc->natts)));
for (i = 0; i < dst_tupdesc->natts; i++)

View File

@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/parser/parse_func.c,v 1.211 2009/01/01 17:23:45 momjian Exp $
* $PostgreSQL: pgsql/src/backend/parser/parse_func.c,v 1.212 2009/03/26 22:26:06 petere Exp $
*
*-------------------------------------------------------------------------
*/
@ -89,7 +89,9 @@ ParseFuncOrColumn(ParseState *pstate, List *funcname, List *fargs,
if (list_length(fargs) > FUNC_MAX_ARGS)
ereport(ERROR,
(errcode(ERRCODE_TOO_MANY_ARGUMENTS),
errmsg("cannot pass more than %d arguments to a function",
errmsg(ngettext("cannot pass more than %d argument to a function",
"cannot pass more than %d arguments to a function",
FUNC_MAX_ARGS),
FUNC_MAX_ARGS),
parser_errposition(pstate, location)));
@ -259,7 +261,9 @@ ParseFuncOrColumn(ParseState *pstate, List *funcname, List *fargs,
if (nargsplusdefs >= FUNC_MAX_ARGS)
ereport(ERROR,
(errcode(ERRCODE_TOO_MANY_ARGUMENTS),
errmsg("cannot pass more than %d arguments to a function",
errmsg(ngettext("cannot pass more than %d argument to a function",
"cannot pass more than %d arguments to a function",
FUNC_MAX_ARGS),
FUNC_MAX_ARGS),
parser_errposition(pstate, location)));
@ -538,7 +542,9 @@ func_select_candidate(int nargs,
if (nargs > FUNC_MAX_ARGS)
ereport(ERROR,
(errcode(ERRCODE_TOO_MANY_ARGUMENTS),
errmsg("cannot pass more than %d arguments to a function",
errmsg(ngettext("cannot pass more than %d argument to a function",
"cannot pass more than %d arguments to a function",
FUNC_MAX_ARGS),
FUNC_MAX_ARGS)));
/*
@ -1413,7 +1419,9 @@ LookupFuncNameTypeNames(List *funcname, List *argtypes, bool noError)
if (argcount > FUNC_MAX_ARGS)
ereport(ERROR,
(errcode(ERRCODE_TOO_MANY_ARGUMENTS),
errmsg("functions cannot have more than %d arguments",
errmsg(ngettext("functions cannot have more than %d argument",
"functions cannot have more than %d arguments",
FUNC_MAX_ARGS),
FUNC_MAX_ARGS)));
args_item = list_head(argtypes);
@ -1451,7 +1459,9 @@ LookupAggNameTypeNames(List *aggname, List *argtypes, bool noError)
if (argcount > FUNC_MAX_ARGS)
ereport(ERROR,
(errcode(ERRCODE_TOO_MANY_ARGUMENTS),
errmsg("functions cannot have more than %d arguments",
errmsg(ngettext("functions cannot have more than %d argument",
"functions cannot have more than %d arguments",
FUNC_MAX_ARGS),
FUNC_MAX_ARGS)));
i = 0;

View File

@ -37,7 +37,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/postmaster/bgwriter.c,v 1.56 2009/02/18 15:58:41 heikki Exp $
* $PostgreSQL: pgsql/src/backend/postmaster/bgwriter.c,v 1.57 2009/03/26 22:26:06 petere Exp $
*
*-------------------------------------------------------------------------
*/
@ -459,7 +459,9 @@ BackgroundWriterMain(void)
(flags & CHECKPOINT_CAUSE_XLOG) &&
elapsed_secs < CheckPointWarning)
ereport(LOG,
(errmsg("checkpoints are occurring too frequently (%d seconds apart)",
(errmsg(ngettext("checkpoints are occurring too frequently (%d second apart)",
"checkpoints are occurring too frequently (%d seconds apart)",
elapsed_secs),
elapsed_secs),
errhint("Consider increasing the configuration parameter \"checkpoint_segments\".")));

View File

@ -15,7 +15,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.168 2009/03/20 09:21:08 petere Exp $
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.169 2009/03/26 22:26:07 petere Exp $
*
*-------------------------------------------------------------------------
*/
@ -884,7 +884,10 @@ EndRestoreBlobs(ArchiveHandle *AH)
ahprintf(AH, "COMMIT;\n\n");
}
ahlog(AH, 1, "restored %d large objects\n", AH->blobCount);
ahlog(AH, 1, ngettext("restored %d large object\n",
"restored %d large objects\n",
AH->blobCount),
AH->blobCount);
}
@ -1230,7 +1233,9 @@ dump_lo_buf(ArchiveHandle *AH)
size_t res;
res = lo_write(AH->connection, AH->loFd, AH->lo_buf, AH->lo_buf_used);
ahlog(AH, 5, "wrote %lu bytes of large object data (result = %lu)\n",
ahlog(AH, 5, ngettext("wrote %lu byte of large object data (result = %lu)\n",
"wrote %lu bytes of large object data (result = %lu)\n",
AH->lo_buf_used),
(unsigned long) AH->lo_buf_used, (unsigned long) res);
if (res != AH->lo_buf_used)
die_horribly(AH, modulename,
@ -1781,7 +1786,9 @@ _discoverArchiveFormat(ArchiveHandle *AH)
AH->lookaheadLen = 0; /* Don't bother since we've reset the file */
#if 0
write_msg(modulename, "read %lu bytes into lookahead buffer\n",
write_msg(modulename, ngettext("read %lu byte into lookahead buffer\n",
"read %lu bytes into lookahead buffer\n",
AH->lookaheadLen),
(unsigned long) AH->lookaheadLen);
#endif

View File

@ -16,7 +16,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_tar.c,v 1.63 2009/02/02 20:07:37 adunstan Exp $
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_tar.c,v 1.64 2009/03/26 22:26:07 petere Exp $
*
*-------------------------------------------------------------------------
*/
@ -550,7 +550,9 @@ _tarReadRaw(ArchiveHandle *AH, void *buf, size_t len, TAR_MEMBER *th, FILE *fh)
}
#if 0
write_msg(modulename, "requested %d bytes, got %d from lookahead and %d from file\n",
write_msg(modulename, ngettext("requested %d byte, got %d from lookahead and %d from file\n",
"requested %d bytes, got %d from lookahead and %d from file\n",
reqLen),
reqLen, used, res);
#endif
@ -1246,7 +1248,9 @@ _tarGetHeader(ArchiveHandle *AH, TAR_MEMBER *th)
if (len != 512)
die_horribly(AH, modulename,
"incomplete tar header found (%lu bytes)\n",
ngettext("incomplete tar header found (%lu byte)\n",
"incomplete tar header found (%lu bytes)\n",
len),
(unsigned long) len);
/* Calc checksum */

View File

@ -12,7 +12,7 @@
* by PostgreSQL
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.530 2009/03/22 16:44:26 tgl Exp $
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.531 2009/03/26 22:26:07 petere Exp $
*
*-------------------------------------------------------------------------
*/
@ -5004,7 +5004,9 @@ getTableAttrs(TableInfo *tblinfo, int numTables)
numConstrs = PQntuples(res);
if (numConstrs != tbinfo->ncheck)
{
write_msg(NULL, "expected %d check constraints on table \"%s\" but found %d\n",
write_msg(NULL, ngettext("expected %d check constraint on table \"%s\" but found %d\n",
"expected %d check constraints on table \"%s\" but found %d\n",
tbinfo->ncheck),
tbinfo->ncheck, tbinfo->dobj.name, numConstrs);
write_msg(NULL, "(The system catalogs might be corrupted.)\n");
exit_nicely();
@ -6335,7 +6337,9 @@ dumpBaseType(Archive *fout, TypeInfo *tinfo)
ntups = PQntuples(res);
if (ntups != 1)
{
write_msg(NULL, "query returned %d rows instead of one: %s\n",
write_msg(NULL, ngettext("query returned %d row instead of one: %s\n",
"query returned %d rows instead of one: %s\n",
ntups),
ntups, query->data);
exit_nicely();
}
@ -6532,7 +6536,9 @@ dumpDomain(Archive *fout, TypeInfo *tinfo)
ntups = PQntuples(res);
if (ntups != 1)
{
write_msg(NULL, "query returned %d rows instead of one: %s\n",
write_msg(NULL, ngettext("query returned %d row instead of one: %s\n",
"query returned %d rows instead of one: %s\n",
ntups),
ntups, query->data);
exit_nicely();
}
@ -7181,7 +7187,9 @@ dumpFunc(Archive *fout, FuncInfo *finfo)
ntups = PQntuples(res);
if (ntups != 1)
{
write_msg(NULL, "query returned %d rows instead of one: %s\n",
write_msg(NULL, ngettext("query returned %d row instead of one: %s\n",
"query returned %d rows instead of one: %s\n",
ntups),
ntups, query->data);
exit_nicely();
}
@ -10518,7 +10526,9 @@ dumpSequence(Archive *fout, TableInfo *tbinfo)
if (PQntuples(res) != 1)
{
write_msg(NULL, "query to get data of sequence \"%s\" returned %d rows (expected 1)\n",
write_msg(NULL, ngettext("query to get data of sequence \"%s\" returned %d row (expected 1)\n",
"query to get data of sequence \"%s\" returned %d rows (expected 1)\n",
PQntuples(res)),
tbinfo->dobj.name, PQntuples(res));
exit_nicely();
}

View File

@ -8,7 +8,7 @@
*
* Copyright (c) 2000-2009, PostgreSQL Global Development Group
*
* $PostgreSQL: pgsql/src/bin/psql/describe.c,v 1.202 2009/03/25 13:11:43 petere Exp $
* $PostgreSQL: pgsql/src/bin/psql/describe.c,v 1.203 2009/03/26 22:26:07 petere Exp $
*/
#include "postgres_fe.h"
@ -1891,10 +1891,8 @@ describeRoles(const char *pattern, bool verbose)
if (conns == 0)
appendPQExpBuffer(&buf, _("No connections"));
else if (conns == 1)
appendPQExpBuffer(&buf, _("1 connection"));
else
appendPQExpBuffer(&buf, _("%d connections"), conns);
appendPQExpBuffer(&buf, ngettext("1 connection", "%d connections", conns), conns);
}
attr[i] = pg_strdup(buf.data);

View File

@ -3,7 +3,7 @@
*
* Copyright (c) 2000-2009, PostgreSQL Global Development Group
*
* $PostgreSQL: pgsql/src/bin/psql/print.c,v 1.110 2009/01/01 17:23:55 momjian Exp $
* $PostgreSQL: pgsql/src/bin/psql/print.c,v 1.111 2009/03/26 22:26:07 petere Exp $
*/
#include "postgres_fe.h"
@ -2348,10 +2348,7 @@ printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, FILE *f
char default_footer[100];
total_records = opt->topt.prior_records + cont.nrows;
if (total_records == 1)
snprintf(default_footer, 100, _("(1 row)"));
else
snprintf(default_footer, 100, _("(%lu rows)"), total_records);
snprintf(default_footer, 100, ngettext("(1 row)", "(%lu rows)", total_records), total_records);
printTableAddFooter(&cont, default_footer);
}

View File

@ -12,7 +12,7 @@
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $PostgreSQL: pgsql/src/include/c.h,v 1.234 2009/01/01 17:23:55 momjian Exp $
* $PostgreSQL: pgsql/src/include/c.h,v 1.235 2009/03/26 22:26:07 petere Exp $
*
*-------------------------------------------------------------------------
*/
@ -97,6 +97,8 @@
#else
#define gettext(x) (x)
#define dgettext(d,x) (x)
#define ngettext(s,p,n) ((n) == 1 ? (s) : (p))
#define dngettext(d,s,p,n) ((n) == 1 ? (s) : (p))
#endif
/*

View File

@ -1,4 +1,4 @@
/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/variable.c,v 1.47 2009/01/26 10:19:44 petere Exp $ */
/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/variable.c,v 1.48 2009/03/26 22:26:08 petere Exp $ */
#include "postgres_fe.h"
@ -496,7 +496,9 @@ adjust_array(enum ECPGttype type_enum, char **dimension, char **length, char *ty
}
if (pointer_len > 2)
mmerror(PARSE_ERROR, ET_FATAL, "multilevel pointers (more than 2 levels) are not supported; found %d levels", pointer_len);
mmerror(PARSE_ERROR, ET_FATAL, ngettext("multilevel pointers (more than 2 levels) are not supported; found %d level",
"multilevel pointers (more than 2 levels) are not supported; found %d levels", pointer_len),
pointer_len);
if (pointer_len > 1 && type_enum != ECPGt_char && type_enum != ECPGt_unsigned_char)
mmerror(PARSE_ERROR, ET_FATAL, "pointer to pointer is not supported for this data type");

View File

@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.235 2009/02/23 10:03:22 petere Exp $
* $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.236 2009/03/26 22:26:08 petere Exp $
*
*-------------------------------------------------------------------------
*/
@ -4088,7 +4088,8 @@ exec_eval_expr(PLpgSQL_execstate *estate,
if (estate->eval_tuptable->tupdesc->natts != 1)
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("query \"%s\" returned %d columns", expr->query,
errmsg(dngettext(TEXTDOMAIN, "query \"%s\" returned %d column", "query \"%s\" returned %d columns", estate->eval_tuptable->tupdesc->natts),
expr->query,
estate->eval_tuptable->tupdesc->natts)));
/*

View File

@ -1,7 +1,7 @@
/**********************************************************************
* plpython.c - python as a procedural language for PostgreSQL
*
* $PostgreSQL: pgsql/src/pl/plpython/plpython.c,v 1.118 2009/01/15 13:49:56 petere Exp $
* $PostgreSQL: pgsql/src/pl/plpython/plpython.c,v 1.119 2009/03/26 22:26:08 petere Exp $
*
*********************************************************************
*/
@ -2523,7 +2523,7 @@ PLy_spi_execute_plan(PyObject * ob, PyObject * list, long limit)
PLy_procedure_name(PLy_curr_procedure));
sv = PyString_AsString(so);
PLy_exception_set(PLy_exc_spi_error,
"Expected sequence of %d arguments, got %d: %s",
dngettext(TEXTDOMAIN, "Expected sequence of %d argument, got %d: %s", "Expected sequence of %d arguments, got %d: %s", plan->nargs),
plan->nargs, nargs, sv);
Py_DECREF(so);