NLS handling fixes.

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

NLS handling fixes.

Kyotaro HORIGUCHI-2
Hello. I found that backend's .po file has lines for GUC
descriptions but we won't see them anywhere.

The cause is GetConfigOptionByNum is fogetting to retrieve
translations for texts that have been marked with gettext_noop.

Regarding GUCs, group names, short desc and long desc have
translations so the attached first patch (fix_GUC_nls.patch) let
the translations appear.


Besides GUCs, I found another misuse of gettext_noop in
pg_GSS_recvauth. (2nd fix_GSSerr_nls.patch)

view_query_is_auto_updatable() and most of its caller are making
the same mistake in a similar way. All caller sites require only
translated message but bringing translated message around doesn't
seem good so the attached third patch adds _() to all required
places. (3rd fix_view_updt_nls.patch, 5th fix_vacuumdb_nls.patch)

psql is making a bit different mistake. \gdesc seems intending
the output columns names in NLS string but they actually
aren't. DescribeQuery is using PrintQueryResults but it is
intended to be used only for SendQuery. Replacing it with
printQuery let \gdesc print NLS string but I'm not sure it is the
right thing to fix this. (4th, fix psql_nls.patch)


plperl/plpgsql/tcl have another kind of problem in NLS. It
installs some GUC parameters and their descriptions actually have
a translation but in *its own* po file. So GetConfigOptionByNum
cannot get them. I don't have an idea to fix this for now.

regards.

--
Kyotaro Horiguchi
NTT Open Source Software Center


diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c
index b05fb209bb..7b023c0064 100644
--- a/src/backend/utils/misc/guc.c
+++ b/src/backend/utils/misc/guc.c
@@ -8419,13 +8419,13 @@ GetConfigOptionByNum(int varnum, const char **values, bool *noshow)
  values[2] = NULL;
 
  /* group */
- values[3] = config_group_names[conf->group];
+ values[3] = gettext(config_group_names[conf->group]);
 
  /* short_desc */
- values[4] = conf->short_desc;
+ values[4] = gettext(conf->short_desc);
 
  /* extra_desc */
- values[5] = conf->long_desc;
+ values[5] = gettext(conf->long_desc);
 
  /* context */
  values[6] = GucContext_Names[conf->context];

diff --git a/src/backend/libpq/auth.c b/src/backend/libpq/auth.c
index cecd104b4a..43a93e493a 100644
--- a/src/backend/libpq/auth.c
+++ b/src/backend/libpq/auth.c
@@ -1227,7 +1227,7 @@ pg_GSS_recvauth(Port *port)
  {
  gss_delete_sec_context(&lmin_s, &port->gss->ctx, GSS_C_NO_BUFFER);
  pg_GSS_error(ERROR,
- gettext_noop("accepting GSS security context failed"),
+ gettext("accepting GSS security context failed"),
  maj_stat, min_stat);
  }
 
