summaryrefslogtreecommitdiff
path: root/include/wolf/i18n/gettext.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/wolf/i18n/gettext.h')
-rw-r--r--include/wolf/i18n/gettext.h93
1 files changed, 93 insertions, 0 deletions
diff --git a/include/wolf/i18n/gettext.h b/include/wolf/i18n/gettext.h
new file mode 100644
index 0000000..3d4a4f9
--- /dev/null
+++ b/include/wolf/i18n/gettext.h
@@ -0,0 +1,93 @@
+/*
+ Copyright (C) 2008 Andreas Baumann <abaumann@yahoo.com>
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef WOLF_GETTEXT_H
+#define WOLF_GETTEXT_H
+
+/**
+ * @addtogroup wolf_port Porting
+ * @{
+ */
+
+/**
+ * @file gettext.h
+ * @brief localization header, nivelating some problems in gettext/libintl
+ * @author Andreas Baumann <abaumann@yahoo.com>
+ */
+
+/* some distributors like to disable NLS */
+#if ENABLE_NLS
+
+/* Some older versions of libintl.h make tests for the value __APPLE_CC though
+ * this macro can be undefined! Nice, defining it here as 0.
+ * (Noticed on OpenBSD 4.3)
+ */
+#if !defined( __APPLE_CC )
+#define __APPLE_CC__ 0
+#endif
+
+/* define a proper prototype with format_arg so that gcc doesn't croak. This
+ * is a problem on systems which have an onlder libintl.h where the declarations
+ * are missing. So we define a first prototype here and hope the compiler survives
+ * the redefiniton in libintl.h but for a format_arg (urgh!). Experienced only
+ * on NetBSD 4.1
+ */
+#if defined __GNUC__
+#if defined GETTEXT_NEEDS_FORMAT_ARG
+char *gettext( const char *__msgid ) __attribute__ ( ( format_arg ( 1 ) ) );
+char *libintl_gettext( const char *__msgid ) __attribute__ ( ( format_arg ( 1 ) ) );
+char *dgettext( const char *__domainname, const char *__msgid ) __attribute__ ( ( format_arg ( 2 ) ) );
+char *libintl_dgettext( const char *__domainname, const char *__msgid ) __attribute__ ( ( format_arg ( 2 ) ) );
+#endif
+#endif
+
+#include <libintl.h> /* for gettext, bindtextdomain */
+
+#include <locale.h> /* for setlocale */
+
+/** It's much easier to define a DEFAULT_TEXT_DOMAIN and map gettext to a
+ * dgettext, so that we don't have to call 'textdomain' anywhere in the
+ * library. Define this before including gettext.h
+ */
+#if defined DEFAULT_TEXT_DOMAIN
+#undef gettext
+#define gettext( msgid ) dgettext( DEFAULT_TEXT_DOMAIN, msgid )
+#endif /* defined DEFAULT_TEXT_DOMAIN */
+
+#else /* ENABLE_NLS */
+
+#define gettext( msgid ) ( (const char *)( msgid ) )
+#define LC_ALL 1
+#define setlocale( category, loc ) ( NULL )
+#define bindtextdomain( domain, directory ) ( NULL )
+#define textdomain( domain )( NULL )
+
+#endif /* ENABLE_NLS */
+
+/* a noop marker which let's xgettext extract the message but doesn't
+ * call the gettext() function if NLS is enabled.
+ */
+#define gettext_noop( s ) s
+
+/* shorthand macro for lazy people */
+#define _( s ) gettext( s )
+
+void wolf_port_initialize_i18n( const char *argv0, const char *app );
+
+/** @} */ /* @addtogroup wolf_port */
+
+#endif /* ifndef WOLF_GETTEXT_H */