threads / patch / 39233

patchFixed a translation error

Subject: [PATCH] Fixed a translation error

## tl;dr

3 messages between May 4, 2015 and May 4, 2015. Diffs are folded; open one to read it.

replies: 2people: 3as markdown or json

Alangi Derick· May 4, 2015, 11:16 UTC · lore
Signed-off-by: Alangi Derick <alangiderick@gmail.com>
---
 builtin/config.c | 34 +++++++++++++++++-----------------
 1 file changed, 17 insertions(+), 17 deletions(-)
Show changes to builtin/config.c +17 −17
diff --git a/builtin/config.c b/builtin/config.c
index d32c532..2b6bf0a 100644
--- a/builtin/config.c
+++ b/builtin/config.c
@@ -85,7 +85,7 @@ static struct option builtin_config_options[] = {
 static void check_argc(int argc, int min, int max) {
 	if (argc >= min && argc <= max)
 		return;
-	error("wrong number of arguments");
+	error(_("wrong number of arguments"));
 	usage_with_options(builtin_config_usage, builtin_config_options);
 }
 
@@ -366,10 +366,10 @@ static int get_colorbool(const char *var, int print)
 static void check_write(void)
 {
 	if (given_config_source.use_stdin)
-		die("writing to stdin is not supported");
+		die(_("writing to stdin is not supported"));
 
 	if (given_config_source.blob)
-		die("writing config blobs is not supported");
+		die(_("writing config blobs is not supported"));
 }
 
 struct urlmatch_current_candidate_value {
@@ -412,7 +412,7 @@ static int get_urlmatch(const char *var, const char *url)
 	config.cb = &values;
 
 	if (!url_normalize(url, &config.url))
-		die("%s", config.url.err);
+		die(_("%s"), config.url.err);
 
 	config.section = xstrdup_tolower(var);
 	section_tail = strchr(config.section, '.');
@@ -477,7 +477,7 @@ int cmd_config(int argc, const char **argv, const char *prefix)
 
 	if (use_global_config + use_system_config + use_local_config +
 	    !!given_config_source.file + !!given_config_source.blob > 1) {
-		error("only one config file at a time.");
+		error(_("only one config file at a time."));
 		usage_with_options(builtin_config_usage, builtin_config_options);
 	}
 
@@ -500,7 +500,7 @@ int cmd_config(int argc, const char **argv, const char *prefix)
 			 * location; error out even if XDG_CONFIG_HOME
 			 * is set and points at a sane location.
 			 */
-			die("$HOME not set");
+			die(_("$HOME not set"));
 
 		if (access_or_warn(user_config, R_OK, 0) &&
 		    xdg_config && !access_or_warn(xdg_config, R_OK, 0))
@@ -530,17 +530,17 @@ int cmd_config(int argc, const char **argv, const char *prefix)
 	}
 
 	if (HAS_MULTI_BITS(types)) {
-		error("only one type at a time.");
+		error(_("only one type at a time."));
 		usage_with_options(builtin_config_usage, builtin_config_options);
 	}
 
 	if ((actions & (ACTION_GET_COLOR|ACTION_GET_COLORBOOL)) && types) {
-		error("--get-color and variable type are incoherent");
+		error(_("--get-color and variable type are incoherent"));
 		usage_with_options(builtin_config_usage, builtin_config_options);
 	}
 
 	if (HAS_MULTI_BITS(actions)) {
-		error("only one action at a time.");
+		error(_("only one action at a time."));
 		usage_with_options(builtin_config_usage, builtin_config_options);
 	}
 	if (actions == 0)
@@ -561,7 +561,7 @@ int cmd_config(int argc, const char **argv, const char *prefix)
 				die_errno("unable to read config file '%s'",
 					  given_config_source.file);
 			else
-				die("error processing config file(s)");
+				die(_("error processing config file(s)"));
 		}
 	}
 	else if (actions == ACTION_EDIT) {
@@ -569,11 +569,11 @@ int cmd_config(int argc, const char **argv, const char *prefix)
 
 		check_argc(argc, 0, 0);
 		if (!given_config_source.file && nongit)
-			die("not in a git directory");
+			die(_("not in a git directory"));
 		if (given_config_source.use_stdin)
-			die("editing stdin is not supported");
+			die(_("editing stdin is not supported"));
 		if (given_config_source.blob)
-			die("editing blobs is not supported");
+			die(_("editing blobs is not supported"));
 		git_config(git_default_config, NULL);
 		config_file = xstrdup(given_config_source.file ?
 				      given_config_source.file : git_path("config"));
@@ -598,8 +598,8 @@ int cmd_config(int argc, const char **argv, const char *prefix)
 		value = normalize_value(argv[0], argv[1]);
 		ret = git_config_set_in_file(given_config_source.file, argv[0], value);
 		if (ret == CONFIG_NOTHING_SET)
-			error("cannot overwrite multiple values with a single value\n"
-			"       Use a regexp, --add or --replace-all to change %s.", argv[0]);
+			error(_("cannot overwrite multiple values with a single value\n"
+			"       Use a regexp, --add or --replace-all to change %s."), argv[0]);
 		return ret;
 	}
 	else if (actions == ACTION_SET_ALL) {
@@ -669,7 +669,7 @@ int cmd_config(int argc, const char **argv, const char *prefix)
 		if (ret < 0)
 			return ret;
 		if (ret == 0)
-			die("No such section!");
+			die(_("No such section!"));
 	}
 	else if (actions == ACTION_REMOVE_SECTION) {
 		int ret;
@@ -680,7 +680,7 @@ int cmd_config(int argc, const char **argv, const char *prefix)
 		if (ret < 0)
 			return ret;
 		if (ret == 0)
-			die("No such section!");
+			die(_("No such section!"));
 	}
 	else if (actions == ACTION_GET_COLOR) {
 		check_argc(argc, 1, 2);
-- 
2.4.0.5.g7a7787e.dirty
Jonathan Nieder· May 4, 2015, 21:18 UTC · re: Alangi Derick · lore

Re: [PATCH] Fixed a translation error

Hi,
Alangi Derick wrote:
> [To: unlisted-recipients: no To-header on input <;]
Please don't do that.

What mailer do you use to send patches? Others on the list using the same mailer might be able to help with configuration tips.

> [Subject: [PATCH] Fixed a translation error]

The above commit description is vague and confusing: in fact, this patch doesn't fix a translation error. Instead, the commit description should explain the purpose of the change in such a way as to make it clear why a person might want to apply it.

More details are in Documentation/SubmittingPatches.
> Signed-off-by: Alangi Derick <alangiderick@gmail.com>
Thanks.
[...]
> +++ b/builtin/config.c

Yes, this is an okay command to start with. Some messages are already translated in this file, so it's a good example of a command that currently presents an inconsistent interface in some languages.

[...]
Show 6 quoted lines
> @@ -412,7 +412,7 @@ static int get_urlmatch(const char *var, const char *url)
>  	config.cb = &values;
>  
>  	if (!url_normalize(url, &config.url))
> -		die("%s", config.url.err);
> +		die(_("%s"), config.url.err);

This change is subtle. It lets a translator replace the format "%s" with something else --- that wouldn't be useful in any language, so this string should not be marked for translation.

The underlying message in config.url.err is from urlmatch.c and is already translated.

There are two more strings that need to be marked for translation in this file: "Invalid key pattern: %s" and "Invalid pattern: %s". Here's a preparatory patch to make that output more consistent.

One more piece of advice: when working on many similar patches like this, a good strategy is to just send out one and get review for it. When it has been reviewed and is in good shape, you can move on to preparing and polishing the next patch. The first few reviewed patches can be used a template for the rest.

In other words, only once it's very clear that all the patches are likely to be in good shape is it time to prepare and send out all of them. By working through only one patch at a time in a collection of similar, unfinished patches, you avoid wasting time re-writing all the patches in response to feedback and avoid overwhelming reviewers by asking them to keep track of many reviews at once. Most comments on one patch will also apply to all the rest and the conversation only has to happen once.

Thanks, Jonathan

-- >8 --
Subject: config: use error() instead of fprintf(stderr, ...)

The die() / error() / warning() helpers put a fatal: / error: / warning: prefix in front of the error message they print describing the message's severity, which users are likely to be accustomed to seeing these days.

This change will also be useful when marking the message for translation: the argument to error() includes no newline at the end, so it is less fussy for translators to translate without lines running together in the translated output.

While we're here, start the error messages with a lowercase letter to match the usual typography of error messages.

A quick web search and a code search at codesearch.debian.net finds no scripts trying to parse these error messages, so this change should be safe.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
 builtin/config.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Show changes to builtin/config.c +2 −2
diff --git a/builtin/config.c b/builtin/config.c
index d32c532..89f3208 100644
--- a/builtin/config.c
+++ b/builtin/config.c
@@ -193,7 +193,7 @@ static int get_value(const char *key_, const char *regex_)
 
 		key_regexp = (regex_t*)xmalloc(sizeof(regex_t));
 		if (regcomp(key_regexp, key, REG_EXTENDED)) {
-			fprintf(stderr, "Invalid key pattern: %s\n", key_);
+			error("invalid key pattern: %s", key_);
 			free(key_regexp);
 			key_regexp = NULL;
 			ret = CONFIG_INVALID_PATTERN;
@@ -214,7 +214,7 @@ static int get_value(const char *key_, const char *regex_)
 
 		regexp = (regex_t*)xmalloc(sizeof(regex_t));
 		if (regcomp(regexp, regex_, REG_EXTENDED)) {
-			fprintf(stderr, "Invalid pattern: %s\n", regex_);
+			error("invalid pattern: %s", regex_);
 			free(regexp);
 			regexp = NULL;
 			ret = CONFIG_INVALID_PATTERN;
Junio C Hamano· May 4, 2015, 21:29 UTC · re: Jonathan Nieder · lore

Re: [PATCH] Fixed a translation error

Jonathan Nieder <jrnieder@gmail.com> writes:
Show 6 quoted lines
> While we're here, start the error messages with a lowercase letter to
> match the usual typography of error messages.
>
> A quick web search and a code search at codesearch.debian.net finds no
> scripts trying to parse these error messages, so this change should be
> safe.
Very well thought through and nicely written.

I am tempted to pick this patch up and queue it on its own. Alengi, if you want to add _() markings to this file, perhaps it is a good idea to base your patch relative to (i.e. on top of) Jonathan's patch.

Thanks.
Show 28 quoted lines
>
> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
> ---
>  builtin/config.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/builtin/config.c b/builtin/config.c
> index d32c532..89f3208 100644
> --- a/builtin/config.c
> +++ b/builtin/config.c
> @@ -193,7 +193,7 @@ static int get_value(const char *key_, const char *regex_)
>  
>  		key_regexp = (regex_t*)xmalloc(sizeof(regex_t));
>  		if (regcomp(key_regexp, key, REG_EXTENDED)) {
> -			fprintf(stderr, "Invalid key pattern: %s\n", key_);
> +			error("invalid key pattern: %s", key_);
>  			free(key_regexp);
>  			key_regexp = NULL;
>  			ret = CONFIG_INVALID_PATTERN;
> @@ -214,7 +214,7 @@ static int get_value(const char *key_, const char *regex_)
>  
>  		regexp = (regex_t*)xmalloc(sizeof(regex_t));
>  		if (regcomp(regexp, regex_, REG_EXTENDED)) {
> -			fprintf(stderr, "Invalid pattern: %s\n", regex_);
> +			error("invalid pattern: %s", regex_);
>  			free(regexp);
>  			regexp = NULL;
>  			ret = CONFIG_INVALID_PATTERN;

← back to recent threads