git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jiang Xin <worldhello.net@gmail.com>
To: Junio C Hamano <gitster@pobox.com>, Duy Nguyen <pclouds@gmail.com>
Cc: Brian Gesiak <modocache@gmail.com>,
	Git List <git@vger.kernel.org>,
	Jiang Xin <worldhello.net@gmail.com>
Subject: [PATCH v2 2/2] blame: use different blame_date_width for different locale
Date: Mon, 21 Apr 2014 00:13:53 +0800	[thread overview]
Message-ID: <07e4dcdc98b5eb9c78b9ed53bf2adc3b33139b67.1398010052.git.worldhello.net@gmail.com> (raw)
In-Reply-To: <cover.1398010052.git.worldhello.net@gmail.com>
In-Reply-To: <cover.1398010052.git.worldhello.net@gmail.com>

When show date in relative date format for `git blame`, the max display
width of datetime is set as the length of the string "Thu Oct 19
16:00:04 2006 -0700" (30 characters long).  But actually the max width
for C locale is only 22 (the length of string "x years, xx months ago").
And for other locale, it maybe smaller.  E.g. For Chinese locale, only
needs 16-character width.

Set blame_date_width as the display width of _("4 years, 11 months
ago"), so that translators can make the choice.

Signed-off-by: Jiang Xin <worldhello.net@gmail.com>
---
 builtin/blame.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/builtin/blame.c b/builtin/blame.c
index 0a0a858..9350ea3 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -2340,7 +2340,15 @@ parse_done:
 		blame_date_width = sizeof("2006-10-19");
 		break;
 	case DATE_RELATIVE:
-		/* "normal" is used as the fallback for "relative" */
+		/* TRANSLATORS: what we care about is not the content itself,
+		   but the display width of this string.  We use the width of
+		   the string as the max width of the datetime in relative
+		   format.  For English and many other languages, "4 years,
+		   11 months ago" is the longest one among "89 seconds ago",
+		   "89 minites ago", "35 hours ago", "13 days ago", "10 weeks
+		   ago", "in the future" and many others. */
+		blame_date_width = utf8_strwidth(_("4 years, 11 months ago")) + 1; /* add the null */
+		break;
 	case DATE_LOCAL:
 	case DATE_NORMAL:
 		blame_date_width = sizeof("Thu Oct 19 16:00:04 2006 -0700");
-- 
2.0.0.rc0.3.g444188f.dirty

  parent reply	other threads:[~2014-04-20 16:14 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-04-18  8:44 [PATCH] blame: add correct paddings in time_buf for align Jiang Xin
2014-04-18 14:42 ` Duy Nguyen
2014-04-18 17:08   ` Junio C Hamano
2014-04-19  0:20     ` Duy Nguyen
2014-04-20 16:13   ` [PATCH v2 0/2] peroper align of datetime filed of git-blame Jiang Xin
2014-04-20 16:13   ` [PATCH v2 1/2] bugfix: fix broken time_buf paddings for git-blame Jiang Xin
2014-04-20 20:28     ` Eric Sunshine
2014-04-20 16:13   ` Jiang Xin [this message]
2014-04-20 21:40     ` [PATCH v2 2/2] blame: use different blame_date_width for different locale Junio C Hamano
2014-04-21  6:02       ` [PATCH v3 0/2] peroper align of datetime filed of git-blame Jiang Xin
2014-04-21  6:02       ` [PATCH v3 1/2] bugfix: fix broken time_buf paddings for git-blame Jiang Xin
2014-04-21  6:02       ` [PATCH v3 2/2] blame: use a helper to get suitable blame_date_width Jiang Xin
2014-04-21 17:20         ` Junio C Hamano
2014-04-21 19:19           ` Junio C Hamano
2014-04-22 12:25             ` Jiang Xin
2014-04-22 14:39             ` [PATCH v4 0/2] peroper align of datetime filed of git-blame Jiang Xin
2014-04-22 14:39             ` [PATCH v4 1/2] bugfix: fix broken time_buf paddings for git-blame Jiang Xin
2014-04-22 14:39             ` [PATCH v4 2/2] blame: dynamic blame_date_width for different locales Jiang Xin
2014-04-22 10:01       ` [PATCH v2 2/2] blame: use different blame_date_width for different locale David Kastrup
2014-04-22 12:16         ` Jiang Xin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=07e4dcdc98b5eb9c78b9ed53bf2adc3b33139b67.1398010052.git.worldhello.net@gmail.com \
    --to=worldhello.net@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=modocache@gmail.com \
    --cc=pclouds@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).