Skip to content

Commit 85a2838

Browse files
alshopovgitster
authored andcommitted
parse-options: localize mark-up of placeholder text in the short help
i18n: expose substitution hint chars in functions and macros to translators For example (based on builtin/commit.c and shortened): the "--author" option takes a name. In source this can be represented as: OPT_STRING(0, "author", &force_author, N_("author"), N_("override author")), When the command is run with "-h" (short help) option (git commit -h), the above definition is displayed as: --[no-]author <author> override author Git does not use translated option names so the first part of the above, "--[no-]author", is given as-is (it is based on the 2nd argument of OPT_STRING). However the string "author" in the pair of "<>", and the explanation "override author for commit" may be translated into user's language. The user's language may use a convention to mark a replaceable part of the command line (called a "placeholder string") differently from enclosing it inside a pair of "<>", but the implementation in parse-options.c hardcodes "<%s>". Allow translators to specify the presentation of a placeholder string for their languages by overriding the "<%s>". In case the translator's writing system is sufficiently different than Latin the "<>" characters can be substituted by an empty string thus effectively skipping them in the output. For example languages with uppercase versions of characters can use that to deliniate replaceability. Alternatively a translator can decide to use characters that are visually close to "<>" but are not interpreted by the shell. Signed-off-by: Alexander Shopov <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 76cf4f6 commit 85a2838

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

parse-options.c

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,11 +1076,23 @@ static int usage_argh(const struct option *opts, FILE *outfile)
10761076
!opts->argh || !!strpbrk(opts->argh, "()<>[]|");
10771077
if (opts->flags & PARSE_OPT_OPTARG)
10781078
if (opts->long_name)
1079-
s = literal ? "[=%s]" : "[=<%s>]";
1079+
s = literal ? "[=%s]" :
1080+
/* TRANSLATORS: %s is a command line argument name, `<>' prompt the user to supply a value for it.
1081+
Change only the `<>' characters to something else if you use another convention for this.
1082+
Most translations leave this message as is. */
1083+
_("[=<%s>]");
10801084
else
1081-
s = literal ? "[%s]" : "[<%s>]";
1085+
s = literal ? "[%s]" :
1086+
/* TRANSLATORS: %s is a command line argument name, `<>' prompt the user to supply a value for it.
1087+
Change only the `<>' characters to something else if you use another convention for this.
1088+
Most translations leave this message as is. */
1089+
_("[<%s>]");
10821090
else
1083-
s = literal ? " %s" : " <%s>";
1091+
s = literal ? " %s" :
1092+
/* TRANSLATORS: %s is a command line argument name, `<>' prompt the user to supply a value for it.
1093+
Change only the `<>' characters to something else if you use another convention for this.
1094+
Most translations leave this message as is. */
1095+
_(" <%s>");
10841096
return utf8_fprintf(outfile, s, opts->argh ? _(opts->argh) : _("..."));
10851097
}
10861098

0 commit comments

Comments
 (0)