Commit 2532c54d authored by Alvaro Herrera's avatar Alvaro Herrera

Improve translatability of error messages for external modules by tweaking

the ereport macro.  Included in this commit are enough files for starting
plpgsql, plpython, plperl and pltcl translations.
parent b1553103
...@@ -42,7 +42,7 @@ ...@@ -42,7 +42,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/error/elog.c,v 1.206 2008/09/01 20:42:45 tgl Exp $ * $PostgreSQL: pgsql/src/backend/utils/error/elog.c,v 1.207 2008/10/09 17:24:05 alvherre Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -160,7 +160,7 @@ static void write_csvlog(ErrorData *edata); ...@@ -160,7 +160,7 @@ static void write_csvlog(ErrorData *edata);
*/ */
bool bool
errstart(int elevel, const char *filename, int lineno, errstart(int elevel, const char *filename, int lineno,
const char *funcname) const char *funcname, const char *domain)
{ {
ErrorData *edata; ErrorData *edata;
bool output_to_server; bool output_to_server;
...@@ -290,6 +290,8 @@ errstart(int elevel, const char *filename, int lineno, ...@@ -290,6 +290,8 @@ errstart(int elevel, const char *filename, int lineno,
edata->filename = filename; edata->filename = filename;
edata->lineno = lineno; edata->lineno = lineno;
edata->funcname = funcname; edata->funcname = funcname;
/* the default text domain is the backend's */
edata->domain = domain ? domain : "postgres";
/* Select default errcode based on elevel */ /* Select default errcode based on elevel */
if (elevel >= ERROR) if (elevel >= ERROR)
edata->sqlerrcode = ERRCODE_INTERNAL_ERROR; edata->sqlerrcode = ERRCODE_INTERNAL_ERROR;
...@@ -611,7 +613,7 @@ errcode_for_socket_access(void) ...@@ -611,7 +613,7 @@ errcode_for_socket_access(void)
char *fmtbuf; \ char *fmtbuf; \
StringInfoData buf; \ StringInfoData buf; \
/* Internationalize the error format string */ \ /* Internationalize the error format string */ \
fmt = _(fmt); \ fmt = dgettext(edata->domain, fmt); \
/* Expand %m in format string */ \ /* Expand %m in format string */ \
fmtbuf = expand_fmt_string(fmt, edata); \ fmtbuf = expand_fmt_string(fmt, edata); \
initStringInfo(&buf); \ initStringInfo(&buf); \
...@@ -982,7 +984,7 @@ elog_finish(int elevel, const char *fmt,...) ...@@ -982,7 +984,7 @@ elog_finish(int elevel, const char *fmt,...)
*/ */
errordata_stack_depth--; errordata_stack_depth--;
errno = edata->saved_errno; errno = edata->saved_errno;
if (!errstart(elevel, edata->filename, edata->lineno, edata->funcname)) if (!errstart(elevel, edata->filename, edata->lineno, edata->funcname, NULL))
return; /* nothing to do */ return; /* nothing to do */
/* /*
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/init/miscinit.c,v 1.167 2008/03/27 17:24:16 momjian Exp $ * $PostgreSQL: pgsql/src/backend/utils/init/miscinit.c,v 1.168 2008/10/09 17:24:05 alvherre Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -1212,3 +1212,17 @@ process_local_preload_libraries(void) ...@@ -1212,3 +1212,17 @@ process_local_preload_libraries(void)
"local_preload_libraries", "local_preload_libraries",
true); true);
} }
void
set_text_domain(const char *domain)
{
#ifdef ENABLE_NLS
if (my_exec_path[0] != '\0')
{
char locale_path[MAXPGPATH];
get_locale_path(my_exec_path, locale_path);
bindtextdomain(domain, locale_path);
}
#endif
}
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/miscadmin.h,v 1.202 2008/04/23 13:44:59 mha Exp $ * $PostgreSQL: pgsql/src/include/miscadmin.h,v 1.203 2008/10/09 17:24:05 alvherre Exp $
* *
* NOTES * NOTES
* some of the information in this file should be moved to other files. * some of the information in this file should be moved to other files.
...@@ -329,6 +329,7 @@ extern void RecordSharedMemoryInLockFile(unsigned long id1, ...@@ -329,6 +329,7 @@ extern void RecordSharedMemoryInLockFile(unsigned long id1,
extern void ValidatePgVersion(const char *path); extern void ValidatePgVersion(const char *path);
extern void process_shared_preload_libraries(void); extern void process_shared_preload_libraries(void);
extern void process_local_preload_libraries(void); extern void process_local_preload_libraries(void);
extern void set_text_domain(const char *domain);
/* in access/transam/xlog.c */ /* in access/transam/xlog.c */
extern bool BackupInProgress(void); extern bool BackupInProgress(void);
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/utils/elog.h,v 1.94 2008/09/01 20:42:45 tgl Exp $ * $PostgreSQL: pgsql/src/include/utils/elog.h,v 1.95 2008/10/09 17:24:05 alvherre Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -92,14 +92,26 @@ ...@@ -92,14 +92,26 @@
* ERRCODE_INTERNAL_ERROR if elevel is ERROR or more, ERRCODE_WARNING * ERRCODE_INTERNAL_ERROR if elevel is ERROR or more, ERRCODE_WARNING
* if elevel is WARNING, or ERRCODE_SUCCESSFUL_COMPLETION if elevel is * if elevel is WARNING, or ERRCODE_SUCCESSFUL_COMPLETION if elevel is
* NOTICE or below. * NOTICE or below.
*
* ereport_domain() allows a message domain to be specified, for modules that
* wish to use a different message catalog from the backend's. To avoid having
* one copy of the default text domain per .o file, we define it as NULL here
* and have errstart insert the default text domain. Modules can either use
* ereport_domain() directly, or preferrably they can override the TEXTDOMAIN
* macro.
*---------- *----------
*/ */
#define ereport(elevel, rest) \ #define ereport_domain(elevel, domain, rest) \
(errstart(elevel, __FILE__, __LINE__, PG_FUNCNAME_MACRO) ? \ (errstart(elevel, __FILE__, __LINE__, PG_FUNCNAME_MACRO, domain) ? \
(errfinish rest) : (void) 0) (errfinish rest) : (void) 0)
#define ereport(level, rest) \
ereport_domain(level, TEXTDOMAIN, rest)
#define TEXTDOMAIN NULL
extern bool errstart(int elevel, const char *filename, int lineno, extern bool errstart(int elevel, const char *filename, int lineno,
const char *funcname); const char *funcname, const char *domain);
extern void errfinish(int dummy,...); extern void errfinish(int dummy,...);
extern int errcode(int sqlerrcode); extern int errcode(int sqlerrcode);
...@@ -269,6 +281,7 @@ typedef struct ErrorData ...@@ -269,6 +281,7 @@ typedef struct ErrorData
const char *filename; /* __FILE__ of ereport() call */ const char *filename; /* __FILE__ of ereport() call */
int lineno; /* __LINE__ of ereport() call */ int lineno; /* __LINE__ of ereport() call */
const char *funcname; /* __func__ of ereport() call */ const char *funcname; /* __func__ of ereport() call */
const char *domain; /* message domain, NULL if default */
int sqlerrcode; /* encoded ERRSTATE */ int sqlerrcode; /* encoded ERRSTATE */
char *message; /* primary error message */ char *message; /* primary error message */
char *detail; /* detail error message */ char *detail; /* detail error message */
......
# $PostgreSQL: pgsql/src/pl/plperl/nls.mk,v 1.1 2008/10/09 17:24:05 alvherre Exp $
CATALOG_NAME := plperl
AVAIL_LANGUAGES :=
GETTEXT_FILES := plperl.c SPI.xs
GETTEXT_TRIGGERS:= _ errmsg errdetail errdetail_log errhint errcontext write_stderr croak Perl_croak
/********************************************************************** /**********************************************************************
* plperl.c - perl as a procedural language for PostgreSQL * plperl.c - perl as a procedural language for PostgreSQL
* *
* $PostgreSQL: pgsql/src/pl/plperl/plperl.c,v 1.139 2008/03/28 00:21:56 tgl Exp $ * $PostgreSQL: pgsql/src/pl/plperl/plperl.c,v 1.140 2008/10/09 17:24:05 alvherre Exp $
* *
**********************************************************************/ **********************************************************************/
...@@ -30,6 +30,10 @@ ...@@ -30,6 +30,10 @@
#include "utils/typcache.h" #include "utils/typcache.h"
#include "utils/hsearch.h" #include "utils/hsearch.h"
/* define our text domain for translations */
#undef TEXTDOMAIN
#define TEXTDOMAIN "plperl"
/* perl stuff */ /* perl stuff */
#include "plperl.h" #include "plperl.h"
...@@ -186,8 +190,10 @@ _PG_init(void) ...@@ -186,8 +190,10 @@ _PG_init(void)
if (inited) if (inited)
return; return;
set_text_domain(TEXTDOMAIN);
DefineCustomBoolVariable("plperl.use_strict", DefineCustomBoolVariable("plperl.use_strict",
"If true, will compile trusted and untrusted perl code in strict mode", gettext_noop("If true, will compile trusted and untrusted perl code in strict mode"),
NULL, NULL,
&plperl_use_strict, &plperl_use_strict,
PGC_USERSET, PGC_USERSET,
......
# $PostgreSQL: pgsql/src/pl/plpgsql/src/nls.mk,v 1.1 2008/10/09 17:24:05 alvherre Exp $
CATALOG_NAME := plpgsql
AVAIL_LANGUAGES :=
GETTEXT_FILES := pl_comp.c pl_exec.c pl_gram.c pl_funcs.c pl_handler.c pl_scan.c
GETTEXT_TRIGGERS:= _ errmsg errdetail errdetail_log errhint errcontext write_stderr yyerror
.PHONY: gettext-files
gettext-files: distprep
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_handler.c,v 1.40 2008/08/29 13:02:33 petere Exp $ * $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_handler.c,v 1.41 2008/10/09 17:24:05 alvherre Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -42,6 +42,8 @@ _PG_init(void) ...@@ -42,6 +42,8 @@ _PG_init(void)
if (inited) if (inited)
return; return;
set_text_domain(TEXTDOMAIN);
plpgsql_HashTableInit(); plpgsql_HashTableInit();
RegisterXactCallback(plpgsql_xact_cb, NULL); RegisterXactCallback(plpgsql_xact_cb, NULL);
RegisterSubXactCallback(plpgsql_subxact_cb, NULL); RegisterSubXactCallback(plpgsql_subxact_cb, NULL);
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/pl/plpgsql/src/plpgsql.h,v 1.101 2008/10/09 16:35:07 tgl Exp $ * $PostgreSQL: pgsql/src/pl/plpgsql/src/plpgsql.h,v 1.102 2008/10/09 17:24:05 alvherre Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -28,6 +28,10 @@ ...@@ -28,6 +28,10 @@
* Definitions * Definitions
**********************************************************************/ **********************************************************************/
/* define our text domain for translations */
#undef TEXTDOMAIN
#define TEXTDOMAIN "plpgsql"
/* ---------- /* ----------
* Compiler's namestack item types * Compiler's namestack item types
* ---------- * ----------
......
# $PostgreSQL: pgsql/src/pl/plpython/nls.mk,v 1.1 2008/10/09 17:24:05 alvherre Exp $
CATALOG_NAME := plpython
AVAIL_LANGUAGES :=
GETTEXT_FILES := plpython.c
GETTEXT_TRIGGERS:= _ errmsg errdetail errdetail_log errhint errcontext write_stderr yyerror
/********************************************************************** /**********************************************************************
* plpython.c - python as a procedural language for PostgreSQL * plpython.c - python as a procedural language for PostgreSQL
* *
* $PostgreSQL: pgsql/src/pl/plpython/plpython.c,v 1.112 2008/07/18 03:32:53 tgl Exp $ * $PostgreSQL: pgsql/src/pl/plpython/plpython.c,v 1.113 2008/10/09 17:24:05 alvherre Exp $
* *
********************************************************************* *********************************************************************
*/ */
...@@ -63,6 +63,10 @@ typedef int Py_ssize_t; ...@@ -63,6 +63,10 @@ typedef int Py_ssize_t;
#include "utils/syscache.h" #include "utils/syscache.h"
#include "utils/typcache.h" #include "utils/typcache.h"
/* define our text domain for translations */
#undef TEXTDOMAIN
#define TEXTDOMAIN "plpython"
#include <compile.h> #include <compile.h>
#include <eval.h> #include <eval.h>
...@@ -2745,6 +2749,8 @@ _PG_init(void) ...@@ -2745,6 +2749,8 @@ _PG_init(void)
if (inited) if (inited)
return; return;
set_text_domain(TEXTDOMAIN);
Py_Initialize(); Py_Initialize();
PLy_init_interp(); PLy_init_interp();
PLy_init_plpy(); PLy_init_plpy();
......
# $PostgreSQL: pgsql/src/pl/tcl/nls.mk,v 1.1 2008/10/09 17:24:05 alvherre Exp $
CATALOG_NAME := pltcl
AVAIL_LANGUAGES :=
GETTEXT_FILES := pltcl.c
GETTEXT_TRIGGERS:= _ errmsg errdetail errdetail_log errhint errcontext write_stderr yyerror
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* pltcl.c - PostgreSQL support for Tcl as * pltcl.c - PostgreSQL support for Tcl as
* procedural language (PL) * procedural language (PL)
* *
* $PostgreSQL: pgsql/src/pl/tcl/pltcl.c,v 1.121 2008/06/17 00:52:43 tgl Exp $ * $PostgreSQL: pgsql/src/pl/tcl/pltcl.c,v 1.122 2008/10/09 17:24:05 alvherre Exp $
* *
**********************************************************************/ **********************************************************************/
...@@ -41,6 +41,10 @@ ...@@ -41,6 +41,10 @@
#define Tcl_GetStringResult(interp) ((interp)->result) #define Tcl_GetStringResult(interp) ((interp)->result)
#endif #endif
/* define our text domain for translations */
#undef TEXTDOMAIN
#define TEXTDOMAIN "pltcl"
#if defined(UNICODE_CONVERSION) && HAVE_TCL_VERSION(8,1) #if defined(UNICODE_CONVERSION) && HAVE_TCL_VERSION(8,1)
#include "mb/pg_wchar.h" #include "mb/pg_wchar.h"
...@@ -263,6 +267,8 @@ _PG_init(void) ...@@ -263,6 +267,8 @@ _PG_init(void)
if (pltcl_pm_init_done) if (pltcl_pm_init_done)
return; return;
set_text_domain(TEXTDOMAIN);
#ifdef WIN32 #ifdef WIN32
/* Required on win32 to prevent error loading init.tcl */ /* Required on win32 to prevent error loading init.tcl */
Tcl_FindExecutable(""); Tcl_FindExecutable("");
......
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