wt-status: i18n of section labels

The original code assumes that:

 (1) the number of bytes written is the width of a string, so they
     can line up;

 (2) the "how" string is always <= 19 bytes.

Neither of which we should assume.

Using the same approach as the earlier 3651e45c (wt-status: take the
alignment burden off translators, 2013-11-05), compute the necessary
column width to hold the longest label and use that for alignment.

cf. http://bugs.debian.org/725777

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Helped-by: Sandy Carter
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Jonathan Nieder 2013-12-19 11:43:19 -08:00 committed by Junio C Hamano
parent 335e825012
commit 8f17f5b22a

View File

@ -245,27 +245,26 @@ static void wt_status_print_trailer(struct wt_status *s)
#define quote_path quote_path_relative #define quote_path quote_path_relative
static void wt_status_print_unmerged_data(struct wt_status *s, static const char *wt_status_unmerged_status_string(int stagemask)
struct string_list_item *it)
{ {
const char *c = color(WT_STATUS_UNMERGED, s); switch (stagemask) {
struct wt_status_change_data *d = it->util; case 1:
struct strbuf onebuf = STRBUF_INIT; return _("both deleted:");
const char *one, *how = _("bug"); case 2:
return _("added by us:");
one = quote_path(it->string, s->prefix, &onebuf); case 3:
status_printf(s, color(WT_STATUS_HEADER, s), "\t"); return _("deleted by them:");
switch (d->stagemask) { case 4:
case 1: how = _("both deleted:"); break; return _("added by them:");
case 2: how = _("added by us:"); break; case 5:
case 3: how = _("deleted by them:"); break; return _("deleted by us:");
case 4: how = _("added by them:"); break; case 6:
case 5: how = _("deleted by us:"); break; return _("both added:");
case 6: how = _("both added:"); break; case 7:
case 7: how = _("both modified:"); break; return _("both modified:");
default:
die(_("bug: unhandled unmerged status %x"), stagemask);
} }
status_printf_more(s, c, "%-20s%s\n", how, one);
strbuf_release(&onebuf);
} }
static const char *wt_status_diff_status_string(int status) static const char *wt_status_diff_status_string(int status)
@ -305,6 +304,35 @@ static int maxwidth(const char *(*label)(int), int minval, int maxval)
return result; return result;
} }
static void wt_status_print_unmerged_data(struct wt_status *s,
struct string_list_item *it)
{
const char *c = color(WT_STATUS_UNMERGED, s);
struct wt_status_change_data *d = it->util;
struct strbuf onebuf = STRBUF_INIT;
static char *padding;
static int label_width;
const char *one, *how;
int len;
if (!padding) {
label_width = maxwidth(wt_status_unmerged_status_string, 1, 7);
label_width += strlen(" ");
if (label_width < 20)
label_width = 20;
padding = xmallocz(label_width);
memset(padding, ' ', label_width);
}
one = quote_path(it->string, s->prefix, &onebuf);
status_printf(s, color(WT_STATUS_HEADER, s), "\t");
how = wt_status_unmerged_status_string(d->stagemask);
len = label_width - utf8_strwidth(how);
status_printf_more(s, c, "%s%.*s%s\n", how, len, padding, one);
strbuf_release(&onebuf);
}
static void wt_status_print_change_data(struct wt_status *s, static void wt_status_print_change_data(struct wt_status *s,
int change_type, int change_type,
struct string_list_item *it) struct string_list_item *it)