Skip to content

Commit a6f01d1

Browse files
committed
Internationalize interactive yes/no responses.
1 parent aea0270 commit a6f01d1

File tree

5 files changed

+32
-8
lines changed

5 files changed

+32
-8
lines changed

src/bin/scripts/common.c

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
66
* Portions Copyright (c) 1994, Regents of the University of California
77
*
8-
* $Header: /cvsroot/pgsql/src/bin/scripts/common.c,v 1.2 2003/04/04 20:42:13 momjian Exp $
8+
* $Header: /cvsroot/pgsql/src/bin/scripts/common.c,v 1.3 2003/05/27 19:36:54 petere Exp $
99
*
1010
*-------------------------------------------------------------------------
1111
*/
@@ -153,3 +153,24 @@ executeQuery(PGconn *conn, const char *query, const char *progname, bool echo)
153153

154154
return res;
155155
}
156+
157+
158+
/*
159+
* Check yes/no answer in a localized way. 1=yes, 0=no, -1=neither.
160+
*/
161+
162+
/* translator: Make sure the (y/n) prompts match the translation of this. */
163+
#define PG_YESLETTER gettext_noop("y")
164+
/* translator: Make sure the (y/n) prompts match the translation of this. */
165+
#define PG_NOLETTER gettext_noop("n")
166+
167+
int
168+
check_yesno_response(const char *string)
169+
{
170+
if (strcmp(string, gettext(PG_YESLETTER)) == 0)
171+
return 1;
172+
else if (strcmp(string, gettext(PG_NOLETTER)) == 0)
173+
return 0;
174+
else
175+
return -1;
176+
}

src/bin/scripts/common.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,6 @@ connectDatabase(const char *dbname, const char *pghost, const char *pgport,
3232

3333
PGresult *
3434
executeQuery(PGconn *conn, const char *command, const char *progname, bool echo);
35+
36+
int
37+
check_yesno_response(const char *string);

src/bin/scripts/createuser.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
66
* Portions Copyright (c) 1994, Regents of the University of California
77
*
8-
* $Header: /cvsroot/pgsql/src/bin/scripts/createuser.c,v 1.2 2003/05/14 03:26:03 tgl Exp $
8+
* $Header: /cvsroot/pgsql/src/bin/scripts/createuser.c,v 1.3 2003/05/27 19:36:54 petere Exp $
99
*
1010
*-------------------------------------------------------------------------
1111
*/
@@ -166,7 +166,7 @@ main(int argc, char *argv[])
166166
char *reply;
167167

168168
reply = simple_prompt("Shall the new user be allowed to create databases? (y/n) ", 1, true);
169-
if (reply[0] == 'y' || reply[0] == 'Y')
169+
if (check_yesno_response(reply) == 1)
170170
createdb = +1;
171171
else
172172
createdb = -1;
@@ -177,7 +177,7 @@ main(int argc, char *argv[])
177177
char *reply;
178178

179179
reply = simple_prompt("Shall the new user be allowed to create more new users? (y/n) ", 1, true);
180-
if (reply[0] == 'y' || reply[0] == 'Y')
180+
if (check_yesno_response(reply) == 1)
181181
adduser = +1;
182182
else
183183
adduser = -1;

src/bin/scripts/dropdb.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
66
* Portions Copyright (c) 1994, Regents of the University of California
77
*
8-
* $Header: /cvsroot/pgsql/src/bin/scripts/dropdb.c,v 1.2 2003/05/14 03:26:03 tgl Exp $
8+
* $Header: /cvsroot/pgsql/src/bin/scripts/dropdb.c,v 1.3 2003/05/27 19:36:54 petere Exp $
99
*
1010
*-------------------------------------------------------------------------
1111
*/
@@ -107,7 +107,7 @@ main(int argc, char *argv[])
107107

108108
printf(_("Database \"%s\" will be permanently deleted.\n"), dbname);
109109
reply = simple_prompt("Are you sure? (y/n) ", 1, true);
110-
if (reply[0] != 'y' && reply[0] != 'Y')
110+
if (check_yesno_response(reply) != 1)
111111
exit(0);
112112
}
113113

src/bin/scripts/dropuser.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
66
* Portions Copyright (c) 1994, Regents of the University of California
77
*
8-
* $Header: /cvsroot/pgsql/src/bin/scripts/dropuser.c,v 1.2 2003/05/14 03:26:03 tgl Exp $
8+
* $Header: /cvsroot/pgsql/src/bin/scripts/dropuser.c,v 1.3 2003/05/27 19:36:55 petere Exp $
99
*
1010
*-------------------------------------------------------------------------
1111
*/
@@ -108,7 +108,7 @@ main(int argc, char *argv[])
108108

109109
printf(_("User \"%s\" will be permanently deleted.\n"), dropuser);
110110
reply = simple_prompt("Are you sure? (y/n) ", 1, true);
111-
if (reply[0] != 'y' && reply[0] != 'Y')
111+
if (check_yesno_response(reply) != 1)
112112
exit(0);
113113
}
114114

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy