[PATCH 1/3] i18n: add no-op _() and N_() wrappers

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Ãvar ArnfjÃrà Bjarmason <avarab@xxxxxxxxx>

The _ function is meant to be used to translate strings into the
user's chosen language.

The N_ macro is a marker for xgettext to find translatable strings
in contexts where a function call cannot be used directly, like so:

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

Its result is still untranslated and should be fed to _ before it
is printed.

Making _ a function and N_ a macro avoids the temptation to use
_("foo") instead of N_("foo") as a string literal.

Define these in a new gettext.h and include it in cache.h, so they can
be used everywhere.  They just return their argument for now.  To
split up the gettext series I'm first submitting patches to gettextize
the source tree before I add any of the Makefile and C changes needed
to actually use translations.

Signed-off-by: Ãvar ArnfjÃrà Bjarmason <avarab@xxxxxxxxx>
Signed-off-by: Jonathan Nieder <jrnieder@xxxxxxxxx>
---
 Makefile  |    1 +
 cache.h   |    1 +
 gettext.h |   26 ++++++++++++++++++++++++++
 3 files changed, 28 insertions(+), 0 deletions(-)
 create mode 100644 gettext.h

diff --git a/Makefile b/Makefile
index ade7923..c153f45 100644
--- 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 += gettext.h
 LIB_H += git-compat-util.h
 LIB_H += graph.h
 LIB_H += grep.h
diff --git a/cache.h b/cache.h
index 3abf895..a465f38 100644
--- a/cache.h
+++ b/cache.h
@@ -5,6 +5,7 @@
 #include "strbuf.h"
 #include "hash.h"
 #include "advice.h"
+#include "gettext.h"
 
 #include SHA1_HEADER
 #ifndef git_SHA_CTX
diff --git a/gettext.h b/gettext.h
new file mode 100644
index 0000000..dc44825
--- /dev/null
+++ b/gettext.h
@@ -0,0 +1,26 @@
+#ifndef GETTEXT_H
+#define GETTEXT_H
+
+/*
+ * Copyright (c) 2010 Ã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.
+ */
+
+#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
-- 
1.7.4.1

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]