#ifndef GTINCL_H
#define GTINCL_H

/* This defines the dirname for bindtextdomain */
#ifndef GETTEXT_DIRNAME
#undef GETTEXT_DIRNAME
#endif

/* Define to the full name of this package. */
#ifndef PACKAGE_NAME
#undef PACKAGE_NAME
#endif

/* Define to 1 if you have the <libintl.h> header file. */
#undef HAVE_LIBINTL_H

/* Set this to 0 if gettext("") does not return the msgstr for msgid ""
 * That it returns something is a nice test and I do not consider this a bug.
 */
#define EXTENDED_CATALOG_SEARCH 1
#if EXTENDED_CATALOG_SEARCH
#include "helper.h"
/* a local work-around for xgettext (does not like the "") */
#define gettext_noscan(s) gettext(s)
#define scmxx_gettext_dirname(p) {\
          char* default_dirname = bindtextdomain(p,NULL);\
          bindtextdomain(p,GETTEXT_DIRNAME);\
          if (str_len(gettext_noscan("")) == 0) bindtextdomain(p,".");\
          if (str_len(gettext_noscan("")) == 0) bindtextdomain(p,"./share/locale");\
          if (str_len(gettext_noscan("")) == 0) bindtextdomain(p,"./locale");\
          if (str_len(gettext_noscan("")) == 0) bindtextdomain(p,"../share/locale");\
          if (str_len(gettext_noscan("")) == 0) bindtextdomain(p,"../locale");\
          if (str_len(gettext_noscan("")) == 0) bindtextdomain(p,default_dirname);\
        }
#undef gettext_noscan
#else
#define scmxx_gettext_dirname(p) {\
          bindtextdomain(p,GETTEXT_DIRNAME);\
        }
#endif

#ifdef HAVE_LIBINTL_H
#include <libintl.h>
#define scmxx_gettext_init() {\
          textdomain(PACKAGE_NAME);\
          scmxx_gettext_dirname(PACKAGE_NAME);\
        }
#define scmxx_gettext_codeset(c) bind_textdomain_codeset(PACKAGE_NAME,c);
#else
#define gettext(msg) ((char*)msg)
#define ngettext(msg,msgn,n) ((char*)((n != 1) ? msgn : msg))
#define scmxx_gettext_init() { }
#define scmxx_gettext_codeset(c) { }
#endif

#define _(msg) gettext(msg)
#define gettext_set_codeset(c) scmxx_gettext_codeset(c)

#endif
