Skip to content

Commit 23cb5bf

Browse files
committed
i18n of multi-line advice messages
Advice messages are by definition meant for human end-users, and prime candidates for i18n/l10n. They tend to also be more verbose to be helpful, and need to be longer than just one line. Although we do not have parameterized multi-line advice messages yet, once we do, we cannot emit such a message like this: advise(_("Please rename %s to something else"), gostak); advise(_("so that we can avoid distimming %s unnecessarily."), doshes); because some translations may need to have the replacement of 'gostak' on the second line (or 'doshes' on the first line). Some languages may even need to use three lines in order to fit the same message within a reasonable width. Instead, it has to be a single advise() construct, like this: advise(_("Please rename %s to something else\n" "so that we can avoid distimming %s unnecessarily."), gostak, doshes); Update the advise() function and its existing callers to - take a format string that can be multi-line and translatable as a whole; - use the string and the parameters to form a localized message; and - show each line in the result with the localization of the "hint: ". Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 2ce0edc commit 23cb5bf

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

advice.c

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,21 @@ static struct {
2121

2222
void advise(const char *advice, ...)
2323
{
24+
struct strbuf buf = STRBUF_INIT;
2425
va_list params;
26+
const char *cp, *np;
2527

2628
va_start(params, advice);
27-
vreportf("hint: ", advice, params);
29+
strbuf_addf(&buf, advice, params);
2830
va_end(params);
31+
32+
for (cp = buf.buf; *cp; cp = np) {
33+
np = strchrnul(cp, '\n');
34+
fprintf(stderr, _("hint: %.*s\n"), (int)(np - cp), cp);
35+
if (*np)
36+
np++;
37+
}
38+
strbuf_release(&buf);
2939
}
3040

3141
int git_default_advice_config(const char *var, const char *value)
@@ -46,16 +56,15 @@ int git_default_advice_config(const char *var, const char *value)
4656
int error_resolve_conflict(const char *me)
4757
{
4858
error("'%s' is not possible because you have unmerged files.", me);
49-
if (advice_resolve_conflict) {
59+
if (advice_resolve_conflict)
5060
/*
5161
* Message used both when 'git commit' fails and when
5262
* other commands doing a merge do.
5363
*/
54-
advise("Fix them up in the work tree,");
55-
advise("and then use 'git add/rm <file>' as");
56-
advise("appropriate to mark resolution and make a commit,");
57-
advise("or use 'git commit -a'.");
58-
}
64+
advise(_("Fix them up in the work tree,\n"
65+
"and then use 'git add/rm <file>' as\n"
66+
"appropriate to mark resolution and make a commit,\n"
67+
"or use 'git commit -a'."));
5968
return -1;
6069
}
6170

builtin/revert.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -332,11 +332,10 @@ static void print_advice(int show_hint)
332332
return;
333333
}
334334

335-
if (show_hint) {
336-
advise("after resolving the conflicts, mark the corrected paths");
337-
advise("with 'git add <paths>' or 'git rm <paths>'");
338-
advise("and commit the result with 'git commit'");
339-
}
335+
if (show_hint)
336+
advise(_("after resolving the conflicts, mark the corrected paths\n"
337+
"with 'git add <paths>' or 'git rm <paths>'\n"
338+
"and commit the result with 'git commit'"));
340339
}
341340

342341
static void write_message(struct strbuf *msgbuf, const char *filename)

0 commit comments

Comments
 (0)