[GRASS-dev] translated options in descriptions

Hi all,

I would like to point out that there was a bug in many modules (around
30) which can appear only with localised grass (fixed r52637). It
produces only warning so probably it's harmless however developers
should avoid using option descriptions in this way:

- params->query->descriptions =
- _("length;Select only lines or boundaries shorter"
- "/longer than threshold distance;"
- "dangle;Select dangles shorter/longer than " "threshold distance");

The problems appear when the translator translates the option and not
only its description. Translatable must be only the description like
this,

+ desc_query = NULL;
+ G_asprintf(&desc_query,
+ "length;%s;"
+ "dangle;%s",
+ _("Select only lines or boundaries shorter"
+ "/longer than threshold distance"),
+ _("Select dangles shorter/longer than threshold distance"));
+ params->query->descriptions = desc_query;

Best regards,
Anna

Anna wrote:

I would like to point out that there was a bug in many
modules (around 30) which can appear only with localised grass
(fixed r52637). It produces only warning so probably it's
harmless however developers should avoid using option
descriptions in this way:

- params->query->descriptions =
- _("length;Select only lines or boundaries shorter"
- "/longer than threshold distance;"
- "dangle;Select dangles shorter/longer than " "threshold distance");

The problems appear when the translator translates the
option and not only its description. Translatable must be only
the description like this,

+ desc_query = NULL;
+ G_asprintf(&desc_query,
+ "length;%s;"
+ "dangle;%s",
+ _("Select only lines or boundaries shorter"
+ "/longer than threshold distance"),
+ _("Select dangles shorter/longer than threshold distance"));
+ params->query->descriptions = desc_query;

is it a problem that G_asprint() can, in some rare cases, call
G_fatal_error() (via G_calloc()) before G_parser() has been
run? or is G_define_module() the critical fn to get past in that
regard?

best,
Hamish

Hamish wrote:

> I would like to point out that there was a bug in many
> modules (around 30) which can appear only with localised grass
> (fixed r52637). It produces only warning so probably it's
> harmless however developers should avoid using option
> descriptions in this way:
>
> - params->query->descriptions =
> - _("length;Select only lines or boundaries shorter"
> - "/longer than threshold distance;"
> - "dangle;Select dangles shorter/longer than " "threshold distance");
>
> The problems appear when the translator translates the
> option and not only its description. Translatable must be only
> the description like this,
>
> + desc_query = NULL;
> + G_asprintf(&desc_query,
> + "length;%s;"
> + "dangle;%s",
> + _("Select only lines or boundaries shorter"
> + "/longer than threshold distance"),
> + _("Select dangles shorter/longer than threshold distance"));
> + params->query->descriptions = desc_query;

is it a problem that G_asprint() can, in some rare cases, call
G_fatal_error() (via G_calloc()) before G_parser() has been
run? or is G_define_module() the critical fn to get past in that
regard?

I think that G_gisinit() should be sufficient. That calls
G_set_program_name(), which has historically been at the root of the
problems with early errors.

But this would be a good opportunity to fix what appears to be a
fundamental design flaw in the ->descriptions interface rather than
just work around it.

I would suggest replacing the above code with e.g.:

  G_option_descs(params->query,
   "length", _("Select only lines or boundaries shorter"
   "/longer than threshold distance"),
   "dangle", _("Select dangles shorter/longer than threshold distance"),
            NULL);

G_option_descs() would either construct the necessary ->descriptions
string, or (preferably) just fill in the ->descs field directly,
eliminating the need for the ->descriptions field altogether.

--
Glynn Clements <glynn@gclements.plus.com>