Alvaro Herrera wrote:
> Tom Lane wrote:

> > No, you could have TEXTDOMAIN be defined as NULL by default, and let
> > modules redefine it as "foo".
> 
> Doh, right.

So this'd seem to be the version ready to be applied (plus the needed
nls.mk files).

-- 
Alvaro Herrera                                http://www.CommandPrompt.com/
PostgreSQL Replication, Consulting, Custom Development, 24x7 support
Index: src/backend/utils/error/elog.c
===================================================================
RCS file: /home/alvherre/Code/cvs/pgsql/src/backend/utils/error/elog.c,v
retrieving revision 1.206
diff -c -p -r1.206 elog.c
*** src/backend/utils/error/elog.c	1 Sep 2008 20:42:45 -0000	1.206
--- src/backend/utils/error/elog.c	8 Oct 2008 23:44:09 -0000
*************** static void write_csvlog(ErrorData *edat
*** 160,166 ****
   */
  bool
  errstart(int elevel, const char *filename, int lineno,
! 		 const char *funcname)
  {
  	ErrorData  *edata;
  	bool		output_to_server;
--- 160,166 ----
   */
  bool
  errstart(int elevel, const char *filename, int lineno,
! 		 const char *funcname, const char *domain)
  {
  	ErrorData  *edata;
  	bool		output_to_server;
*************** errstart(int elevel, const char *filenam
*** 290,295 ****
--- 290,297 ----
  	edata->filename = filename;
  	edata->lineno = lineno;
  	edata->funcname = funcname;
+ 	/* the default text domain is the backend's */
+ 	edata->domain = domain ? domain : "postgres";
  	/* Select default errcode based on elevel */
  	if (elevel >= ERROR)
  		edata->sqlerrcode = ERRCODE_INTERNAL_ERROR;
*************** errcode_for_socket_access(void)
*** 611,617 ****
  		char		   *fmtbuf; \
  		StringInfoData	buf; \
  		/* Internationalize the error format string */ \
! 		fmt = _(fmt); \
  		/* Expand %m in format string */ \
  		fmtbuf = expand_fmt_string(fmt, edata); \
  		initStringInfo(&buf); \
--- 613,619 ----
  		char		   *fmtbuf; \
  		StringInfoData	buf; \
  		/* Internationalize the error format string */ \
! 		fmt = dgettext(edata->domain, fmt); \
  		/* Expand %m in format string */ \
  		fmtbuf = expand_fmt_string(fmt, edata); \
  		initStringInfo(&buf); \
*************** elog_finish(int elevel, const char *fmt,
*** 982,988 ****
  	 */
  	errordata_stack_depth--;
  	errno = edata->saved_errno;
! 	if (!errstart(elevel, edata->filename, edata->lineno, edata->funcname))
  		return;					/* nothing to do */
  
  	/*
--- 984,990 ----
  	 */
  	errordata_stack_depth--;
  	errno = edata->saved_errno;
! 	if (!errstart(elevel, edata->filename, edata->lineno, edata->funcname, NULL))
  		return;					/* nothing to do */
  
  	/*
Index: src/include/utils/elog.h
===================================================================
RCS file: /home/alvherre/Code/cvs/pgsql/src/include/utils/elog.h,v
retrieving revision 1.94
diff -c -p -r1.94 elog.h
*** src/include/utils/elog.h	1 Sep 2008 20:42:45 -0000	1.94
--- src/include/utils/elog.h	9 Oct 2008 02:50:20 -0000
***************
*** 92,105 ****
   * ERRCODE_INTERNAL_ERROR if elevel is ERROR or more, ERRCODE_WARNING
   * if elevel is WARNING, or ERRCODE_SUCCESSFUL_COMPLETION if elevel is
   * NOTICE or below.
   *----------
   */
! #define ereport(elevel, rest)  \
! 	(errstart(elevel, __FILE__, __LINE__, PG_FUNCNAME_MACRO) ? \
  	 (errfinish rest) : (void) 0)
  
  extern bool errstart(int elevel, const char *filename, int lineno,
! 		 const char *funcname);
  extern void errfinish(int dummy,...);
  
  extern int	errcode(int sqlerrcode);
--- 92,117 ----
   * ERRCODE_INTERNAL_ERROR if elevel is ERROR or more, ERRCODE_WARNING
   * if elevel is WARNING, or ERRCODE_SUCCESSFUL_COMPLETION if elevel is
   * 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_domain(elevel, domain, rest)	\
! 	(errstart(elevel, __FILE__, __LINE__, PG_FUNCNAME_MACRO, domain) ? \
  	 (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,
! 		 const char *funcname, const char *domain);
  extern void errfinish(int dummy,...);
  
  extern int	errcode(int sqlerrcode);
*************** typedef struct ErrorData
*** 269,274 ****
--- 281,287 ----
  	const char *filename;		/* __FILE__ of ereport() call */
  	int			lineno;			/* __LINE__ of ereport() call */
  	const char *funcname;		/* __func__ of ereport() call */
+ 	const char *domain;			/* message domain, NULL if default */
  	int			sqlerrcode;		/* encoded ERRSTATE */
  	char	   *message;		/* primary error message */
  	char	   *detail;			/* detail error message */
Index: src/pl/plperl/plperl.c
===================================================================
RCS file: /home/alvherre/Code/cvs/pgsql/src/pl/plperl/plperl.c,v
retrieving revision 1.139
diff -c -p -r1.139 plperl.c
*** src/pl/plperl/plperl.c	28 Mar 2008 00:21:56 -0000	1.139
--- src/pl/plperl/plperl.c	9 Oct 2008 00:50:26 -0000
***************
*** 30,35 ****
--- 30,39 ----
  #include "utils/typcache.h"
  #include "utils/hsearch.h"
  
+ /* define our text domain for translations */
+ #undef TEXTDOMAIN
+ #define TEXTDOMAIN "plperl"
+ 
  /* perl stuff */
  #include "plperl.h"
  
*************** _PG_init(void)
*** 213,218 ****
--- 217,232 ----
  
  	plperl_init_interp();
  
+ #ifdef ENABLE_NLS
+ 	if (my_exec_path[0] != '\0')
+ 	{
+ 		char	locale_path[MAXPGPATH];
+ 
+ 		get_locale_path(my_exec_path, locale_path);
+ 		bindtextdomain(TEXTDOMAIN, locale_path);
+ 	}
+ #endif
+ 
  	inited = true;
  }
  
Index: src/pl/plpgsql/src/pl_handler.c
===================================================================
RCS file: /home/alvherre/Code/cvs/pgsql/src/pl/plpgsql/src/pl_handler.c,v
retrieving revision 1.40
diff -c -p -r1.40 pl_handler.c
*** src/pl/plpgsql/src/pl_handler.c	29 Aug 2008 13:02:33 -0000	1.40
--- src/pl/plpgsql/src/pl_handler.c	9 Oct 2008 00:51:22 -0000
*************** _PG_init(void)
*** 42,47 ****
--- 42,57 ----
  	if (inited)
  		return;
  
+ #ifdef ENABLE_NLS
+ 	if (my_exec_path[0] != '\0')
+ 	{
+ 		char	locale_path[MAXPGPATH];
+ 
+ 		get_locale_path(my_exec_path, locale_path);
+ 		bindtextdomain(TEXTDOMAIN, locale_path);
+ 	}
+ #endif
+ 
  	plpgsql_HashTableInit();
  	RegisterXactCallback(plpgsql_xact_cb, NULL);
  	RegisterSubXactCallback(plpgsql_subxact_cb, NULL);
Index: src/pl/plpgsql/src/plpgsql.h
===================================================================
RCS file: /home/alvherre/Code/cvs/pgsql/src/pl/plpgsql/src/plpgsql.h,v
retrieving revision 1.100
diff -c -p -r1.100 plpgsql.h
*** src/pl/plpgsql/src/plpgsql.h	15 May 2008 22:39:49 -0000	1.100
--- src/pl/plpgsql/src/plpgsql.h	9 Oct 2008 00:51:53 -0000
***************
*** 28,33 ****
--- 28,37 ----
   * Definitions
   **********************************************************************/
  
+ /* define our text domain for translations */
+ #undef TEXTDOMAIN
+ #define TEXTDOMAIN "plpgsql"
+ 
  /* ----------
   * Compiler's namestack item types
   * ----------
Index: src/pl/plpython/plpython.c
===================================================================
RCS file: /home/alvherre/Code/cvs/pgsql/src/pl/plpython/plpython.c,v
retrieving revision 1.112
diff -c -p -r1.112 plpython.c
*** src/pl/plpython/plpython.c	18 Jul 2008 03:32:53 -0000	1.112
--- src/pl/plpython/plpython.c	9 Oct 2008 00:51:04 -0000
*************** typedef int Py_ssize_t;
*** 63,68 ****
--- 63,72 ----
  #include "utils/syscache.h"
  #include "utils/typcache.h"
  
+ /* define our text domain for translations */
+ #undef TEXTDOMAIN
+ #define TEXTDOMAIN "plpython"
+ 
  #include <compile.h>
  #include <eval.h>
  
*************** _PG_init(void)
*** 2754,2759 ****
--- 2758,2773 ----
  	if (PLy_procedure_cache == NULL)
  		PLy_elog(ERROR, "could not create procedure cache");
  
+ #ifdef ENABLE_NLS
+ 	if (my_exec_path[0] != '\0')
+ 	{
+ 		char	locale_path[MAXPGPATH];
+ 
+ 		get_locale_path(my_exec_path, locale_path);
+ 		bindtextdomain(TEXTDOMAIN, locale_path);
+ 	}
+ #endif
+ 
  	inited = true;
  }
  
Index: src/pl/tcl/pltcl.c
===================================================================
RCS file: /home/alvherre/Code/cvs/pgsql/src/pl/tcl/pltcl.c,v
retrieving revision 1.121
diff -c -p -r1.121 pltcl.c
*** src/pl/tcl/pltcl.c	17 Jun 2008 00:52:43 -0000	1.121
--- src/pl/tcl/pltcl.c	9 Oct 2008 02:54:21 -0000
***************
*** 41,46 ****
--- 41,50 ----
  #define Tcl_GetStringResult(interp)  ((interp)->result)
  #endif
  
+ /* redefine ereport() with our text domain */
+ #undef TEXTDOMAIN
+ #define TEXTDOMAIN "pltcl"
+ 
  #if defined(UNICODE_CONVERSION) && HAVE_TCL_VERSION(8,1)
  
  #include "mb/pg_wchar.h"
*************** _PG_init(void)
*** 318,323 ****
--- 322,337 ----
  	Tcl_InitHashTable(pltcl_norm_query_hash, TCL_STRING_KEYS);
  	Tcl_InitHashTable(pltcl_safe_query_hash, TCL_STRING_KEYS);
  
+ #ifdef ENABLE_NLS
+ 	if (my_exec_path[0] != '\0')
+ 	{
+ 		char	locale_path[MAXPGPATH];
+ 
+ 		get_locale_path(my_exec_path, locale_path);
+ 		bindtextdomain(TEXTDOMAIN, locale_path);
+ 	}
+ #endif
+ 
  	pltcl_pm_init_done = true;
  }
  
-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to