# [PATCH v2] i18n: format_tracking_info "Your branch is behind" message

2 messages from 2012-02-02 to 2012-02-02. Participants: Jiang Xin, Junio C Hamano.
Thread: https://gitlist.dev/t/29511

## Jiang Xin, 2012-02-02 01:37

Subject: [PATCH v2] i18n: format_tracking_info "Your branch is behind" message
Message-ID: <1328146639-87863-1-git-send-email-worldhello.net@gmail.com>
URL: https://gitlist.dev/e/1328146639-87863-1-git-send-email-worldhello.net%40gmail.com

```
Function format_tracking_info in remote.c is called by
wt_status_print_tracking in wt-status.c, which will print
branch tracking message in git-status. git-checkout also
show these messages through it's report_tracking function.

Signed-off-by: Jiang Xin <worldhello.net@gmail.com>
---
 remote.c |   48 +++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 37 insertions(+), 11 deletions(-)

diff --git a/remote.c b/remote.c
index 73a38..45ac1 100644
--- a/remote.c
+++ b/remote.c
@@ -1572,19 +1572,45 @@ int format_tracking_info(struct branch *branch, struct strbuf *sb)
 	base = branch->merge[0]->dst;
 	base = shorten_unambiguous_ref(base, 0);
 	if (!num_theirs)
-		strbuf_addf(sb, "Your branch is ahead of '%s' "
-			    "by %d commit%s.\n",
-			    base, num_ours, (num_ours == 1) ? "" : "s");
+		strbuf_addf(sb,
+			Q_(
+			/* The singular version */
+			"Your branch is ahead of '%s' by %d commit.\n",
+			/* The plural version */
+			"Your branch is ahead of '%s' by %d commits.\n",
+			/* Give ngettext() the count */
+			num_ours),
+			base,
+			num_ours);
 	else if (!num_ours)
-		strbuf_addf(sb, "Your branch is behind '%s' "
-			    "by %d commit%s, "
-			    "and can be fast-forwarded.\n",
-			    base, num_theirs, (num_theirs == 1) ? "" : "s");
+		strbuf_addf(sb,
+			Q_(
+			/* The singular version */
+			"Your branch is behind '%s' by %d commit, "
+			"and can be fast-forwarded.\n",
+			/* The plural version */
+			"Your branch is behind '%s' by %d commits, "
+			"and can be fast-forwarded.\n",
+			/* Give ngettext() the count */
+			num_theirs),
+			base,
+			num_theirs);
 	else
-		strbuf_addf(sb, "Your branch and '%s' have diverged,\n"
-			    "and have %d and %d different commit(s) each, "
-			    "respectively.\n",
-			    base, num_ours, num_theirs);
+		strbuf_addf(sb,
+			Q_(
+			/* The singular version */
+			"Your branch and '%s' have diverged,\n"
+			"and have %d and %d different commit each, "
+			"respectively.\n",
+			/* The plural version */
+			"Your branch and '%s' have diverged,\n"
+			"and have %d and %d different commits each, "
+			"respectively.\n",
+			/* Give ngettext() the count */
+			num_theirs),
+			base,
+			num_ours,
+			num_theirs);
 	return 1;
 }
 
-- 
1.7.9.109.gd927b

```

## Junio C Hamano, 2012-02-02 01:50

Subject: Re: [PATCH v2] i18n: format_tracking_info "Your branch is behind" message
Message-ID: <7vr4yeypei.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vr4yeypei.fsf%40alter.siamese.dyndns.org
In-Reply-To: <1328146639-87863-1-git-send-email-worldhello.net@gmail.com>

```
Jiang Xin <worldhello.net@gmail.com> writes:

> Function format_tracking_info in remote.c is called by
> wt_status_print_tracking in wt-status.c, which will print
> branch tracking message in git-status. git-checkout also
> show these messages through it's report_tracking function.
>
> Signed-off-by: Jiang Xin <worldhello.net@gmail.com>
> ---
>  remote.c |   48 +++++++++++++++++++++++++++++++++++++-----------
>  1 files changed, 37 insertions(+), 11 deletions(-)
>
> diff --git a/remote.c b/remote.c
> index 73a38..45ac1 100644
> --- a/remote.c
> +++ b/remote.c
> @@ -1572,19 +1572,45 @@ int format_tracking_info(struct branch *branch, struct strbuf *sb)
>  	base = branch->merge[0]->dst;
>  	base = shorten_unambiguous_ref(base, 0);
>  	if (!num_theirs)
> -		strbuf_addf(sb, "Your branch is ahead of '%s' "
> -			    "by %d commit%s.\n",
> -			    base, num_ours, (num_ours == 1) ? "" : "s");
> +		strbuf_addf(sb,
> +			Q_(
> +			/* The singular version */
> +			"Your branch is ahead of '%s' by %d commit.\n",
> +			/* The plural version */
> +			"Your branch is ahead of '%s' by %d commits.\n",
> +			/* Give ngettext() the count */
> +			num_ours),
> +			base,
> +			num_ours);

It may be just me, but I think

		strbuf_addf(sb,
			Q_("Your branch is ahead of '%s' by %d commit.\n",
			   "Your branch is ahead of '%s' by %d commits.\n",
			   num_ours),
                        base, num_ours);

would be far easier to read than these repetitive comments.

It allows you to see it more clearly that the two strings and one variable
are given to Q_(), and the last two, base and num_ours, are the values to
be formatted by whatever the format string Q_() would choose.

When the strings are longer, an extra indent would probably help, e.g.

		strbuf_addf(sb,
			Q_("Your branch is behind '%s' by %d commit, "
				"and can be fast-forwarded.\n",
			   "Your branch is behind '%s' by %d commits, "
				"and can be fast-forwarded.\n",
			   num_theirs),
			base, num_theirs);

```
