@matheusbsbs / matheus-bagliano / commits / 5b34dd08d0
Fork 0

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 <ash@kambanaria.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Alexander Shopov committed Dec 28, 2024 at 12:42 UTC 5b34dd08d0ffc967b92abe187cc890d52ade5ac7
1 file changed +40 -3
parse-options.c
+40 -3
@@ -1076,11 +1076,48 @@ static int usage_argh(const struct option *opts, FILE *outfile)
1076 !opts->argh || !!strpbrk(opts->argh, "()<>[]|");
1077 if (opts->flags & PARSE_OPT_OPTARG)
1078 if (opts->long_name)
1079 - s = literal ? "[=%s]" : "[=<%s>]";
1079 + /*
1080 + * TRANSLATORS: The "<%s>" part of this string
1081 + * stands for an optional value given to a command
1082 + * line option in the long form, and "<>" is there
1083 + * as a convention to signal that it is a
1084 + * placeholder (i.e. the user should substitute it
1085 + * with the real value). If your language uses a
1086 + * different convention, you can change "<%s>" part
1087 + * to match yours, e.g. it might use "|%s|" instead,
1088 + * or if the alphabet is different enough it may use
1089 + * "%s" without any placeholder signal. Most
1090 + * translations leave this message as is.
1091 + */
1092 + s = literal ? "[=%s]" : _("[=<%s>]");
1093 else
1081 - s = literal ? "[%s]" : "[<%s>]";
1094 + /*
1095 + * TRANSLATORS: The "<%s>" part of this string
1096 + * stands for an optional value given to a command
1097 + * line option in the short form, and "<>" is there
1098 + * as a convention to signal that it is a
1099 + * placeholder (i.e. the user should substitute it
1100 + * with the real value). If your language uses a
1101 + * different convention, you can change "<%s>" part
1102 + * to match yours, e.g. it might use "|%s|" instead,
1103 + * or if the alphabet is different enough it may use
1104 + * "%s" without any placeholder signal. Most
1105 + * translations leave this message as is.
1106 + */
1107 + s = literal ? "[%s]" : _("[<%s>]");
1108 else
1083 - s = literal ? " %s" : " <%s>";
1109 + /*
1110 + * TRANSLATORS: The "<%s>" part of this string stands for a
1111 + * value given to a command line option, and "<>" is there
1112 + * as a convention to signal that it is a placeholder
1113 + * (i.e. the user should substitute it with the real value).
1114 + * If your language uses a different convention, you can
1115 + * change "<%s>" part to match yours, e.g. it might use
1116 + * "|%s|" instead, or if the alphabet is different enough it
1117 + * may use "%s" without any placeholder signal. Most
1118 + * translations leave this message as is.
1119 + */
1120 + s = literal ? " %s" : _(" <%s>");
1121 return utf8_fprintf(outfile, s, opts->argh ? _(opts->argh) : _("..."));
1122 }
1123