🌐 AI搜索 & 代理 主页
Skip to content

Commit 169ff4c

Browse files
jchampioalvherre
andcommitted
libpq: Add missing OAuth translations
Several strings that should have been translated as they passed through libpq_gettext were not actually being pulled into the translation files, because I hadn't directly wrapped them in one of the GETTEXT_TRIGGERS. Move the responsibility for calling libpq_gettext() to the code that sets actx->errctx. Doing the same in report_type_mismatch() would result in double-translation, so mark those strings with gettext_noop() instead. And wrap two ternary operands with gettext_noop(), even though they're already in one of the triggers, since xgettext sees only the first. Finally, fe-auth-oauth.c was missing from nls.mk, so none of that file was being translated at all. Add it now. Original patch by Zhijie Hou, plus suggested tweaks by Álvaro Herrera and small additions by me. Reported-by: Zhijie Hou <houzj.fnst@fujitsu.com> Author: Zhijie Hou <houzj.fnst@fujitsu.com> Co-authored-by: Álvaro Herrera <alvherre@kurilemu.de> Co-authored-by: Jacob Champion <jacob.champion@enterprisedb.com> Reviewed-by: Álvaro Herrera <alvherre@kurilemu.de> Discussion: https://postgr.es/m/TY4PR01MB1690746DB91991D1E9A47F57E94CDA%40TY4PR01MB16907.jpnprd01.prod.outlook.com Backpatch-through: 18
1 parent bae8ca8 commit 169ff4c

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

src/interfaces/libpq-oauth/oauth-curl.c

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,8 @@ struct async_ctx
247247
* our entry point, errors have three parts:
248248
*
249249
* - errctx: an optional static string, describing the global operation
250-
* currently in progress. It'll be translated for you.
250+
* currently in progress. Should be translated with
251+
* libpq_gettext().
251252
*
252253
* - errbuf: contains the actual error message. Generally speaking, use
253254
* actx_error[_str] to manipulate this. This must be filled
@@ -475,20 +476,20 @@ report_type_mismatch(struct oauth_parse *ctx)
475476
switch (ctx->active->type)
476477
{
477478
case JSON_TOKEN_STRING:
478-
msgfmt = "field \"%s\" must be a string";
479+
msgfmt = gettext_noop("field \"%s\" must be a string");
479480
break;
480481

481482
case JSON_TOKEN_NUMBER:
482-
msgfmt = "field \"%s\" must be a number";
483+
msgfmt = gettext_noop("field \"%s\" must be a number");
483484
break;
484485

485486
case JSON_TOKEN_ARRAY_START:
486-
msgfmt = "field \"%s\" must be an array of strings";
487+
msgfmt = gettext_noop("field \"%s\" must be an array of strings");
487488
break;
488489

489490
default:
490491
Assert(false);
491-
msgfmt = "field \"%s\" has unexpected type";
492+
msgfmt = gettext_noop("field \"%s\" has unexpected type");
492493
}
493494

494495
oauth_parse_set_error(ctx, msgfmt, ctx->active->name);
@@ -1087,7 +1088,7 @@ parse_token_error(struct async_ctx *actx, struct token_error *err)
10871088
* override the errctx if parsing explicitly fails.
10881089
*/
10891090
if (!result)
1090-
actx->errctx = "failed to parse token error response";
1091+
actx->errctx = libpq_gettext("failed to parse token error response");
10911092

10921093
return result;
10931094
}
@@ -1115,8 +1116,8 @@ record_token_error(struct async_ctx *actx, const struct token_error *err)
11151116
if (response_code == 401)
11161117
{
11171118
actx_error(actx, actx->used_basic_auth
1118-
? "provider rejected the oauth_client_secret"
1119-
: "provider requires client authentication, and no oauth_client_secret is set");
1119+
? gettext_noop("provider rejected the oauth_client_secret")
1120+
: gettext_noop("provider requires client authentication, and no oauth_client_secret is set"));
11201121
actx_error_str(actx, " ");
11211122
}
11221123
}
@@ -2153,7 +2154,7 @@ finish_discovery(struct async_ctx *actx)
21532154
/*
21542155
* Pull the fields we care about from the document.
21552156
*/
2156-
actx->errctx = "failed to parse OpenID discovery document";
2157+
actx->errctx = libpq_gettext("failed to parse OpenID discovery document");
21572158
if (!parse_provider(actx, &actx->provider))
21582159
return false; /* error message already set */
21592160

