wt-status: take the alignment burden off translators
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. Noticed-by: Wolfgang Rohdewald <wolfgang@rohdewald.de> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Nguyễn Thái Ngọc Duy committed
Nov 5, 2013 at 09:07 UTC
3651e45c341fc40302b7c21bf1e60a5b038439d3
1 file changed
+53
-27
wt-status.c
+53
-27
@@ -15,6 +15,7 @@
15
#include "submodule.h"
16
#include "column.h"
17
#include "strbuf.h"
18
+#include "utf8.h"
19
20
static char default_wt_status_colors[][COLOR_MAXLEN] = {
21
GIT_COLOR_NORMAL, /* WT_STATUS_HEADER */
@@ -264,6 +265,30 @@ static void wt_status_print_unmerged_data(struct wt_status *s,
265
strbuf_release(&onebuf);
266
}
267
268
+static const char *wt_status_diff_status_string(int status)
269
+{
270
+ switch (status) {
271
+ case DIFF_STATUS_ADDED:
272
+ return _("new file");
273
+ case DIFF_STATUS_COPIED:
274
+ return _("copied");
275
+ case DIFF_STATUS_DELETED:
276
+ return _("deleted");
277
+ case DIFF_STATUS_MODIFIED:
278
+ return _("modified");
279
+ case DIFF_STATUS_RENAMED:
280
+ return _("renamed");
281
+ case DIFF_STATUS_TYPE_CHANGED:
282
+ return _("typechange");
283
+ case DIFF_STATUS_UNKNOWN:
284
+ return _("unknown");
285
+ case DIFF_STATUS_UNMERGED:
286
+ return _("unmerged");
287
+ default:
288
+ return NULL;
289
+ }
290
+}
291
+
292
static void wt_status_print_change_data(struct wt_status *s,
293
int change_type,
294
struct string_list_item *it)
@@ -276,6 +301,23 @@ static void wt_status_print_change_data(struct wt_status *s,
301
const char *one, *two;
302
struct strbuf onebuf = STRBUF_INIT, twobuf = STRBUF_INIT;
303
struct strbuf extra = STRBUF_INIT;
304
+ static char *padding;
305
+ const char *what;
306
+ int len;
307
+
308
+ if (!padding) {
309
+ int width = 0;
310
+ /* If DIFF_STATUS_* uses outside this range, we're in trouble */
311
+ for (status = 'A'; status <= 'Z'; status++) {
312
+ what = wt_status_diff_status_string(status);
313
+ len = what ? strlen(what) : 0;
314
+ if (len > width)
315
+ width = len;
316
+ }
317
+ width += 2; /* colon and a space */
318
+ padding = xmallocz(width);
319
+ memset(padding, ' ', width);
320
+ }
321
322
one_name = two_name = it->string;
323
switch (change_type) {
@@ -307,34 +349,18 @@ static void wt_status_print_change_data(struct wt_status *s,
349
two = quote_path(two_name, s->prefix, &twobuf);
350
351
status_printf(s, color(WT_STATUS_HEADER, s), "\t");
310
- switch (status) {
311
- case DIFF_STATUS_ADDED:
312
- status_printf_more(s, c, _("new file: %s"), one);
313
- break;
314
- case DIFF_STATUS_COPIED:
315
- status_printf_more(s, c, _("copied: %s -> %s"), one, two);
316
- break;
317
- case DIFF_STATUS_DELETED:
318
- status_printf_more(s, c, _("deleted: %s"), one);
319
- break;
320
- case DIFF_STATUS_MODIFIED:
321
- status_printf_more(s, c, _("modified: %s"), one);
322
- break;
323
- case DIFF_STATUS_RENAMED:
324
- status_printf_more(s, c, _("renamed: %s -> %s"), one, two);
325
- break;
326
- case DIFF_STATUS_TYPE_CHANGED:
327
- status_printf_more(s, c, _("typechange: %s"), one);
328
- break;
329
- case DIFF_STATUS_UNKNOWN:
330
- status_printf_more(s, c, _("unknown: %s"), one);
331
- break;
332
- case DIFF_STATUS_UNMERGED:
333
- status_printf_more(s, c, _("unmerged: %s"), one);
334
- break;
335
- default:
352
+ what = wt_status_diff_status_string(status);
353
+ if (!what)
354
die(_("bug: unhandled diff status %c"), status);
337
- }
355
+ /* 1 for colon, which is not part of "what" */
356
+ len = strlen(padding) - (utf8_strwidth(what) + 1);
357
+ assert(len >= 0);
358
+ if (status == DIFF_STATUS_COPIED || status == DIFF_STATUS_RENAMED)
359
+ status_printf_more(s, c, "%s:%.*s%s -> %s",
360
+ what, len, padding, one, two);
361
+ else
362
+ status_printf_more(s, c, "%s:%.*s%s",
363
+ what, len, padding, one);
364
if (extra.len) {
365
status_printf_more(s, color(WT_STATUS_HEADER, s), "%s", extra.buf);
366
strbuf_release(&extra);