Thread: Rough draft: easier translation of psql help

Rough draft: easier translation of psql help

From
Peter Eisentraut
Date:
One of the main pains in translating PostgreSQL messages is translating
the SQL syntax synopses in psql.  Things like:

msgid ""
"[ WITH [ RECURSIVE ] with_query [, ...] ]\n"
"SELECT [ ALL | DISTINCT [ ON ( expression [, ...] ) ] ]\n"
"    * | expression [ [ AS ] output_name ] [, ...]\n"
"    INTO [ TEMPORARY | TEMP ] [ TABLE ] new_table\n"
"    [ FROM from_item [, ...] ]\n"
"    [ WHERE condition ]\n"
"    [ GROUP BY expression [, ...] ]\n"
"    [ HAVING condition [, ...] ]\n"
"    [ WINDOW window_name AS ( window_definition ) [, ...] ]\n"
"    [ { UNION | INTERSECT | EXCEPT } [ ALL ] select ]\n"
"    [ ORDER BY expression [ ASC | DESC | USING operator ] [ NULLS
{ FIRST | "
"LAST } ] [, ...] ]\n"
"    [ LIMIT { count | ALL } ]\n"
"    [ OFFSET start [ ROW | ROWS ] ]\n"
"    [ FETCH { FIRST | NEXT } [ count ] { ROW | ROWS } ONLY ]\n"
"    [ FOR { UPDATE | SHARE } [ OF table_name [, ...] ] [ NOWAIT ]
[...] ]"

Especially when small things are changed from release to release,
figuring this out on the part of the translator is cumbersome and
error-prone.

Instead of translating the whole string, that is (picking a shorter
example)

N_("ALTER TEXT SEARCH PARSER name RENAME TO newname")

we really only want to translate the placeholders, so it could look like
this:

   appendPQExpBuffer(buf,
                      "ALTER TEXT SEARCH PARSER %s RENAME TO %s",
                      _("name"),
                      _("newname"));

This is what the attached patch produces.

Comments?

Attachment

Re: Rough draft: easier translation of psql help

From
Tom Lane
Date:
Peter Eisentraut <peter_e@gmx.net> writes:
> Instead of translating the whole string, that is (picking a shorter
> example)

> N_("ALTER TEXT SEARCH PARSER name RENAME TO newname")

> we really only want to translate the placeholders, so it could look like
> this:

>    appendPQExpBuffer(buf,
>                       "ALTER TEXT SEARCH PARSER %s RENAME TO %s",
>                       _("name"),
>                       _("newname"));

> This is what the attached patch produces.

Seems like a reasonable idea.

> Comments?

I'm not sure what the "const" here is good for, and I can think of
some compilers that are likely to get confused too:

> +    void (* const syntaxfunc)(PQExpBuffer);    /* function that prints the syntax associated with it */

Also, are you sure that code to identify the placeholders is robust?
Should you be defending against '%' in the syntax string?
Will the NLS infrastructure remember to build sql_help.c before
looking for strings?
        regards, tom lane


Re: Rough draft: easier translation of psql help

From
Alvaro Herrera
Date:
Peter Eisentraut wrote:

> Instead of translating the whole string, that is (picking a shorter
> example)
> 
> N_("ALTER TEXT SEARCH PARSER name RENAME TO newname")
> 
> we really only want to translate the placeholders, so it could look like
> this:
> 
>    appendPQExpBuffer(buf,
>                       "ALTER TEXT SEARCH PARSER %s RENAME TO %s",
>                       _("name"),
>                       _("newname"));

+1000

Should create_help.pl be run on "make dist"?

-- 
Alvaro Herrera                                http://www.CommandPrompt.com/
PostgreSQL Replication, Consulting, Custom Development, 24x7 support


Re: Rough draft: easier translation of psql help

From
Josh Berkus
Date:
Peter,

> This is what the attached patch produces.
> 
> Comments?

This is how other project handle transation of these kinds of strings.

-- 
Josh Berkus
PostgreSQL Experts Inc.
www.pgexperts.com


Re: Rough draft: easier translation of psql help

From
Peter Eisentraut
Date:
On Sun, 2009-09-13 at 23:46 -0400, Alvaro Herrera wrote:
> Should create_help.pl be run on "make dist"?

It is.