wt-status: make full label string to be subject to l10n
Earlier in 3651e45c (wt-status: take the alignment burden off translators, 2013-11-05), we assumed that it is OK to make the string before the colon in a label string we give as the section header of various kinds of changes (e.g. "new file:") translatable. This assumption apparently does not hold for some languages, e.g. ones that want to have spaces around the colon. Also introduce a static label_width to avoid having to run strlen(padding) over and over. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Junio C Hamano committed
Mar 12, 2014 at 13:51 UTC
d52cb5761a0e92e6051ea92edc7ae96fb6dca78f
1 file changed
+17
-18
wt-status.c
+17
-18
@@ -272,21 +272,21 @@ static const char *wt_status_diff_status_string(int status)
272
{
273
switch (status) {
274
case DIFF_STATUS_ADDED:
275
- return _("new file");
275
+ return _("new file:");
276
case DIFF_STATUS_COPIED:
277
- return _("copied");
277
+ return _("copied:");
278
case DIFF_STATUS_DELETED:
279
- return _("deleted");
279
+ return _("deleted:");
280
case DIFF_STATUS_MODIFIED:
281
- return _("modified");
281
+ return _("modified:");
282
case DIFF_STATUS_RENAMED:
283
- return _("renamed");
283
+ return _("renamed:");
284
case DIFF_STATUS_TYPE_CHANGED:
285
- return _("typechange");
285
+ return _("typechange:");
286
case DIFF_STATUS_UNKNOWN:
287
- return _("unknown");
287
+ return _("unknown:");
288
case DIFF_STATUS_UNMERGED:
289
- return _("unmerged");
289
+ return _("unmerged:");
290
default:
291
return NULL;
292
}
@@ -305,21 +305,21 @@ static void wt_status_print_change_data(struct wt_status *s,
305
struct strbuf onebuf = STRBUF_INIT, twobuf = STRBUF_INIT;
306
struct strbuf extra = STRBUF_INIT;
307
static char *padding;
308
+ static int label_width;
309
const char *what;
310
int len;
311
312
if (!padding) {
312
- int width = 0;
313
/* If DIFF_STATUS_* uses outside this range, we're in trouble */
314
for (status = 'A'; status <= 'Z'; status++) {
315
what = wt_status_diff_status_string(status);
316
len = what ? strlen(what) : 0;
317
- if (len > width)
318
- width = len;
317
+ if (len > label_width)
318
+ label_width = len;
319
}
320
- width += 2; /* colon and a space */
321
- padding = xmallocz(width);
322
- memset(padding, ' ', width);
320
+ label_width += strlen(" ");
321
+ padding = xmallocz(label_width);
322
+ memset(padding, ' ', label_width);
323
}
324
325
one_name = two_name = it->string;
@@ -355,14 +355,13 @@ static void wt_status_print_change_data(struct wt_status *s,
355
what = wt_status_diff_status_string(status);
356
if (!what)
357
die(_("bug: unhandled diff status %c"), status);
358
- /* 1 for colon, which is not part of "what" */
359
- len = strlen(padding) - (utf8_strwidth(what) + 1);
358
+ len = label_width - utf8_strwidth(what);
359
assert(len >= 0);
360
if (status == DIFF_STATUS_COPIED || status == DIFF_STATUS_RENAMED)
362
- status_printf_more(s, c, "%s:%.*s%s -> %s",
361
+ status_printf_more(s, c, "%s%.*s%s -> %s",
362
what, len, padding, one, two);
363
else
365
- status_printf_more(s, c, "%s:%.*s%s",
364
+ status_printf_more(s, c, "%s%.*s%s",
365
what, len, padding, one);
366
if (extra.len) {
367
status_printf_more(s, color(WT_STATUS_HEADER, s), "%s", extra.buf);