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>
Jonathan Nieder committed
Dec 19, 2013 at 11:43 UTC
8f17f5b22ae54ecc3dfdafe33d7697e1bf3949f6
1 file changed
+47
-19
wt-status.c
+47
-19
@@ -245,27 +245,26 @@ static void wt_status_print_trailer(struct wt_status *s)
245
246
#define quote_path quote_path_relative
247
248
-static void wt_status_print_unmerged_data(struct wt_status *s,
249
- struct string_list_item *it)
248
+static const char *wt_status_unmerged_status_string(int stagemask)
249
{
251
- const char *c = color(WT_STATUS_UNMERGED, s);
252
- struct wt_status_change_data *d = it->util;
253
- struct strbuf onebuf = STRBUF_INIT;
254
- const char *one, *how = _("bug");
255
-
256
- one = quote_path(it->string, s->prefix, &onebuf);
257
- status_printf(s, color(WT_STATUS_HEADER, s), "\t");
258
- switch (d->stagemask) {
259
- case 1: how = _("both deleted:"); break;
260
- case 2: how = _("added by us:"); break;
261
- case 3: how = _("deleted by them:"); break;
262
- case 4: how = _("added by them:"); break;
263
- case 5: how = _("deleted by us:"); break;
264
- case 6: how = _("both added:"); break;
265
- case 7: how = _("both modified:"); break;
250
+ switch (stagemask) {
251
+ case 1:
252
+ return _("both deleted:");
253
+ case 2:
254
+ return _("added by us:");
255
+ case 3:
256
+ return _("deleted by them:");
257
+ case 4:
258
+ return _("added by them:");
259
+ case 5:
260
+ return _("deleted by us:");
261
+ case 6:
262
+ return _("both added:");
263
+ case 7:
264
+ return _("both modified:");
265
+ default:
266
+ die(_("bug: unhandled unmerged status %x"), stagemask);
267
}
267
- status_printf_more(s, c, "%-20s%s\n", how, one);
268
- strbuf_release(&onebuf);
268
}
269
270
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)
304
return result;
305
}
306
307
+static void wt_status_print_unmerged_data(struct wt_status *s,
308
+ struct string_list_item *it)
309
+{
310
+ const char *c = color(WT_STATUS_UNMERGED, s);
311
+ struct wt_status_change_data *d = it->util;
312
+ struct strbuf onebuf = STRBUF_INIT;
313
+ static char *padding;
314
+ static int label_width;
315
+ const char *one, *how;
316
+ int len;
317
+
318
+ if (!padding) {
319
+ label_width = maxwidth(wt_status_unmerged_status_string, 1, 7);
320
+ label_width += strlen(" ");
321
+ if (label_width < 20)
322
+ label_width = 20;
323
+ padding = xmallocz(label_width);
324
+ memset(padding, ' ', label_width);
325
+ }
326
+
327
+ one = quote_path(it->string, s->prefix, &onebuf);
328
+ status_printf(s, color(WT_STATUS_HEADER, s), "\t");
329
+
330
+ how = wt_status_unmerged_status_string(d->stagemask);
331
+ len = label_width - utf8_strwidth(how);
332
+ status_printf_more(s, c, "%s%.*s%s\n", how, len, padding, one);
333
+ strbuf_release(&onebuf);
334
+}
335
+
336
static void wt_status_print_change_data(struct wt_status *s,
337
int change_type,
338
struct string_list_item *it)