All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Nieder <jrnieder@gmail.com>
To: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Cc: git@vger.kernel.org, "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>,
	"Jiang Xin" <worldhello.net@gmail.com>
Subject: Re: [PATCH i18n 03/11] i18n: parseopt: lookup help and argument translations when showing usage
Date: Mon, 16 Apr 2012 12:54:02 -0500	[thread overview]
Message-ID: <20120416175402.GV5813@burratino> (raw)
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().

> @@ -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.

>  	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.

>  		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));
[...]
> @@ -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));
[...]
> --- 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.
[...]
> @@ -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

  reply	other threads:[~2012-04-16 17:54 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-16 12:49 [PATCH i18n 00/11] Mark more strings for translation Nguyễn Thái Ngọc Duy
2012-04-16 12:49 ` [PATCH i18n 01/11] Add three convenient format printing functions with \n automatically appended Nguyễn Thái Ngọc Duy
2012-04-16 17:26   ` Jonathan Nieder
2012-04-17  8:12   ` Erik Faye-Lund
2012-04-16 12:49 ` [PATCH i18n 02/11] i18n: mark relative dates for translation Nguyễn Thái Ngọc Duy
2012-04-16 12:49 ` [PATCH i18n 03/11] i18n: parseopt: lookup help and argument translations when showing usage Nguyễn Thái Ngọc Duy
2012-04-16 17:54   ` Jonathan Nieder [this message]
2012-04-16 23:35     ` Jonathan Nieder
2012-04-16 12:49 ` [PATCH i18n 04/11] i18n: help: mark parseopt strings for translation Nguyễn Thái Ngọc Duy
2012-04-16 12:49 ` [PATCH i18n 05/11] i18n: help: mark " Nguyễn Thái Ngọc Duy
2012-04-18 19:30   ` Jonathan Nieder
2012-04-16 12:49 ` [PATCH i18n 06/11] i18n: make warn_dangling_symref() automatically append \n Nguyễn Thái Ngọc Duy
2012-04-16 12:49 ` [PATCH i18n 07/11] i18n: remote: mark strings for translation Nguyễn Thái Ngọc Duy
2012-04-16 12:50 ` [PATCH i18n 08/11] i18n: apply: " Nguyễn Thái Ngọc Duy
2012-04-16 12:50 ` [PATCH i18n 09/11] i18n: apply: update say_patch_name to give translators complete sentence Nguyễn Thái Ngọc Duy
2012-04-22 16:42   ` Zbigniew Jędrzejewski-Szmek
2012-04-23 11:33     ` Nguyen Thai Ngoc Duy
2012-04-16 12:50 ` [PATCH i18n 10/11] i18n: index-pack: mark strings for translation Nguyễn Thái Ngọc Duy
2012-04-16 12:50 ` [PATCH i18n 11/11] i18n: bundle: " Nguyễn Thái Ngọc Duy
2012-04-18 19:40 ` [PATCH i18n 00/11] Mark more " Jonathan Nieder
2012-04-22  3:24   ` Nguyen Thai Ngoc Duy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20120416175402.GV5813@burratino \
    --to=jrnieder@gmail.com \
    --cc=avarab@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=pclouds@gmail.com \
    --cc=worldhello.net@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.