Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2532c54

Browse files
committed
Improve translatability of error messages for external modules by tweaking
the ereport macro. Included in this commit are enough files for startingplpgsql, plpython, plperl and pltcl translations.
1 parentb155310 commit2532c54

File tree

13 files changed

+93
-16
lines changed

13 files changed

+93
-16
lines changed

‎src/backend/utils/error/elog.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
*
4343
*
4444
* IDENTIFICATION
45-
* $PostgreSQL: pgsql/src/backend/utils/error/elog.c,v 1.206 2008/09/01 20:42:45 tgl Exp $
45+
* $PostgreSQL: pgsql/src/backend/utils/error/elog.c,v 1.207 2008/10/09 17:24:05 alvherre Exp $
4646
*
4747
*-------------------------------------------------------------------------
4848
*/
@@ -160,7 +160,7 @@ static void write_csvlog(ErrorData *edata);
160160
*/
161161
bool
162162
errstart(intelevel,constchar*filename,intlineno,
163-
constchar*funcname)
163+
constchar*funcname,constchar*domain)
164164
{
165165
ErrorData*edata;
166166
booloutput_to_server;
@@ -290,6 +290,8 @@ errstart(int elevel, const char *filename, int lineno,
290290
edata->filename=filename;
291291
edata->lineno=lineno;
292292
edata->funcname=funcname;
293+
/* the default text domain is the backend's */
294+
edata->domain=domain ?domain :"postgres";
293295
/* Select default errcode based on elevel */
294296
if (elevel >=ERROR)
295297
edata->sqlerrcode=ERRCODE_INTERNAL_ERROR;
@@ -611,7 +613,7 @@ errcode_for_socket_access(void)
611613
char *fmtbuf; \
612614
StringInfoDatabuf; \
613615
/* Internationalize the error format string */ \
614-
fmt=_(fmt); \
616+
fmt=dgettext(edata->domain,fmt); \
615617
/* Expand %m in format string */ \
616618
fmtbuf=expand_fmt_string(fmt,edata); \
617619
initStringInfo(&buf); \
@@ -982,7 +984,7 @@ elog_finish(int elevel, const char *fmt,...)
982984
*/
983985
errordata_stack_depth--;
984986
errno=edata->saved_errno;
985-
if (!errstart(elevel,edata->filename,edata->lineno,edata->funcname))
987+
if (!errstart(elevel,edata->filename,edata->lineno,edata->funcname,NULL))
986988
return;/* nothing to do */
987989

988990
/*

‎src/backend/utils/init/miscinit.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/utils/init/miscinit.c,v 1.167 2008/03/27 17:24:16 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/init/miscinit.c,v 1.168 2008/10/09 17:24:05 alvherre Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -1212,3 +1212,17 @@ process_local_preload_libraries(void)
12121212
"local_preload_libraries",
12131213
true);
12141214
}
1215+
1216+
void
1217+
set_text_domain(constchar*domain)
1218+
{
1219+
#ifdefENABLE_NLS
1220+
if (my_exec_path[0]!='\0')
1221+
{
1222+
charlocale_path[MAXPGPATH];
1223+
1224+
get_locale_path(my_exec_path,locale_path);
1225+
bindtextdomain(domain,locale_path);
1226+
}
1227+
#endif
1228+
}

‎src/include/miscadmin.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
1414
* Portions Copyright (c) 1994, Regents of the University of California
1515
*
16-
* $PostgreSQL: pgsql/src/include/miscadmin.h,v 1.202 2008/04/23 13:44:59 mha Exp $
16+
* $PostgreSQL: pgsql/src/include/miscadmin.h,v 1.203 2008/10/09 17:24:05 alvherre Exp $
1717
*
1818
* NOTES
1919
* some of the information in this file should be moved to other files.
@@ -329,6 +329,7 @@ extern void RecordSharedMemoryInLockFile(unsigned long id1,
329329
externvoidValidatePgVersion(constchar*path);
330330
externvoidprocess_shared_preload_libraries(void);
331331
externvoidprocess_local_preload_libraries(void);
332+
externvoidset_text_domain(constchar*domain);
332333

333334
/* in access/transam/xlog.c */
334335
externboolBackupInProgress(void);

‎src/include/utils/elog.h

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $PostgreSQL: pgsql/src/include/utils/elog.h,v 1.94 2008/09/01 20:42:45 tgl Exp $
10+
* $PostgreSQL: pgsql/src/include/utils/elog.h,v 1.95 2008/10/09 17:24:05 alvherre Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -92,14 +92,26 @@
9292
* ERRCODE_INTERNAL_ERROR if elevel is ERROR or more, ERRCODE_WARNING
9393
* if elevel is WARNING, or ERRCODE_SUCCESSFUL_COMPLETION if elevel is
9494
* NOTICE or below.
95+
*
96+
* ereport_domain() allows a message domain to be specified, for modules that
97+
* wish to use a different message catalog from the backend's.To avoid having
98+
* one copy of the default text domain per .o file, we define it as NULL here
99+
* and have errstart insert the default text domain. Modules can either use
100+
* ereport_domain() directly, or preferrably they can override the TEXTDOMAIN
101+
* macro.
95102
*----------
96103
*/
97-
#defineereport(elevel,rest)\
98-
(errstart(elevel, __FILE__, __LINE__, PG_FUNCNAME_MACRO) ? \
104+
#defineereport_domain(elevel,domain,rest)\
105+
(errstart(elevel, __FILE__, __LINE__, PG_FUNCNAME_MACRO, domain) ? \
99106
(errfinish rest) : (void) 0)
100107

108+
#defineereport(level,rest)\
109+
ereport_domain(level, TEXTDOMAIN, rest)
110+
111+
#defineTEXTDOMAIN NULL
112+
101113
externboolerrstart(intelevel,constchar*filename,intlineno,
102-
constchar*funcname);
114+
constchar*funcname,constchar*domain);
103115
externvoiderrfinish(intdummy,...);
104116

105117
externinterrcode(intsqlerrcode);
@@ -269,6 +281,7 @@ typedef struct ErrorData
269281
constchar*filename;/* __FILE__ of ereport() call */
270282
intlineno;/* __LINE__ of ereport() call */
271283
constchar*funcname;/* __func__ of ereport() call */
284+
constchar*domain;/* message domain, NULL if default */
272285
intsqlerrcode;/* encoded ERRSTATE */
273286
char*message;/* primary error message */
274287
char*detail;/* detail error message */

‎src/pl/plperl/nls.mk

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# $PostgreSQL: pgsql/src/pl/plperl/nls.mk,v 1.1 2008/10/09 17:24:05 alvherre Exp $
2+
CATALOG_NAME:= plperl
3+
AVAIL_LANGUAGES:=
4+
GETTEXT_FILES:= plperl.c SPI.xs
5+
GETTEXT_TRIGGERS:= _ errmsg errdetail errdetail_log errhint errcontext write_stderr croak Perl_croak

‎src/pl/plperl/plperl.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**********************************************************************
22
* plperl.c - perl as a procedural language for PostgreSQL
33
*
4-
* $PostgreSQL: pgsql/src/pl/plperl/plperl.c,v 1.139 2008/03/28 00:21:56 tgl Exp $
4+
* $PostgreSQL: pgsql/src/pl/plperl/plperl.c,v 1.140 2008/10/09 17:24:05 alvherre Exp $
55
*
66
**********************************************************************/
77

@@ -30,6 +30,10 @@
3030
#include"utils/typcache.h"
3131
#include"utils/hsearch.h"
3232

33+
/* define our text domain for translations */
34+
#undef TEXTDOMAIN
35+
#defineTEXTDOMAIN "plperl"
36+
3337
/* perl stuff */
3438
#include"plperl.h"
3539

@@ -186,8 +190,10 @@ _PG_init(void)
186190
if (inited)
187191
return;
188192

193+
set_text_domain(TEXTDOMAIN);
194+
189195
DefineCustomBoolVariable("plperl.use_strict",
190-
"If true, will compile trusted and untrusted perl code in strict mode",
196+
gettext_noop("If true, will compile trusted and untrusted perl code in strict mode"),
191197
NULL,
192198
&plperl_use_strict,
193199
PGC_USERSET,

‎src/pl/plpgsql/src/nls.mk

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# $PostgreSQL: pgsql/src/pl/plpgsql/src/nls.mk,v 1.1 2008/10/09 17:24:05 alvherre Exp $
2+
CATALOG_NAME:= plpgsql
3+
AVAIL_LANGUAGES:=
4+
GETTEXT_FILES:= pl_comp.c pl_exec.c pl_gram.c pl_funcs.c pl_handler.c pl_scan.c
5+
GETTEXT_TRIGGERS:= _ errmsg errdetail errdetail_log errhint errcontext write_stderr yyerror
6+
7+
.PHONY: gettext-files
8+
gettext-files: distprep

‎src/pl/plpgsql/src/pl_handler.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_handler.c,v 1.40 2008/08/29 13:02:33 petere Exp $
11+
* $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_handler.c,v 1.41 2008/10/09 17:24:05 alvherre Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -42,6 +42,8 @@ _PG_init(void)
4242
if (inited)
4343
return;
4444

45+
set_text_domain(TEXTDOMAIN);
46+
4547
plpgsql_HashTableInit();
4648
RegisterXactCallback(plpgsql_xact_cb,NULL);
4749
RegisterSubXactCallback(plpgsql_subxact_cb,NULL);

‎src/pl/plpgsql/src/plpgsql.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/pl/plpgsql/src/plpgsql.h,v 1.101 2008/10/0916:35:07 tgl Exp $
11+
* $PostgreSQL: pgsql/src/pl/plpgsql/src/plpgsql.h,v 1.102 2008/10/0917:24:05 alvherre Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -28,6 +28,10 @@
2828
* Definitions
2929
**********************************************************************/
3030

31+
/* define our text domain for translations */
32+
#undef TEXTDOMAIN
33+
#defineTEXTDOMAIN "plpgsql"
34+
3135
/* ----------
3236
* Compiler's namestack item types
3337
* ----------

‎src/pl/plpython/nls.mk

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# $PostgreSQL: pgsql/src/pl/plpython/nls.mk,v 1.1 2008/10/09 17:24:05 alvherre Exp $
2+
CATALOG_NAME:= plpython
3+
AVAIL_LANGUAGES:=
4+
GETTEXT_FILES:= plpython.c
5+
GETTEXT_TRIGGERS:= _ errmsg errdetail errdetail_log errhint errcontext write_stderr yyerror

‎src/pl/plpython/plpython.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**********************************************************************
22
* plpython.c - python as a procedural language for PostgreSQL
33
*
4-
*$PostgreSQL: pgsql/src/pl/plpython/plpython.c,v 1.112 2008/07/18 03:32:53 tgl Exp $
4+
*$PostgreSQL: pgsql/src/pl/plpython/plpython.c,v 1.113 2008/10/09 17:24:05 alvherre Exp $
55
*
66
*********************************************************************
77
*/
@@ -63,6 +63,10 @@ typedef int Py_ssize_t;
6363
#include"utils/syscache.h"
6464
#include"utils/typcache.h"
6565

66+
/* define our text domain for translations */
67+
#undef TEXTDOMAIN
68+
#defineTEXTDOMAIN "plpython"
69+
6670
#include<compile.h>
6771
#include<eval.h>
6872

@@ -2745,6 +2749,8 @@ _PG_init(void)
27452749
if (inited)
27462750
return;
27472751

2752+
set_text_domain(TEXTDOMAIN);
2753+
27482754
Py_Initialize();
27492755
PLy_init_interp();
27502756
PLy_init_plpy();

‎src/pl/tcl/nls.mk

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# $PostgreSQL: pgsql/src/pl/tcl/nls.mk,v 1.1 2008/10/09 17:24:05 alvherre Exp $
2+
CATALOG_NAME:= pltcl
3+
AVAIL_LANGUAGES:=
4+
GETTEXT_FILES:= pltcl.c
5+
GETTEXT_TRIGGERS:= _ errmsg errdetail errdetail_log errhint errcontext write_stderr yyerror

‎src/pl/tcl/pltcl.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* pltcl.c- PostgreSQL support for Tcl as
33
* procedural language (PL)
44
*
5-
* $PostgreSQL: pgsql/src/pl/tcl/pltcl.c,v 1.121 2008/06/17 00:52:43 tgl Exp $
5+
* $PostgreSQL: pgsql/src/pl/tcl/pltcl.c,v 1.122 2008/10/09 17:24:05 alvherre Exp $
66
*
77
**********************************************************************/
88

@@ -41,6 +41,10 @@
4141
#defineTcl_GetStringResult(interp) ((interp)->result)
4242
#endif
4343

44+
/* define our text domain for translations */
45+
#undef TEXTDOMAIN
46+
#defineTEXTDOMAIN "pltcl"
47+
4448
#if defined(UNICODE_CONVERSION)&&HAVE_TCL_VERSION(8,1)
4549

4650
#include"mb/pg_wchar.h"
@@ -263,6 +267,8 @@ _PG_init(void)
263267
if (pltcl_pm_init_done)
264268
return;
265269

270+
set_text_domain(TEXTDOMAIN);
271+
266272
#ifdefWIN32
267273
/* Required on win32 to prevent error loading init.tcl */
268274
Tcl_FindExecutable("");

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp