Skip to content

Commit 9665627

Browse files
pcloudsgitster
authored andcommitted
i18n: help: mark strings for translation
This patch also marks most common commands' synopsis for translation so that "git help" gives a friendly listing. Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7d29afd commit 9665627

File tree

5 files changed

+47
-38
lines changed

5 files changed

+47
-38
lines changed

Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,7 @@ VCSSVN_H += vcs-svn/svndump.h
563563
MISC_H += branch.h
564564
MISC_H += bundle.h
565565
MISC_H += bisect.h
566+
MISC_H += common-cmds.h
566567
MISC_H += fetch-pack.h
567568
MISC_H += thread-utils.h
568569
MISC_H += send-pack.h

builtin/help.c

+24-24
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ static enum help_format parse_help_format(const char *format)
5454
return HELP_FORMAT_INFO;
5555
if (!strcmp(format, "web") || !strcmp(format, "html"))
5656
return HELP_FORMAT_WEB;
57-
die("unrecognized help format '%s'", format);
57+
die(_("unrecognized help format '%s'"), format);
5858
}
5959

6060
static const char *get_man_viewer_info(const char *name)
@@ -82,7 +82,7 @@ static int check_emacsclient_version(void)
8282
ec_process.err = -1;
8383
ec_process.stdout_to_stderr = 1;
8484
if (start_command(&ec_process))
85-
return error("Failed to start emacsclient.");
85+
return error(_("Failed to start emacsclient."));
8686

8787
strbuf_read(&buffer, ec_process.err, 20);
8888
close(ec_process.err);
@@ -95,15 +95,15 @@ static int check_emacsclient_version(void)
9595

9696
if (prefixcmp(buffer.buf, "emacsclient")) {
9797
strbuf_release(&buffer);
98-
return error("Failed to parse emacsclient version.");
98+
return error(_("Failed to parse emacsclient version."));
9999
}
100100

101101
strbuf_remove(&buffer, 0, strlen("emacsclient"));
102102
version = atoi(buffer.buf);
103103

104104
if (version < 22) {
105105
strbuf_release(&buffer);
106-
return error("emacsclient version '%d' too old (< 22).",
106+
return error(_("emacsclient version '%d' too old (< 22)."),
107107
version);
108108
}
109109

@@ -121,7 +121,7 @@ static void exec_woman_emacs(const char *path, const char *page)
121121
path = "emacsclient";
122122
strbuf_addf(&man_page, "(woman \"%s\")", page);
123123
execlp(path, "emacsclient", "-e", man_page.buf, (char *)NULL);
124-
warning("failed to exec '%s': %s", path, strerror(errno));
124+
warning(_("failed to exec '%s': %s"), path, strerror(errno));
125125
}
126126
}
127127

@@ -149,7 +149,7 @@ static void exec_man_konqueror(const char *path, const char *page)
149149
path = "kfmclient";
150150
strbuf_addf(&man_page, "man:%s(1)", page);
151151
execlp(path, filename, "newTab", man_page.buf, (char *)NULL);
152-
warning("failed to exec '%s': %s", path, strerror(errno));
152+
warning(_("failed to exec '%s': %s"), path, strerror(errno));
153153
}
154154
}
155155

@@ -158,15 +158,15 @@ static void exec_man_man(const char *path, const char *page)
158158
if (!path)
159159
path = "man";
160160
execlp(path, "man", page, (char *)NULL);
161-
warning("failed to exec '%s': %s", path, strerror(errno));
161+
warning(_("failed to exec '%s': %s"), path, strerror(errno));
162162
}
163163

164164
static void exec_man_cmd(const char *cmd, const char *page)
165165
{
166166
struct strbuf shell_cmd = STRBUF_INIT;
167167
strbuf_addf(&shell_cmd, "%s %s", cmd, page);
168168
execl("/bin/sh", "sh", "-c", shell_cmd.buf, (char *)NULL);
169-
warning("failed to exec '%s': %s", cmd, strerror(errno));
169+
warning(_("failed to exec '%s': %s"), cmd, strerror(errno));
170170
}
171171

172172
static void add_man_viewer(const char *name)
@@ -206,8 +206,8 @@ static int add_man_viewer_path(const char *name,
206206
if (supported_man_viewer(name, len))
207207
do_add_man_viewer_info(name, len, value);
208208
else
209-
warning("'%s': path for unsupported man viewer.\n"
210-
"Please consider using 'man.<tool>.cmd' instead.",
209+
warning(_("'%s': path for unsupported man viewer.\n"
210+
"Please consider using 'man.<tool>.cmd' instead."),
211211
name);
212212

213213
return 0;
@@ -218,8 +218,8 @@ static int add_man_viewer_cmd(const char *name,
218218
const char *value)
219219
{
220220
if (supported_man_viewer(name, len))
221-
warning("'%s': cmd for supported man viewer.\n"
222-
"Please consider using 'man.<tool>.path' instead.",
221+
warning(_("'%s': cmd for supported man viewer.\n"
222+
"Please consider using 'man.<tool>.path' instead."),
223223
name);
224224
else
225225
do_add_man_viewer_info(name, len, value);
@@ -280,11 +280,11 @@ void list_common_cmds_help(void)
280280
longest = strlen(common_cmds[i].name);
281281
}
282282

283-
puts("The most commonly used git commands are:");
283+
puts(_("The most commonly used git commands are:"));
284284
for (i = 0; i < ARRAY_SIZE(common_cmds); i++) {
285285
printf(" %s ", common_cmds[i].name);
286286
mput_char(' ', longest - strlen(common_cmds[i].name));
287-
puts(common_cmds[i].help);
287+
puts(_(common_cmds[i].help));
288288
}
289289
}
290290

@@ -348,7 +348,7 @@ static void exec_viewer(const char *name, const char *page)
348348
else if (info)
349349
exec_man_cmd(info, page);
350350
else
351-
warning("'%s': unknown man viewer.", name);
351+
warning(_("'%s': unknown man viewer."), name);
352352
}
353353

354354
static void show_man_page(const char *git_cmd)
@@ -365,15 +365,15 @@ static void show_man_page(const char *git_cmd)
365365
if (fallback)
366366
exec_viewer(fallback, page);
367367
exec_viewer("man", page);
368-
die("no man viewer handled the request");
368+
die(_("no man viewer handled the request"));
369369
}
370370

371371
static void show_info_page(const char *git_cmd)
372372
{
373373
const char *page = cmd_to_page(git_cmd);
374374
setenv("INFOPATH", system_path(GIT_INFO_PATH), 1);
375375
execlp("info", "info", "gitman", page, (char *)NULL);
376-
die("no info viewer handled the request");
376+
die(_("no info viewer handled the request"));
377377
}
378378

379379
static void get_html_page_path(struct strbuf *page_path, const char *page)
@@ -384,7 +384,7 @@ static void get_html_page_path(struct strbuf *page_path, const char *page)
384384
/* Check that we have a git documentation directory. */
385385
if (stat(mkpath("%s/git.html", html_path), &st)
386386
|| !S_ISREG(st.st_mode))
387-
die("'%s': not a documentation directory.", html_path);
387+
die(_("'%s': not a documentation directory."), html_path);
388388

389389
strbuf_init(page_path, 0);
390390
strbuf_addf(page_path, "%s/%s.html", html_path, page);
@@ -424,16 +424,16 @@ int cmd_help(int argc, const char **argv, const char *prefix)
424424
parsed_help_format = help_format;
425425

426426
if (show_all) {
427-
printf("usage: %s\n\n", git_usage_string);
428-
list_commands("git commands", &main_cmds, &other_cmds);
429-
printf("%s\n", git_more_info_string);
427+
printf(_("usage: %s%s"), _(git_usage_string), "\n\n");
428+
list_commands(_("git commands"), &main_cmds, &other_cmds);
429+
printf("%s\n", _(git_more_info_string));
430430
return 0;
431431
}
432432

433433
if (!argv[0]) {
434-
printf("usage: %s\n\n", git_usage_string);
434+
printf(_("usage: %s%s"), _(git_usage_string), "\n\n");
435435
list_common_cmds_help();
436-
printf("\n%s\n", git_more_info_string);
436+
printf("\n%s\n", _(git_more_info_string));
437437
return 0;
438438
}
439439

@@ -445,7 +445,7 @@ int cmd_help(int argc, const char **argv, const char *prefix)
445445

446446
alias = alias_lookup(argv[0]);
447447
if (alias && !is_git_command(argv[0])) {
448-
printf("`git %s' is aliased to `%s'\n", argv[0], alias);
448+
printf_ln(_("`git %s' is aliased to `%s'"), argv[0], alias);
449449
return 0;
450450
}
451451

generate-cmdlist.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ do
1616
/^NAME/,/git-'"$cmd"'/H
1717
${
1818
x
19-
s/.*git-'"$cmd"' - \(.*\)/ {"'"$cmd"'", "\1"},/
19+
s/.*git-'"$cmd"' - \(.*\)/ {"'"$cmd"'", N_("\1")},/
2020
p
2121
}' "Documentation/git-$cmd.txt"
2222
done

git.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const char git_usage_string[] =
1313
" <command> [<args>]";
1414

1515
const char git_more_info_string[] =
16-
"See 'git help <command>' for more information on a specific command.";
16+
N_("See 'git help <command>' for more information on a specific command.");
1717

1818
static struct startup_info git_startup_info;
1919
static int use_pager = -1;

help.c

+20-12
Original file line numberDiff line numberDiff line change
@@ -217,17 +217,22 @@ void list_commands(const char *title, struct cmdnames *main_cmds,
217217

218218
if (main_cmds->cnt) {
219219
const char *exec_path = git_exec_path();
220-
printf("available %s in '%s'\n", title, exec_path);
221-
printf("----------------");
220+
printf_ln(_("available %s in '%s'"), title, exec_path);
221+
/* TRANSLATORS: this must align with "available %s in '%s'" */
222+
printf(_("----------------"));
222223
mput_char('-', strlen(title) + strlen(exec_path));
223224
putchar('\n');
224225
pretty_print_string_list(main_cmds, longest);
225226
putchar('\n');
226227
}
227228

228229
if (other_cmds->cnt) {
229-
printf("%s available from elsewhere on your $PATH\n", title);
230-
printf("---------------------------------------");
230+
printf_ln(_("%s available from elsewhere on your $PATH"), title);
231+
/* TRANSLATORS:
232+
* this must align with
233+
* "%s available from elsewhere on your $PATH"
234+
*/
235+
printf(_("---------------------------------------"));
231236
mput_char('-', strlen(title));
232237
putchar('\n');
233238
pretty_print_string_list(other_cmds, longest);
@@ -341,7 +346,7 @@ const char *help_unknown_cmd(const char *cmd)
341346
sizeof(*main_cmds.names), levenshtein_compare);
342347

343348
if (!main_cmds.cnt)
344-
die ("Uh oh. Your system reports no Git commands at all.");
349+
die(_("Uh oh. Your system reports no Git commands at all."));
345350

346351
/* skip and count prefix matches */
347352
for (n = 0; n < main_cmds.cnt && !main_cmds.names[n]->len; n++)
@@ -362,23 +367,26 @@ const char *help_unknown_cmd(const char *cmd)
362367
const char *assumed = main_cmds.names[0]->name;
363368
main_cmds.names[0] = NULL;
364369
clean_cmdnames(&main_cmds);
365-
fprintf(stderr, "WARNING: You called a Git command named '%s', "
366-
"which does not exist.\n"
367-
"Continuing under the assumption that you meant '%s'\n",
370+
fprintf_ln(stderr,
371+
_("WARNING: You called a Git command named '%s', "
372+
"which does not exist.\n"
373+
"Continuing under the assumption that you meant '%s'"),
368374
cmd, assumed);
369375
if (autocorrect > 0) {
370-
fprintf(stderr, "in %0.1f seconds automatically...\n",
376+
fprintf_ln(stderr, _("in %0.1f seconds automatically..."),
371377
(float)autocorrect/10.0);
372378
poll(NULL, 0, autocorrect * 100);
373379
}
374380
return assumed;
375381
}
376382

377-
fprintf(stderr, "git: '%s' is not a git command. See 'git --help'.\n", cmd);
383+
fprintf_ln(stderr, _("git: '%s' is not a git command. See 'git --help'."), cmd);
378384

379385
if (SIMILAR_ENOUGH(best_similarity)) {
380-
fprintf(stderr, "\nDid you mean %s?\n",
381-
n < 2 ? "this": "one of these");
386+
fprintf_ln(stderr,
387+
Q_("\nDid you mean this?",
388+
"\nDid you mean one of these?",
389+
n));
382390

383391
for (i = 0; i < n; i++)
384392
fprintf(stderr, "\t%s\n", main_cmds.names[i]->name);

0 commit comments

Comments
 (0)