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

[PATCH 3/5] i18n: parseopt: lookup help and argument translations when showing usage

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Mar 8, 2012, 09:16 UTC
Message-ID
<1331198198-22409-4-git-send-email-pclouds@gmail.com>
In-Reply-To
<1331198198-22409-1-git-send-email-pclouds@gmail.com>

"struct option" and the help usage array needs N_() marking on help and argument text for this to work.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 parse-options.c |   15 +++++++--------
 1 files changed, 7 insertions(+), 8 deletions(-)
diff --git a/parse-options.c b/parse-options.c
index 850cfa7..6247c20 100644
--- a/parse-options.c
+++ b/parse-options.c
@@ -490,7 +490,7 @@ static int usage_argh(const struct option *opts, FILE *outfile)
 			s = literal ? "[%s]" : "[<%s>]";
 	else
 		s = literal ? " %s" : " <%s>";
-	return fprintf(outfile, s, opts->argh ? opts->argh : "...");
+	return fprintf(outfile, s, opts->argh ? gettext(opts->argh) : "...");
 }
 
 #define USAGE_OPTS_WIDTH 24
@@ -508,13 +508,12 @@ static int usage_with_options_internal(struct parse_opt_ctx_t *ctx,
 	if (!err && ctx && ctx->flags & PARSE_OPT_SHELL_EVAL)
 		fprintf(outfile, "cat <<\\EOF\n");
 
-	fprintf(outfile, "usage: %s\n", *usagestr++);
+	fprintf(outfile, _("usage: %s\n"), gettext(*usagestr++));
 	while (*usagestr && **usagestr)
-		fprintf(outfile, "   or: %s\n", *usagestr++);
+		fprintf(outfile, _("   or: %s\n"), gettext(*usagestr++));
 	while (*usagestr) {
-		fprintf(outfile, "%s%s\n",
-				**usagestr ? "    " : "",
-				*usagestr);
+		fprintf(outfile, "%s%s\n", **usagestr ? "    " : "",
+			gettext(*usagestr));
 		usagestr++;
 	}
 
@@ -528,7 +527,7 @@ static int usage_with_options_internal(struct parse_opt_ctx_t *ctx,
 		if (opts->type == OPTION_GROUP) {
 			fputc('\n', outfile);
 			if (*opts->help)
-				fprintf(outfile, "%s\n", opts->help);
+				fprintf(outfile, "%s\n", gettext(opts->help));
 			continue;
 		}
 		if (!full && (opts->flags & PARSE_OPT_HIDDEN))
@@ -558,7 +557,7 @@ static int usage_with_options_internal(struct parse_opt_ctx_t *ctx,
 			fputc('\n', outfile);
 			pad = USAGE_OPTS_WIDTH;
 		}
-		fprintf(outfile, "%*s%s\n", pad + USAGE_GAP, "", opts->help);
+		fprintf(outfile, "%*s%s\n", pad + USAGE_GAP, "", gettext(opts->help));
 	}
 	fputc('\n', outfile);
 
-- 
1.7.3.1.256.g2539c.dirty
Previous: Nguyen Thai Ngoc DuyNext: Jonathan Nieder
Message 12 of 15 in “i18n-ize relative dates, git-help and parseopt”
  1. 0/5 i18n-ize relative dates, git-help and parseoptNguyễn Thái Ngọc Duy, Mar 8, 2012
  2. 1/5 i18n: keep the last \n even when text is poisonedNguyễn Thái Ngọc Duy, Mar 8, 2012
  3. Jonathan NiederMar 8, 2012
  4. Nguyen Thai Ngoc DuyMar 9, 2012
  5. Nguyen Thai Ngoc DuyMar 9, 2012
  6. Ævar Arnfjörð BjarmasonMar 9, 2012
  7. 2/5 i18n: mark relative dates for translationNguyễn Thái Ngọc Duy, Mar 8, 2012
  8. Jonathan NiederMar 15, 2012
  9. Johannes SixtMar 15, 2012
  10. Jonathan NiederMar 15, 2012
  11. Nguyen Thai Ngoc DuyMar 16, 2012
  12. 3/5 i18n: parseopt: lookup help and argument translations when showing usageNguyễn Thái Ngọc Duy, Mar 8, 2012
  13. Jonathan NiederMar 8, 2012
  14. 4/5 i18n: help: mark parseopt strings for translationNguyễn Thái Ngọc Duy, Mar 8, 2012
  15. 5/5 i18n: help: mark strings for translationNguyễn Thái Ngọc Duy, Mar 8, 2012

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.