@@ -2421,7 +2422,7 @@ finish_device_authz(struct async_ctx *actx)
24212422
*/
24222423
if (response_code == 200)
24232424
{
2424-
actx->errctx = "failed to parse device authorization";
2425+
actx->errctx = libpq_gettext("failed to parse device authorization");
24252426
if (!parse_device_authz(actx, &actx->authz))
24262427
return false; /* error message already set */
24272428

@@ -2509,7 +2510,7 @@ finish_token_request(struct async_ctx *actx, struct token *tok)
25092510
*/
25102511
if (response_code == 200)
25112512
{
2512-
actx->errctx = "failed to parse access token response";
2513+
actx->errctx = libpq_gettext("failed to parse access token response");
25132514
if (!parse_access_token(actx, tok))
25142515
return false; /* error message already set */
25152516

@@ -2888,7 +2889,7 @@ pg_fe_run_oauth_flow_impl(PGconn *conn)
28882889
switch (actx->step)
28892890
{
28902891
case OAUTH_STEP_INIT:
2891-
actx->errctx = "failed to fetch OpenID discovery document";
2892+
actx->errctx = libpq_gettext("failed to fetch OpenID discovery document");
28922893
if (!start_discovery(actx, conn_oauth_discovery_uri(conn)))
28932894
goto error_return;
28942895

@@ -2902,11 +2903,11 @@ pg_fe_run_oauth_flow_impl(PGconn *conn)
29022903
if (!check_issuer(actx, conn))
29032904
goto error_return;
29042905

2905-
actx->errctx = "cannot run OAuth device authorization";
2906+
actx->errctx = libpq_gettext("cannot run OAuth device authorization");
29062907
if (!check_for_device_flow(actx))
29072908
goto error_return;
29082909

2909-
actx->errctx = "failed to obtain device authorization";
2910+
actx->errctx = libpq_gettext("failed to obtain device authorization");
29102911
if (!start_device_authz(actx, conn))
29112912
goto error_return;
29122913

@@ -2917,7 +2918,7 @@ pg_fe_run_oauth_flow_impl(PGconn *conn)
29172918
if (!finish_device_authz(actx))
29182919
goto error_return;
29192920

2920-
actx->errctx = "failed to obtain access token";
2921+
actx->errctx = libpq_gettext("failed to obtain access token");
29212922
if (!start_token_request(actx, conn))
29222923
goto error_return;
29232924

@@ -2968,7 +2969,7 @@ pg_fe_run_oauth_flow_impl(PGconn *conn)
29682969
break;
29692970

29702971
case OAUTH_STEP_WAIT_INTERVAL:
2971-
actx->errctx = "failed to obtain access token";
2972+
actx->errctx = libpq_gettext("failed to obtain access token");
29722973
if (!start_token_request(actx, conn))
29732974
goto error_return;
29742975

@@ -2994,7 +2995,7 @@ pg_fe_run_oauth_flow_impl(PGconn *conn)
29942995
* also the documentation for struct async_ctx.
29952996
*/
29962997
if (actx->errctx)
2997-
appendPQExpBuffer(errbuf, "%s: ", libpq_gettext(actx->errctx));
2998+
appendPQExpBuffer(errbuf, "%s: ", actx->errctx);
29982999

29993000
if (PQExpBufferDataBroken(actx->errbuf))
30003001
appendPQExpBufferStr(errbuf, libpq_gettext("out of memory"));

src/interfaces/libpq/nls.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# src/interfaces/libpq/nls.mk
22
CATALOG_NAME = libpq
33
GETTEXT_FILES = fe-auth.c \
4+
fe-auth-oauth.c \
45
fe-auth-scram.c \
56
fe-cancel.c \
67
fe-connect.c \

0 commit comments

Comments
 (0)