summaryrefslogtreecommitdiff
path: root/gettext.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2012-09-18 14:35:54 -0700
committerJunio C Hamano <gitster@pobox.com>2012-09-18 14:35:55 -0700
commitd71abd99f82e7076775f12deb9326f7d26761591 (patch)
treed8e065cd6e33d3c5617dfe1de2df3379818db338 /gettext.c
parent3c7d50979abd0fbc8e1d7a1baac4c8a26e440a7c (diff)
parent754395d3052fc0d46948b2ff7006b3c6701785c8 (diff)
downloadgit-d71abd99f82e7076775f12deb9326f7d26761591.tar.gz
Merge branch 'nd/fetch-status-alignment'
The status report from "git fetch", when messages like 'up-to-date' are translated, did not align the branch names well. * nd/fetch-status-alignment: fetch: align per-ref summary report in UTF-8 locales
Diffstat (limited to 'gettext.c')
-rw-r--r--gettext.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/gettext.c b/gettext.c
index f75bca7f56..71e954563d 100644
--- a/gettext.c
+++ b/gettext.c
@@ -4,6 +4,8 @@
#include "git-compat-util.h"
#include "gettext.h"
+#include "strbuf.h"
+#include "utf8.h"
#ifndef NO_GETTEXT
# include <locale.h>
@@ -27,10 +29,9 @@ int use_gettext_poison(void)
#endif
#ifndef NO_GETTEXT
+static const char *charset;
static void init_gettext_charset(const char *domain)
{
- const char *charset;
-
/*
This trick arranges for messages to be emitted in the user's
requested encoding, but avoids setting LC_CTYPE from the
@@ -128,4 +129,14 @@ void git_setup_gettext(void)
init_gettext_charset("git");
textdomain("git");
}
+
+/* return the number of columns of string 's' in current locale */
+int gettext_width(const char *s)
+{
+ static int is_utf8 = -1;
+ if (is_utf8 == -1)
+ is_utf8 = !strcmp(charset, "UTF-8");
+
+ return is_utf8 ? utf8_strwidth(s) : strlen(s);
+}
#endif