@@ -1253,7 +1253,7 @@ pg_GSS_recvauth(Port *port)
  maj_stat = gss_display_name(&min_stat, port->gss->name, &gbuf, NULL);
  if (maj_stat != GSS_S_COMPLETE)
  pg_GSS_error(ERROR,
- gettext_noop("retrieving GSS user name failed"),
+ gettext("retrieving GSS user name failed"),
  maj_stat, min_stat);
 
  /*

diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index eb2d33dd86..2ac7eae84b 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -10807,7 +10807,7 @@ ATExecSetRelOptions(Relation rel, List *defList, AlterTableType operation,
  ereport(ERROR,
  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
  errmsg("WITH CHECK OPTION is supported only on automatically updatable views"),
- errhint("%s", view_updatable_error)));
+ errhint("%s", _(view_updatable_error))));
  }
  }
 
diff --git a/src/backend/commands/view.c b/src/backend/commands/view.c
index 7d4511c585..ffb71c0ea7 100644
--- a/src/backend/commands/view.c
+++ b/src/backend/commands/view.c
@@ -502,7 +502,7 @@ DefineView(ViewStmt *stmt, const char *queryString,
  ereport(ERROR,
  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
  errmsg("WITH CHECK OPTION is supported only on automatically updatable views"),
- errhint("%s", view_updatable_error)));
+ errhint("%s", _(view_updatable_error))));
  }
 
  /*

diff --git a/src/bin/psql/common.c b/src/bin/psql/common.c
index b56995925b..1894e812e6 100644
--- a/src/bin/psql/common.c
+++ b/src/bin/psql/common.c
@@ -1640,7 +1640,14 @@ DescribeQuery(const char *query, double *elapsed_msec)
  }
 
  if (OK && results)
- OK = PrintQueryResults(results);
+ {
+ printQueryOpt myopt = pset.popt;
+
+ myopt.nullPrint = NULL;
+ myopt.title = NULL;
+ myopt.translate_header = true;
+ printQuery(results, &myopt, pset.queryFout, false, pset.logfile);
+ }
 
  termPQExpBuffer(&buf);
  }

diff --git a/src/bin/scripts/vacuumdb.c b/src/bin/scripts/vacuumdb.c
index 60f8b1c394..9408b8f869 100644
--- a/src/bin/scripts/vacuumdb.c
+++ b/src/bin/scripts/vacuumdb.c
@@ -371,7 +371,7 @@ vacuum_one_database(const char *dbname, vacuumingOptions *vacopts,
  {
  if (stage != ANALYZE_NO_STAGE)
  printf(_("%s: processing database \"%s\": %s\n"),
-   progname, PQdb(conn), stage_messages[stage]);
+   progname, PQdb(conn), _(stage_messages[stage]));
  else
  printf(_("%s: vacuuming database \"%s\"\n"),
    progname, PQdb(conn));
Reply | Threaded
Open this post in threaded view
|

Re: NLS handling fixes.

Michael Paquier-2
On Fri, Aug 10, 2018 at 03:21:31PM +0900, Kyotaro HORIGUCHI wrote:

> The cause is GetConfigOptionByNum is forgetting to retrieve
> translations for texts that have been marked with gettext_noop.
>
> Regarding GUCs, group names, short desc and long desc have
> translations so the attached first patch (fix_GUC_nls.patch) let
> the translations appear.
>
> Besides GUCs, I found another misuse of gettext_noop in
> pg_GSS_recvauth. (2nd fix_GSSerr_nls.patch)
>
> view_query_is_auto_updatable() and most of its caller are making
> the same mistake in a similar way. All caller sites require only
> translated message but bringing translated message around doesn't
> seem good so the attached third patch adds _() to all required
> places. (3rd fix_view_updt_nls.patch, 5th fix_vacuumdb_nls.patch)
I have been looking at all the things you are proposing here, and it
seems to me that you are right for these.  I lack a bit of knowledge
about the translation of items, but can such things be back-patched?

> psql is making a bit different mistake. \gdesc seems intending
> the output columns names in NLS string but they actually
> aren't. DescribeQuery is using PrintQueryResults but it is
> intended to be used only for SendQuery. Replacing it with
> printQuery let \gdesc print NLS string but I'm not sure it is the
> right thing to fix this. (4th, fix psql_nls.patch)

This one I am not sure though...
--
Michael

signature.asc (849 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: NLS handling fixes.

Alvaro Herrera-9
On 2018-Aug-10, Michael Paquier wrote:

> On Fri, Aug 10, 2018 at 03:21:31PM +0900, Kyotaro HORIGUCHI wrote:
> > The cause is GetConfigOptionByNum is forgetting to retrieve
> > translations for texts that have been marked with gettext_noop.
> >
> > Regarding GUCs, group names, short desc and long desc have
> > translations so the attached first patch (fix_GUC_nls.patch) let
> > the translations appear.
> >
> > Besides GUCs, I found another misuse of gettext_noop in
> > pg_GSS_recvauth. (2nd fix_GSSerr_nls.patch)
> >
> > view_query_is_auto_updatable() and most of its caller are making
> > the same mistake in a similar way. All caller sites require only
> > translated message but bringing translated message around doesn't
> > seem good so the attached third patch adds _() to all required
> > places. (3rd fix_view_updt_nls.patch, 5th fix_vacuumdb_nls.patch)
>
> I have been looking at all the things you are proposing here, and it
> seems to me that you are right for these.  I lack a bit of knowledge
> about the translation of items, but can such things be back-patched?

Well, if I understood correctly, the translations would have the
messages already translated -- the problem is that they are not used at
runtime.  So, yes, this should be backpatched.

--
Álvaro Herrera                https://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

Reply | Threaded
Open this post in threaded view
|

Re: NLS handling fixes.

Tom Lane-2
In reply to this post by Michael Paquier-2
Michael Paquier <[hidden email]> writes:
> I have been looking at all the things you are proposing here, and it
> seems to me that you are right for these.  I lack a bit of knowledge
> about the translation of items, but can such things be back-patched?

I would certainly *not* back-patch the GetConfigOptionByNum change,
as that will be a user-visible behavioral change that people will
not be expecting.  We might get away with back-patching the other changes,
but SHOW ALL output seems like something that people might be expecting
not to change drastically in a minor release.

Some general review notes:

* I believe our usual convention is to write _() not gettext().
This patch set is pretty schizophrenic about that.

* In the patch fixing view_query_is_auto_updatable misuse, nothing's
been done to remove the underlying cause of the errors, which IMO
is that the header comment for view_query_is_auto_updatable fails to
specify the return convention.  I'd consider adding a comment along
the lines of

 * view_query_is_auto_updatable - test whether the specified view definition
 * represents an auto-updatable view. Returns NULL (if the view can be updated)
 * or a message string giving the reason that it cannot be.
+*
+* The returned string has not been translated; if it is shown as an error
+* message, the caller should apply _() to translate it.
 *

* Perhaps pg_GSS_error likewise could use a comment saying the error
string must be translated already.  Or we could leave its callers alone
and put the _() into it, but either way the API contract ought to be
written down.

* The proposed patch for psql/common.c seems completely wrong, or at
least it has a lot of side-effects other than enabling header translation,
and I doubt they are desirable.

                        regards, tom lane

Reply | Threaded
Open this post in threaded view
|

Re: NLS handling fixes.

Michael Paquier-2
On Fri, Aug 10, 2018 at 04:50:55PM -0400, Tom Lane wrote:
> I would certainly *not* back-patch the GetConfigOptionByNum change,
> as that will be a user-visible behavioral change that people will
> not be expecting.  We might get away with back-patching the other changes,
> but SHOW ALL output seems like something that people might be expecting
> not to change drastically in a minor release.

Agreed, some folks may rely on that.

> * In the patch fixing view_query_is_auto_updatable misuse, nothing's
> been done to remove the underlying cause of the errors, which IMO
> is that the header comment for view_query_is_auto_updatable fails to
> specify the return convention.  I'd consider adding a comment along
> the lines of
>
>  * view_query_is_auto_updatable - test whether the specified view definition
>  * represents an auto-updatable view. Returns NULL (if the view can be updated)
>  * or a message string giving the reason that it cannot be.
> +*
> +* The returned string has not been translated; if it is shown as an error
> +* message, the caller should apply _() to translate it.
That sounds right.  A similar comment should be added for
view_cols_are_auto_updatable and view_col_is_auto_updatable.

> * Perhaps pg_GSS_error likewise could use a comment saying the error
> string must be translated already.  Or we could leave its callers alone
> and put the _() into it, but either way the API contract ought to be
> written down.

Both things are indeed possible.  As pg_SSPI_error applies translation
beforehand, I have taken the approach to let the caller just apply _().
For two messages that does not matter much one way or another.

> * The proposed patch for psql/common.c seems completely wrong, or at
> least it has a lot of side-effects other than enabling header translation,
> and I doubt they are desirable.

I doubted about it, and at closer look I think that you are right, so +1
for discarding this one.

Attached is a patch which should address all the issues reported and all
the remarks done.  What do you think?
--
Michael

nls-fixes-v2.patch (5K) Download Attachment
signature.asc (849 bytes) Download Attachment
Previous Thread Next Thread