[PATCH i18n 03/11] i18n: parseopt: lookup help and argument translations when showing usage
From: Nguyễn Thái Ngọc Duy <hidden>
Date: 2016-06-15 22:53:36
Subsystem:
the rest · Maintainer:
Linus Torvalds
--- parse-options.c | 15 +++++++-------- parse-options.h | 7 +++++-- 2 files changed, 12 insertions(+), 10 deletions(-)
diff --git a/parse-options.c b/parse-options.c
index 850cfa7..7690de8 100644
--- a/parse-options.c
+++ b/parse-options.c@@ -490,7 +490,7 @@ static int usage_argh(const struct option *opts, FILE *outfile) s = literal ? "[%s]" : "[<%s>]"; else s = literal ? " %s" : " <%s>"; - return fprintf(outfile, s, opts->argh ? opts->argh : "..."); + return fprintf(outfile, s, opts->argh ? _(opts->argh) : "..."); } #define USAGE_OPTS_WIDTH 24
@@ -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", *usagestr++); + fprintf_ln(outfile, _("usage: %s"), _(*usagestr++)); while (*usagestr && **usagestr) - fprintf(outfile, " or: %s\n", *usagestr++); + fprintf_ln(outfile, _(" or: %s"), _(*usagestr++)); while (*usagestr) { - fprintf(outfile, "%s%s\n", - **usagestr ? " " : "", - *usagestr); + fprintf(outfile, "%s%s\n", **usagestr ? " " : "", + _(*usagestr)); 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)); continue; } if (!full && (opts->flags & PARSE_OPT_HIDDEN))
@@ -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)); } fputc('\n', outfile);
diff --git a/parse-options.h b/parse-options.h
index def9ced..4e59f2c 100644
--- 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. * * `flags`:: * mask of parse_opt_option_flags.
@@ -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_(). * Returns the number of arguments left in argv[]. */ extern int parse_options(int argc, const char **argv, const char *prefix,
--
1.7.3.1.256.g2539c.dirty