Skip to content

Commit c0b5c62

Browse files
committed
Merge branch 'nd/i18n-parseopt'
Text from "git cmd --help" are getting prepared for i18n. By Nguyễn Thái Ngọc Duy * nd/i18n-parseopt: i18n: apply: mark parseopt strings for translation i18n: parseopt: lookup help and argument translations when showing usage
2 parents 2e464dd + de37393 commit c0b5c62

File tree

3 files changed

+56
-50
lines changed

3 files changed

+56
-50
lines changed

builtin/apply.c

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ static const char *fake_ancestor;
5050
static int line_termination = '\n';
5151
static unsigned int p_context = UINT_MAX;
5252
static const char * const apply_usage[] = {
53-
"git apply [options] [<patch>...]",
53+
N_("git apply [options] [<patch>...]"),
5454
NULL
5555
};
5656

@@ -3959,66 +3959,66 @@ int cmd_apply(int argc, const char **argv, const char *prefix_)
39593959
const char *whitespace_option = NULL;
39603960

39613961
struct option builtin_apply_options[] = {
3962-
{ OPTION_CALLBACK, 0, "exclude", NULL, "path",
3963-
"don't apply changes matching the given path",
3962+
{ OPTION_CALLBACK, 0, "exclude", NULL, N_("path"),
3963+
N_("don't apply changes matching the given path"),
39643964
0, option_parse_exclude },
3965-
{ OPTION_CALLBACK, 0, "include", NULL, "path",
3966-
"apply changes matching the given path",
3965+
{ OPTION_CALLBACK, 0, "include", NULL, N_("path"),
3966+
N_("apply changes matching the given path"),
39673967
0, option_parse_include },
3968-
{ OPTION_CALLBACK, 'p', NULL, NULL, "num",
3969-
"remove <num> leading slashes from traditional diff paths",
3968+
{ OPTION_CALLBACK, 'p', NULL, NULL, N_("num"),
3969+
N_("remove <num> leading slashes from traditional diff paths"),
39703970
0, option_parse_p },
39713971
OPT_BOOLEAN(0, "no-add", &no_add,
3972-
"ignore additions made by the patch"),
3972+
N_("ignore additions made by the patch")),
39733973
OPT_BOOLEAN(0, "stat", &diffstat,
3974-
"instead of applying the patch, output diffstat for the input"),
3974+
N_("instead of applying the patch, output diffstat for the input")),
39753975
OPT_NOOP_NOARG(0, "allow-binary-replacement"),
39763976
OPT_NOOP_NOARG(0, "binary"),
39773977
OPT_BOOLEAN(0, "numstat", &numstat,
3978-
"shows number of added and deleted lines in decimal notation"),
3978+
N_("shows number of added and deleted lines in decimal notation")),
39793979
OPT_BOOLEAN(0, "summary", &summary,
3980-
"instead of applying the patch, output a summary for the input"),
3980+
N_("instead of applying the patch, output a summary for the input")),
39813981
OPT_BOOLEAN(0, "check", &check,
3982-
"instead of applying the patch, see if the patch is applicable"),
3982+
N_("instead of applying the patch, see if the patch is applicable")),
39833983
OPT_BOOLEAN(0, "index", &check_index,
3984-
"make sure the patch is applicable to the current index"),
3984+
N_("make sure the patch is applicable to the current index")),
39853985
OPT_BOOLEAN(0, "cached", &cached,
3986-
"apply a patch without touching the working tree"),
3986+
N_("apply a patch without touching the working tree")),
39873987
OPT_BOOLEAN(0, "apply", &force_apply,
3988-
"also apply the patch (use with --stat/--summary/--check)"),
3988+
N_("also apply the patch (use with --stat/--summary/--check)")),
39893989
OPT_FILENAME(0, "build-fake-ancestor", &fake_ancestor,
3990-
"build a temporary index based on embedded index information"),
3990+
N_("build a temporary index based on embedded index information")),
39913991
{ OPTION_CALLBACK, 'z', NULL, NULL, NULL,
3992-
"paths are separated with NUL character",
3992+
N_("paths are separated with NUL character"),
39933993
PARSE_OPT_NOARG, option_parse_z },
39943994
OPT_INTEGER('C', NULL, &p_context,
3995-
"ensure at least <n> lines of context match"),
3996-
{ OPTION_CALLBACK, 0, "whitespace", &whitespace_option, "action",
3997-
"detect new or modified lines that have whitespace errors",
3995+
N_("ensure at least <n> lines of context match")),
3996+
{ OPTION_CALLBACK, 0, "whitespace", &whitespace_option, N_("action"),
3997+
N_("detect new or modified lines that have whitespace errors"),
39983998
0, option_parse_whitespace },
39993999
{ OPTION_CALLBACK, 0, "ignore-space-change", NULL, NULL,
4000-
"ignore changes in whitespace when finding context",
4000+
N_("ignore changes in whitespace when finding context"),
40014001
PARSE_OPT_NOARG, option_parse_space_change },
40024002
{ OPTION_CALLBACK, 0, "ignore-whitespace", NULL, NULL,
4003-
"ignore changes in whitespace when finding context",
4003+
N_("ignore changes in whitespace when finding context"),
40044004
PARSE_OPT_NOARG, option_parse_space_change },
40054005
OPT_BOOLEAN('R', "reverse", &apply_in_reverse,
4006-
"apply the patch in reverse"),
4006+
N_("apply the patch in reverse")),
40074007
OPT_BOOLEAN(0, "unidiff-zero", &unidiff_zero,
4008-
"don't expect at least one line of context"),
4008+
N_("don't expect at least one line of context")),
40094009
OPT_BOOLEAN(0, "reject", &apply_with_reject,
4010-
"leave the rejected hunks in corresponding *.rej files"),
4010+
N_("leave the rejected hunks in corresponding *.rej files")),
40114011
OPT_BOOLEAN(0, "allow-overlap", &allow_overlap,
4012-
"allow overlapping hunks"),
4013-
OPT__VERBOSE(&apply_verbosely, "be verbose"),
4012+
N_("allow overlapping hunks")),
4013+
OPT__VERBOSE(&apply_verbosely, N_("be verbose")),
40144014
OPT_BIT(0, "inaccurate-eof", &options,
4015-
"tolerate incorrectly detected missing new-line at the end of file",
4015+
N_("tolerate incorrectly detected missing new-line at the end of file"),
40164016
INACCURATE_EOF),
40174017
OPT_BIT(0, "recount", &options,
4018-
"do not trust the line counts in the hunk headers",
4018+
N_("do not trust the line counts in the hunk headers"),
40194019
RECOUNT),
4020-
{ OPTION_CALLBACK, 0, "directory", NULL, "root",
4021-
"prepend <root> to all filenames",
4020+
{ OPTION_CALLBACK, 0, "directory", NULL, N_("root"),
4021+
N_("prepend <root> to all filenames"),
40224022
0, option_parse_directory },
40234023
OPT_END()
40244024
};

parse-options.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ static int usage_argh(const struct option *opts, FILE *outfile)
490490
s = literal ? "[%s]" : "[<%s>]";
491491
else
492492
s = literal ? " %s" : " <%s>";
493-
return fprintf(outfile, s, opts->argh ? opts->argh : "...");
493+
return fprintf(outfile, s, opts->argh ? _(opts->argh) : _("..."));
494494
}
495495

496496
#define USAGE_OPTS_WIDTH 24
@@ -508,13 +508,16 @@ static int usage_with_options_internal(struct parse_opt_ctx_t *ctx,
508508
if (!err && ctx && ctx->flags & PARSE_OPT_SHELL_EVAL)
509509
fprintf(outfile, "cat <<\\EOF\n");
510510

511-
fprintf(outfile, "usage: %s\n", *usagestr++);
511+
fprintf_ln(outfile, _("usage: %s"), _(*usagestr++));
512512
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++));
514516
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');
518521
usagestr++;
519522
}
520523

@@ -528,7 +531,7 @@ static int usage_with_options_internal(struct parse_opt_ctx_t *ctx,
528531
if (opts->type == OPTION_GROUP) {
529532
fputc('\n', outfile);
530533
if (*opts->help)
531-
fprintf(outfile, "%s\n", opts->help);
534+
fprintf(outfile, "%s\n", _(opts->help));
532535
continue;
533536
}
534537
if (!full && (opts->flags & PARSE_OPT_HIDDEN))
@@ -558,7 +561,7 @@ static int usage_with_options_internal(struct parse_opt_ctx_t *ctx,
558561
fputc('\n', outfile);
559562
pad = USAGE_OPTS_WIDTH;
560563
}
561-
fprintf(outfile, "%*s%s\n", pad + USAGE_GAP, "", opts->help);
564+
fprintf(outfile, "%*s%s\n", pad + USAGE_GAP, "", _(opts->help));
562565
}
563566
fputc('\n', outfile);
564567

parse-options.h

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,14 @@ typedef int parse_opt_ll_cb(struct parse_opt_ctx_t *ctx,
6666
*
6767
* `argh`::
6868
* 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.
7071
*
7172
* `help`::
7273
* the short help associated to what the option does.
7374
* Must never be NULL (except for OPTION_END).
7475
* OPTION_GROUP uses this pointer to store the group header.
76+
* Should be wrapped by N_() for translation.
7577
*
7678
* `flags`::
7779
* mask of parse_opt_option_flags.
@@ -128,37 +130,38 @@ struct option {
128130
#define OPT_BOOL(s, l, v, h) OPT_SET_INT(s, l, v, h, 1)
129131
#define OPT_SET_PTR(s, l, v, h, p) { OPTION_SET_PTR, (s), (l), (v), NULL, \
130132
(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) }
132134
#define OPT_STRING(s, l, v, a, h) { OPTION_STRING, (s), (l), (v), (a), (h) }
133135
#define OPT_STRING_LIST(s, l, v, a, h) \
134136
{ OPTION_CALLBACK, (s), (l), (v), (a), \
135137
(h), 0, &parse_opt_string_list }
136138
#define OPT_UYN(s, l, v, h) { OPTION_CALLBACK, (s), (l), (v), NULL, \
137139
(h), PARSE_OPT_NOARG, &parse_opt_tertiary }
138140
#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, \
140142
parse_opt_approxidate_cb }
141143
#define OPT_CALLBACK(s, l, v, a, h, f) \
142144
{ OPTION_CALLBACK, (s), (l), (v), (a), (h), 0, (f) }
143145
#define OPT_NUMBER_CALLBACK(v, h, f) \
144146
{ OPTION_NUMBER, 0, NULL, (v), NULL, (h), \
145147
PARSE_OPT_NOARG | PARSE_OPT_NONEG, (f) }
146148
#define OPT_FILENAME(s, l, v, h) { OPTION_FILENAME, (s), (l), (v), \
147-
"file", (h) }
149+
N_("file"), (h) }
148150
#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, \
150152
parse_opt_color_flag_cb, (intptr_t)"always" }
151153

152154
#define OPT_NOOP_NOARG(s, l) \
153155
{ OPTION_CALLBACK, (s), (l), NULL, NULL, \
154-
"no-op (backward compatibility)", \
156+
N_("no-op (backward compatibility)"), \
155157
PARSE_OPT_HIDDEN | PARSE_OPT_NOARG, parse_opt_noop_cb }
156158

157159
/* Deprecated synonym */
158160
#define OPT_BOOLEAN OPT_COUNTUP
159161

160162
/* 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_().
162165
* Returns the number of arguments left in argv[].
163166
*/
164167
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);
222225
#define OPT__VERBOSE(var, h) OPT_BOOLEAN('v', "verbose", (var), (h))
223226
#define OPT__QUIET(var, h) OPT_BOOLEAN('q', "quiet", (var), (h))
224227
#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"), \
226229
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"), \
228231
PARSE_OPT_NOARG, &parse_opt_verbosity_cb, 0 }
229232
#define OPT__DRY_RUN(var, h) OPT_BOOLEAN('n', "dry-run", (var), (h))
230233
#define OPT__FORCE(var, h) OPT_BOOLEAN('f', "force", (var), (h))
231234
#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"), \
234237
PARSE_OPT_OPTARG, &parse_opt_abbrev_cb, 0 }
235238
#define OPT__COLOR(var, h) \
236239
OPT_COLOR_FLAG(0, "color", (var), (h))

0 commit comments

Comments
 (0)