From 9440b831ad5b1750b65fa3f1d0b99179ab317c76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Sat, 10 Nov 2018 06:16:11 +0100 Subject: parse-options: replace opterror() with optname() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Introduce optname() that does the early half of original opterror() to come up with the name of the option reported back to the user, and use it to kill opterror(). The callers of opterror() now directly call error() using the string returned by opterror() instead. There are a few issues with opterror() - it tries to assemble an English sentence from pieces. This is not great for translators because we give them pieces instead of a full sentence. - It's a wrapper around error() and needs some hack to let the compiler know it always returns -1. - Since it takes a string instead of printf format, one call site has to assemble the string manually before passing to it. Using error() directly solves the second and third problems. It kind helps the first problem as well because "%s does foo" does give a translator a full sentence in a sense and let them reorder if needed. But it has limitations, if the subject part has to change based on the rest of the sentence, that language is screwed. This is also why I try to avoid calling optname() when 'flags' is known in advance. Mark of these strings for translation as well while at there. Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- parse-options-cb.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'parse-options-cb.c') diff --git a/parse-options-cb.c b/parse-options-cb.c index e8236534ac..813eb6301b 100644 --- a/parse-options-cb.c +++ b/parse-options-cb.c @@ -18,7 +18,8 @@ int parse_opt_abbrev_cb(const struct option *opt, const char *arg, int unset) } else { v = strtol(arg, (char **)&arg, 10); if (*arg) - return opterror(opt, "expects a numerical value", 0); + return error(_("option `%s' expects a numerical value"), + opt->long_name); if (v && v < MINIMUM_ABBREV) v = MINIMUM_ABBREV; else if (v > 40) @@ -54,8 +55,8 @@ int parse_opt_color_flag_cb(const struct option *opt, const char *arg, arg = unset ? "never" : (const char *)opt->defval; value = git_config_colorbool(NULL, arg); if (value < 0) - return opterror(opt, - "expects \"always\", \"auto\", or \"never\"", 0); + return error(_("option `%s' expects \"always\", \"auto\", or \"never\""), + opt->long_name); *(int *)opt->value = value; return 0; } -- cgit v1.2.3