git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[RFC/PATCH] i18n of multi-line messages

From
Junio C Hamano <gitster@pobox.com>
Date
Dec 21, 2011, 23:55 UTC
Message-ID
<7vr4zxeaz5.fsf@alter.siamese.dyndns.org>

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
 - append each line in the result to localization of the "hint: " prefix.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 advice.c         |   23 ++++++++++++++++-------
 builtin/revert.c |    9 ++++-----
 2 files changed, 20 insertions(+), 12 deletions(-)
diff --git a/advice.c b/advice.c
index e02e632..fcdf66a 100644
--- a/advice.c
+++ b/advice.c
@@ -21,11 +21,21 @@ static struct {
 
 void advise(const char *advice, ...)
 {
+	struct strbuf buf = STRBUF_INIT;
 	va_list params;
+	const char *cp, *np;
 
 	va_start(params, advice);
-	vreportf("hint: ", advice, params);
+	strbuf_addf(&buf, advice, params);
 	va_end(params);
+
+	for (cp = buf.buf; *cp; cp = np) {
+		np = strchrnul(cp, '\n');
+		fprintf(stderr, "%s%.*s\n", _("hint: "), (int)(np - cp), cp);
+		if (*np)
+			np++;
+	}
+	strbuf_release(&buf);
 }
 
 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)
 int error_resolve_conflict(const char *me)
 {
 	error("'%s' is not possible because you have unmerged files.", me);
-	if (advice_resolve_conflict) {
+	if (advice_resolve_conflict)
 		/*
 		 * Message used both when 'git commit' fails and when
 		 * other commands doing a merge do.
 		 */
-		advise("Fix them up in the work tree,");
-		advise("and then use 'git add/rm <file>' as");
-		advise("appropriate to mark resolution and make a commit,");
-		advise("or use 'git commit -a'.");
-	}
+		advise(_("Fix them up in the work tree,\n"
+			 "and then use 'git add/rm <file>' as\n"
+			 "appropriate to mark resolution and make a commit,\n"
+			 "or use 'git commit -a'."));
 	return -1;
 }
 
diff --git a/builtin/revert.c b/builtin/revert.c
index fce3f92..440d2be 100644
--- a/builtin/revert.c
+++ b/builtin/revert.c
@@ -343,11 +343,10 @@ static void print_advice(int show_hint)
 		return;
 	}
 
-	if (show_hint) {
-		advise("after resolving the conflicts, mark the corrected paths");
-		advise("with 'git add <paths>' or 'git rm <paths>'");
-		advise("and commit the result with 'git commit'");
-	}
+	if (show_hint)
+		advise(_("after resolving the conflicts, mark the corrected paths\n"
+			 "with 'git add <paths>' or 'git rm <paths>'\n"
+			 "and commit the result with 'git commit'"));
 }
 
 static void write_message(struct strbuf *msgbuf, const char *filename)
Next: Ævar Arnfjörð Bjarmason
Message 1 of 15 in “i18n of multi-line messages”
  1. i18n of multi-line messagesJunio C Hamano, Dec 21, 2011
  2. Ævar Arnfjörð BjarmasonDec 22, 2011
  3. Junio C HamanoDec 22, 2011
  4. Thomas RastDec 22, 2011
  5. Johannes SixtDec 22, 2011
  6. Junio C HamanoDec 22, 2011
  7. Junio C HamanoDec 22, 2011
  8. Junio C HamanoDec 22, 2011
  9. Johannes SixtDec 22, 2011
  10. Junio C HamanoDec 22, 2011
  11. Johannes SixtDec 23, 2011
  12. Junio C HamanoDec 23, 2011
  13. Chris PackhamDec 22, 2011
  14. Andreas SchwabDec 22, 2011
  15. Ævar Arnfjörð BjarmasonDec 22, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.