git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH i18n 03/11] i18n: parseopt: lookup help and argument translations when showing usage

From
Jonathan Nieder <jrnieder@gmail.com>
Date
Apr 16, 2012, 17:54 UTC
Message-ID
<20120416175402.GV5813@burratino>
In-Reply-To
<1334580603-11577-4-git-send-email-pclouds@gmail.com>
Hi again,
Nguyễn Thái Ngọc Duy wrote:
> --- a/parse-options.c
> +++ b/parse-options.c
> @@ -490,7 +490,7 @@ static int usage_argh(const struct option *opts, FILE *outfile)

The interesting parts in this patch are strings not marked for translation:

>  			s = literal ? "[%s]" : "[<%s>]";
>  	else
>  		s = literal ? " %s" : " <%s>";
That means the usage message will have one of the formats
	--foo[=<bar>]
	-f[<bar>]
	--foo <bar>
	-f <bar>
in all languages.  Makes sense.
> -	return fprintf(outfile, s, opts->argh ? opts->argh : "...");
> +	return fprintf(outfile, s, opts->argh ? _(opts->argh) : "...");

"bar" becomes "..." in all languages when the caller was too lazy to fill it in. I wonder if we should not just require argh to be non-NULL for options that can take an argument and catch mistakes in parse_options_check().

Show 6 quoted lines
> @@ -508,13 +508,12 @@ static int usage_with_options_internal(struct parse_opt_ctx_t *ctx,
>  	if (!err && ctx && ctx->flags & PARSE_OPT_SHELL_EVAL)
>  		fprintf(outfile, "cat <<\\EOF\n");
>  
> -	fprintf(outfile, "usage: %s\n",
> +	fprintf_ln(outfile, _("usage: %s"),

It's too bad this doesn't share code with usage.c. :) The prompt will be translated in some contexts and not in others, which seems fine.

> -                                   *usagestr++);
> +                                   _(*usagestr++));

Maybe this change belongs in a separate patch that would mark the usage strings with N_ at the same time. (*)

>  	while (*usagestr && **usagestr)
> -		fprintf(outfile, "   or: %s\n", *usagestr++);
> +		fprintf_ln(outfile, _("   or: %s"), _(*usagestr++));
Maybe worth a translators note to explain how these line up.
Show 6 quoted lines
>  	while (*usagestr) {
> -		fprintf(outfile, "%s%s\n",
> -				**usagestr ? "    " : "",
> -				*usagestr);
> +		fprintf(outfile, "%s%s\n", **usagestr ? "    " : "",
> +			_(*usagestr));
Mph, the space is going to look wrong in other languages.
Show 9 quoted lines
>  		usagestr++;
>  	}
>  
> @@ -528,7 +527,7 @@ static int usage_with_options_internal(struct parse_opt_ctx_t *ctx,
>  		if (opts->type == OPTION_GROUP) {
>  			fputc('\n', outfile);
>  			if (*opts->help)
> -				fprintf(outfile, "%s\n", opts->help);
> +				fprintf(outfile, "%s\n", _(opts->help));
[...]
Show 6 quoted lines
> @@ -558,7 +557,7 @@ static int usage_with_options_internal(struct parse_opt_ctx_t *ctx,
>  			fputc('\n', outfile);
>  			pad = USAGE_OPTS_WIDTH;
>  		}
> -		fprintf(outfile, "%*s%s\n", pad + USAGE_GAP, "", opts->help);
> +		fprintf(outfile, "%*s%s\n", pad + USAGE_GAP, "", _(opts->help));
[...]
Show 15 quoted lines
> --- a/parse-options.h
> +++ b/parse-options.h
> @@ -66,12 +66,14 @@ typedef int parse_opt_ll_cb(struct parse_opt_ctx_t *ctx,
>   *
>   * `argh`::
>   *   token to explain the kind of argument this option wants. Keep it
> - *   homogeneous across the repository.
> + *   homogeneous across the repository. Should be wrapped by N_() for
> + *   translation.
>   *
>   * `help`::
>   *   the short help associated to what the option does.
>   *   Must never be NULL (except for OPTION_END).
>   *   OPTION_GROUP uses this pointer to store the group header.
> + *   Should be wrapped by N_() for translation.
[...]
Show 7 quoted lines
> @@ -158,7 +160,8 @@ struct option {
>  #define OPT_BOOLEAN OPT_COUNTUP
>  
>  /* parse_options() will filter out the processed options and leave the
> - * non-option arguments in argv[].
> + * non-option arguments in argv[]. usagestr strings should be marked
> + * for translation with N_().

Also might be worth splitting into a separate patch that adjusts callers to use N_ at the same time. Is there some easy way to catch strings not in the po template that are passed to gettext() using a variable (at runtime)?

Thanks for some food for thought. Jonathan

Previous: Nguyễn Thái Ngọc DuyNext: Jonathan Nieder
Message 7 of 21 in “Mark more strings for translation”
  1. 00/11 Mark more strings for translationNguyễn Thái Ngọc Duy, Apr 16, 2012
  2. 01/11 Add three convenient format printing functions with \n automatically appendedNguyễn Thái Ngọc Duy, Apr 16, 2012
  3. Jonathan NiederApr 16, 2012
  4. Erik Faye-LundApr 17, 2012
  5. 02/11 i18n: mark relative dates for translationNguyễn Thái Ngọc Duy, Apr 16, 2012
  6. 03/11 i18n: parseopt: lookup help and argument translations when showing usageNguyễn Thái Ngọc Duy, Apr 16, 2012
  7. Jonathan NiederApr 16, 2012
  8. Jonathan NiederApr 16, 2012
  9. 04/11 i18n: help: mark parseopt strings for translationNguyễn Thái Ngọc Duy, Apr 16, 2012
  10. 05/11 i18n: help: mark strings for translationNguyễn Thái Ngọc Duy, Apr 16, 2012
  11. Jonathan NiederApr 18, 2012
  12. 06/11 i18n: make warn_dangling_symref() automatically append \nNguyễn Thái Ngọc Duy, Apr 16, 2012
  13. 07/11 i18n: remote: mark strings for translationNguyễn Thái Ngọc Duy, Apr 16, 2012
  14. 08/11 i18n: apply: mark strings for translationNguyễn Thái Ngọc Duy, Apr 16, 2012
  15. 09/11 i18n: apply: update say_patch_name to give translators complete sentenceNguyễn Thái Ngọc Duy, Apr 16, 2012
  16. Zbigniew Jędrzejewski-SzmekApr 22, 2012
  17. Nguyen Thai Ngoc DuyApr 23, 2012
  18. 10/11 i18n: index-pack: mark strings for translationNguyễn Thái Ngọc Duy, Apr 16, 2012
  19. 11/11 i18n: bundle: mark strings for translationNguyễn Thái Ngọc Duy, Apr 16, 2012
  20. Jonathan NiederApr 18, 2012
  21. Nguyen Thai Ngoc DuyApr 22, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.