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

[PATCH i18n 03/11] i18n: parseopt: lookup help and argument translations when showing usage

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Apr 16, 2012, 12:49 UTC
Message-ID
<1334580603-11577-4-git-send-email-pclouds@gmail.com>
In-Reply-To
<1334580603-11577-1-git-send-email-pclouds@gmail.com>
---
 parse-options.c |   15 +++++++--------
 parse-options.h |    7 +++++--
 2 files changed, 12 insertions(+), 10 deletions(-)
diff --git a/parse-options.c b/parse-options.c
index 850cfa7..7690de8 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 ? _(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_ln(outfile, _("usage: %s"), _(*usagestr++));
 	while (*usagestr && **usagestr)
-		fprintf(outfile, "   or: %s\n", *usagestr++);
+		fprintf_ln(outfile, _("   or: %s"), _(*usagestr++));
 	while (*usagestr) {
-		fprintf(outfile, "%s%s\n",
-				**usagestr ? "    " : "",
-				*usagestr);
+		fprintf(outfile, "%s%s\n", **usagestr ? "    " : "",
+			_(*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", _(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, "", _(opts->help));
 	}
 	fputc('\n', outfile);
 
diff --git a/parse-options.h b/parse-options.h
index def9ced..4e59f2c 100644
--- a/parse-options.h
+++ b/parse-options.h
@@ -66,12 +66,14 @@ typedef int parse_opt_ll_cb(struct parse_opt_ctx_t *ctx,
  *
  * `argh`::
  *   token to explain the kind of argument this option wants. Keep it
- *   homogeneous across the repository.
+ *   homogeneous across the repository. Should be wrapped by N_() for
+ *   translation.
  *
  * `help`::
  *   the short help associated to what the option does.
  *   Must never be NULL (except for OPTION_END).
  *   OPTION_GROUP uses this pointer to store the group header.
+ *   Should be wrapped by N_() for translation.
  *
  * `flags`::
  *   mask of parse_opt_option_flags.
@@ -158,7 +160,8 @@ struct option {
 #define OPT_BOOLEAN OPT_COUNTUP
 
 /* parse_options() will filter out the processed options and leave the
- * non-option arguments in argv[].
+ * non-option arguments in argv[]. usagestr strings should be marked
+ * for translation with N_().
  * Returns the number of arguments left in argv[].
  */
 extern int parse_options(int argc, const char **argv, const char *prefix,
-- 
1.7.3.1.256.g2539c.dirty
Previous: Nguyễn Thái Ngọc DuyNext: Jonathan Nieder
Message 6 of 21 in “Mark more strings for translation”
  1. 00/11 Mark more strings for translationNguyễn Thái Ngọc Duy, Apr 16, 2012
  2. 01/11 Add three convenient format printing functions with \n automatically appendedNguyễn Thái Ngọc Duy, Apr 16, 2012
  3. Jonathan NiederApr 16, 2012
  4. Erik Faye-LundApr 17, 2012
  5. 02/11 i18n: mark relative dates for translationNguyễn Thái Ngọc Duy, Apr 16, 2012
  6. 03/11 i18n: parseopt: lookup help and argument translations when showing usageNguyễn Thái Ngọc Duy, Apr 16, 2012
  7. Jonathan NiederApr 16, 2012
  8. Jonathan NiederApr 16, 2012
  9. 04/11 i18n: help: mark parseopt strings for translationNguyễn Thái Ngọc Duy, Apr 16, 2012
  10. 05/11 i18n: help: mark strings for translationNguyễn Thái Ngọc Duy, Apr 16, 2012
  11. Jonathan NiederApr 18, 2012
  12. 06/11 i18n: make warn_dangling_symref() automatically append \nNguyễn Thái Ngọc Duy, Apr 16, 2012
  13. 07/11 i18n: remote: mark strings for translationNguyễn Thái Ngọc Duy, Apr 16, 2012
  14. 08/11 i18n: apply: mark strings for translationNguyễn Thái Ngọc Duy, Apr 16, 2012
  15. 09/11 i18n: apply: update say_patch_name to give translators complete sentenceNguyễn Thái Ngọc Duy, Apr 16, 2012
  16. Zbigniew Jędrzejewski-SzmekApr 22, 2012
  17. Nguyen Thai Ngoc DuyApr 23, 2012
  18. 10/11 i18n: index-pack: mark strings for translationNguyễn Thái Ngọc Duy, Apr 16, 2012
  19. 11/11 i18n: bundle: mark strings for translationNguyễn Thái Ngọc Duy, Apr 16, 2012
  20. Jonathan NiederApr 18, 2012
  21. Nguyen Thai Ngoc DuyApr 22, 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.