i18n: parseopt: lookup help and argument translations when showing usage

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nguyễn Thái Ngọc Duy committed May 6, 2012 at 21:23 UTC 54e6dc7daf8e4160d5ec5d2742ae09d416126a1b
2 files changed +25 -19
parse-options.c
+11 -8
@@ -490,7 +490,7 @@ static int usage_argh(const struct option *opts, FILE *outfile)
490 s = literal ? "[%s]" : "[<%s>]";
491 else
492 s = literal ? " %s" : " <%s>";
493 - return fprintf(outfile, s, opts->argh ? opts->argh : "...");
493 + return fprintf(outfile, s, opts->argh ? _(opts->argh) : _("..."));
494 }
495
496 #define USAGE_OPTS_WIDTH 24
@@ -508,13 +508,16 @@ static int usage_with_options_internal(struct parse_opt_ctx_t *ctx,
508 if (!err && ctx && ctx->flags & PARSE_OPT_SHELL_EVAL)
509 fprintf(outfile, "cat <<\\EOF\n");
510
511 - fprintf(outfile, "usage: %s\n", *usagestr++);
511 + fprintf_ln(outfile, _("usage: %s"), _(*usagestr++));
512 while (*usagestr && **usagestr)
513 - fprintf(outfile, " or: %s\n", *usagestr++);
513 + /* TRANSLATORS: the colon here should align with the
514 + one in "usage: %s" translation */
515 + fprintf_ln(outfile, _(" or: %s"), _(*usagestr++));
516 while (*usagestr) {
515 - fprintf(outfile, "%s%s\n",
516 - **usagestr ? " " : "",
517 - *usagestr);
517 + if (**usagestr)
518 + fprintf_ln(outfile, _(" %s"), _(*usagestr));
519 + else
520 + putchar('\n');
521 usagestr++;
522 }
523
@@ -528,7 +531,7 @@ static int usage_with_options_internal(struct parse_opt_ctx_t *ctx,
531 if (opts->type == OPTION_GROUP) {
532 fputc('\n', outfile);
533 if (*opts->help)
531 - fprintf(outfile, "%s\n", opts->help);
534 + fprintf(outfile, "%s\n", _(opts->help));
535 continue;
536 }
537 if (!full && (opts->flags & PARSE_OPT_HIDDEN))
@@ -558,7 +561,7 @@ static int usage_with_options_internal(struct parse_opt_ctx_t *ctx,
561 fputc('\n', outfile);
562 pad = USAGE_OPTS_WIDTH;
563 }
561 - fprintf(outfile, "%*s%s\n", pad + USAGE_GAP, "", opts->help);
564 + fprintf(outfile, "%*s%s\n", pad + USAGE_GAP, "", _(opts->help));
565 }
566 fputc('\n', outfile);
567
parse-options.h
+14 -11
@@ -66,12 +66,14 @@ typedef int parse_opt_ll_cb(struct parse_opt_ctx_t *ctx,
66 *
67 * `argh`::
68 * token to explain the kind of argument this option wants. Keep it
69 - * homogeneous across the repository.
69 + * homogeneous across the repository. Should be wrapped by N_() for
70 + * translation.
71 *
72 * `help`::
73 * the short help associated to what the option does.
74 * Must never be NULL (except for OPTION_END).
75 * OPTION_GROUP uses this pointer to store the group header.
76 + * Should be wrapped by N_() for translation.
77 *
78 * `flags`::
79 * mask of parse_opt_option_flags.
@@ -128,7 +130,7 @@ struct option {
130 #define OPT_BOOL(s, l, v, h) OPT_SET_INT(s, l, v, h, 1)
131 #define OPT_SET_PTR(s, l, v, h, p) { OPTION_SET_PTR, (s), (l), (v), NULL, \
132 (h), PARSE_OPT_NOARG, NULL, (p) }
131 -#define OPT_INTEGER(s, l, v, h) { OPTION_INTEGER, (s), (l), (v), "n", (h) }
133 +#define OPT_INTEGER(s, l, v, h) { OPTION_INTEGER, (s), (l), (v), N_("n"), (h) }
134 #define OPT_STRING(s, l, v, a, h) { OPTION_STRING, (s), (l), (v), (a), (h) }
135 #define OPT_STRING_LIST(s, l, v, a, h) \
136 { OPTION_CALLBACK, (s), (l), (v), (a), \
@@ -136,7 +138,7 @@ struct option {
138 #define OPT_UYN(s, l, v, h) { OPTION_CALLBACK, (s), (l), (v), NULL, \
139 (h), PARSE_OPT_NOARG, &parse_opt_tertiary }
140 #define OPT_DATE(s, l, v, h) \
139 - { OPTION_CALLBACK, (s), (l), (v), "time",(h), 0, \
141 + { OPTION_CALLBACK, (s), (l), (v), N_("time"),(h), 0, \
142 parse_opt_approxidate_cb }
143 #define OPT_CALLBACK(s, l, v, a, h, f) \
144 { OPTION_CALLBACK, (s), (l), (v), (a), (h), 0, (f) }
@@ -144,21 +146,22 @@ struct option {
146 { OPTION_NUMBER, 0, NULL, (v), NULL, (h), \
147 PARSE_OPT_NOARG | PARSE_OPT_NONEG, (f) }
148 #define OPT_FILENAME(s, l, v, h) { OPTION_FILENAME, (s), (l), (v), \
147 - "file", (h) }
149 + N_("file"), (h) }
150 #define OPT_COLOR_FLAG(s, l, v, h) \
149 - { OPTION_CALLBACK, (s), (l), (v), "when", (h), PARSE_OPT_OPTARG, \
151 + { OPTION_CALLBACK, (s), (l), (v), N_("when"), (h), PARSE_OPT_OPTARG, \
152 parse_opt_color_flag_cb, (intptr_t)"always" }
153
154 #define OPT_NOOP_NOARG(s, l) \
155 { OPTION_CALLBACK, (s), (l), NULL, NULL, \
154 - "no-op (backward compatibility)", \
156 + N_("no-op (backward compatibility)"), \
157 PARSE_OPT_HIDDEN | PARSE_OPT_NOARG, parse_opt_noop_cb }
158
159 /* Deprecated synonym */
160 #define OPT_BOOLEAN OPT_COUNTUP
161
162 /* parse_options() will filter out the processed options and leave the
161 - * non-option arguments in argv[].
163 + * non-option arguments in argv[]. usagestr strings should be marked
164 + * for translation with N_().
165 * Returns the number of arguments left in argv[].
166 */
167 extern int parse_options(int argc, const char **argv, const char *prefix,
@@ -222,15 +225,15 @@ extern int parse_opt_noop_cb(const struct option *, const char *, int);
225 #define OPT__VERBOSE(var, h) OPT_BOOLEAN('v', "verbose", (var), (h))
226 #define OPT__QUIET(var, h) OPT_BOOLEAN('q', "quiet", (var), (h))
227 #define OPT__VERBOSITY(var) \
225 - { OPTION_CALLBACK, 'v', "verbose", (var), NULL, "be more verbose", \
228 + { OPTION_CALLBACK, 'v', "verbose", (var), NULL, N_("be more verbose"), \
229 PARSE_OPT_NOARG, &parse_opt_verbosity_cb, 0 }, \
227 - { OPTION_CALLBACK, 'q', "quiet", (var), NULL, "be more quiet", \
230 + { OPTION_CALLBACK, 'q', "quiet", (var), NULL, N_("be more quiet"), \
231 PARSE_OPT_NOARG, &parse_opt_verbosity_cb, 0 }
232 #define OPT__DRY_RUN(var, h) OPT_BOOLEAN('n', "dry-run", (var), (h))
233 #define OPT__FORCE(var, h) OPT_BOOLEAN('f', "force", (var), (h))
234 #define OPT__ABBREV(var) \
232 - { OPTION_CALLBACK, 0, "abbrev", (var), "n", \
233 - "use <n> digits to display SHA-1s", \
235 + { OPTION_CALLBACK, 0, "abbrev", (var), N_("n"), \
236 + N_("use <n> digits to display SHA-1s"), \
237 PARSE_OPT_OPTARG, &parse_opt_abbrev_cb, 0 }
238 #define OPT__COLOR(var, h) \
239 OPT_COLOR_FLAG(0, "color", (var), (h))