i18n: add no-op _() and N_() wrappers
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>
Tue, 22 Feb 2011 23:41:20 +0000 (23:41 +0000)
committerJunio C Hamano <gitster@pobox.com>
Tue, 8 Mar 2011 20:10:03 +0000 (12:10 -0800)
The _ function is for translating strings into the user's chosen
language. The N_ macro just marks translatable strings for the
xgettext(1) tool without translating them; it is intended for use in
contexts where a function call cannot be used. So, for example:

fprintf(stderr, _("Expansion of alias '%s' failed; "
"'%s' is not a git command\n"),
cmd, argv[0]);

and

const char *unpack_plumbing_errors[NB_UNPACK_TREES_ERROR_TYPES] = {
/* ERROR_WOULD_OVERWRITE */
N_("Entry '%s' would be overwritten by merge. Cannot merge."),
[...]

Define such _ and N_ in a new gettext.h and include it in cache.h, so
they can be used everywhere. Each just returns its argument for now.
_ is a function rather than a macro like N_ to avoid the temptation to
use _("foo") as a string literal (which would be a compile-time error
once _(s) expands to an expression for the translation of s).

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Makefile
cache.h
gettext.h [new file with mode: 0644]
index ade79232f4c3c080fa7d35c4b55870c416e49da6..c153f450c5fa3aa7f16798ec58342f1d97562964 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -515,6 +515,7 @@ LIB_H += diff.h
 LIB_H += dir.h
 LIB_H += exec_cmd.h
 LIB_H += fsck.h
 LIB_H += dir.h
 LIB_H += exec_cmd.h
 LIB_H += fsck.h
+LIB_H += gettext.h
 LIB_H += git-compat-util.h
 LIB_H += graph.h
 LIB_H += grep.h
 LIB_H += git-compat-util.h
 LIB_H += graph.h
 LIB_H += grep.h
diff --git a/cache.h b/cache.h
index 4a758babec4b53bf8b98572128c5bbf11019beb3..8188169ac66047d53b4623c5bf15370190773ba7 100644 (file)
--- a/cache.h
+++ b/cache.h
@@ -5,6 +5,7 @@
 #include "strbuf.h"
 #include "hash.h"
 #include "advice.h"
 #include "strbuf.h"
 #include "hash.h"
 #include "advice.h"
+#include "gettext.h"
 
 #include SHA1_HEADER
 #ifndef git_SHA_CTX
 
 #include SHA1_HEADER
 #ifndef git_SHA_CTX
diff --git a/gettext.h b/gettext.h
new file mode 100644 (file)
index 0000000..6949d73
--- /dev/null
+++ b/gettext.h
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2010-2011 Ævar Arnfjörð Bjarmason
+ *
+ * This is a skeleton no-op implementation of gettext for Git.
+ * You can replace it with something that uses libintl.h and wraps
+ * gettext() to try out the translations.
+ */
+
+#ifndef GETTEXT_H
+#define GETTEXT_H
+
+#ifdef _
+#error "namespace conflict: '_' is pre-defined?"
+#endif
+
+#define FORMAT_PRESERVING(n) __attribute__((format_arg(n)))
+
+static inline FORMAT_PRESERVING(1) const char *_(const char *msgid)
+{
+       return msgid;
+}
+
+/* Mark msgid for translation but do not translate it. */
+#define N_(msgid) (msgid)
+
+#endif