git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>,
	wolfgang@rohdewald.de, vnwildman@gmail.com,
	ralf.thielow@gmail.com,
	"Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH] wt-status: take the alignment burden off translators
Date: Mon,  4 Nov 2013 10:08:51 +0700	[thread overview]
Message-ID: <1383534531-5153-1-git-send-email-pclouds@gmail.com> (raw)
In-Reply-To: <31465687.35grSWXxkx@i5>

It's not easy for translators to see spaces in these strings have to
align, especially when there are no guarantees that these strings are
grouped together in .po files.

Refactor the code and do the alignment automatically. Let the
translator specify how big the alignment is, though, in case some
languages need more than 12 columns for the preceding text.

Noticed-by: Wolfgang Rohdewald <wolfgang@rohdewald.de>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 Ralf and Quan, don't update your translations yet. If this change
 gets merged it'll simplify your task a bit.

 wt-status.c | 51 +++++++++++++++++++++++++++++++++++++++++++--------
 1 file changed, 43 insertions(+), 8 deletions(-)

diff --git a/wt-status.c b/wt-status.c
index b4e44ba..f9715d3 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -15,6 +15,7 @@
 #include "submodule.h"
 #include "column.h"
 #include "strbuf.h"
+#include "utf8.h"
 
 static char default_wt_status_colors[][COLOR_MAXLEN] = {
 	GIT_COLOR_NORMAL, /* WT_STATUS_HEADER */
@@ -276,6 +277,10 @@ static void wt_status_print_change_data(struct wt_status *s,
 	const char *one, *two;
 	struct strbuf onebuf = STRBUF_INIT, twobuf = STRBUF_INIT;
 	struct strbuf extra = STRBUF_INIT;
+	const char *what;
+	static const char *spaces = "                                ";
+	static int width = -1;
+	int len;
 
 	one_name = two_name = it->string;
 	switch (change_type) {
@@ -309,32 +314,62 @@ static void wt_status_print_change_data(struct wt_status *s,
 	status_printf(s, color(WT_STATUS_HEADER, s), "\t");
 	switch (status) {
 	case DIFF_STATUS_ADDED:
-		status_printf_more(s, c, _("new file:   %s"), one);
+		what = _("new file");
 		break;
 	case DIFF_STATUS_COPIED:
-		status_printf_more(s, c, _("copied:     %s -> %s"), one, two);
+		what = _("copied");
 		break;
 	case DIFF_STATUS_DELETED:
-		status_printf_more(s, c, _("deleted:    %s"), one);
+		what = _("deleted");
 		break;
 	case DIFF_STATUS_MODIFIED:
-		status_printf_more(s, c, _("modified:   %s"), one);
+		what = _("modified");
 		break;
 	case DIFF_STATUS_RENAMED:
-		status_printf_more(s, c, _("renamed:    %s -> %s"), one, two);
+		what = _("renamed");
 		break;
 	case DIFF_STATUS_TYPE_CHANGED:
-		status_printf_more(s, c, _("typechange: %s"), one);
+		what = _("typechange");
 		break;
 	case DIFF_STATUS_UNKNOWN:
-		status_printf_more(s, c, _("unknown:    %s"), one);
+		what = _("unknown");
 		break;
 	case DIFF_STATUS_UNMERGED:
-		status_printf_more(s, c, _("unmerged:   %s"), one);
+		what = _("unmerged");
 		break;
 	default:
 		die(_("bug: unhandled diff status %c"), status);
 	}
+	if (width == -1) {
+		/*
+		 * Translators: if you do translate this, replace it
+		 * with a decimal number of how many columns needed
+		 * to align file names in "git status":
+		 *
+		 * |<-columns->|
+		 *
+		 *   unmerged: foo.c
+		 *   copied:   foo.c -> bar.c
+		 *
+		 * The default value is 12. Normally you would not
+		 * need to translate this at all unless the translated
+		 * strings are longer than 12 columns and therefore
+		 * break alignment.
+		 */
+		width = atoi(_("<wt-status.c:width>"));
+		if (width <= 0 || width > 32)
+			width = 12;
+	}
+	if (width > utf8_strwidth(what) + 1)
+		len = width - utf8_strwidth(what) - 1;
+	else
+		len = 0;
+	if (status == DIFF_STATUS_COPIED || status == DIFF_STATUS_RENAMED)
+		status_printf_more(s, c, "%s:%.*s%s -> %s",
+				   what, len, spaces, one, two);
+	else
+		status_printf_more(s, c, "%s:%.*s%s",
+				   what, len, spaces, one);
 	if (extra.len) {
 		status_printf_more(s, color(WT_STATUS_HEADER, s), "%s", extra.buf);
 		strbuf_release(&extra);
-- 
1.8.2.83.gc99314b

  parent reply	other threads:[~2013-11-04  3:05 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-03 17:17 git status: minor output format error Wolfgang Rohdewald
2013-11-04  1:46 ` Duy Nguyen
2013-11-04  7:53   ` Ralf Thielow
2013-11-04  3:08 ` Nguyễn Thái Ngọc Duy [this message]
2013-11-04 18:42   ` [PATCH] wt-status: take the alignment burden off translators Junio C Hamano
2013-11-05  2:07   ` [PATCH v2] " Nguyễn Thái Ngọc Duy

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=1383534531-5153-1-git-send-email-pclouds@gmail.com \
    --to=pclouds@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=ralf.thielow@gmail.com \
    --cc=vnwildman@gmail.com \
    --cc=wolfgang@rohdewald.de \
    /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).