gettext.hon commit Merge branch 'pc/submodule-helper' (a1bf46e)
   1/*
   2 * Copyright (c) 2010-2011 Ævar Arnfjörð Bjarmason
   3 *
   4 * This is a skeleton no-op implementation of gettext for Git.
   5 * You can replace it with something that uses libintl.h and wraps
   6 * gettext() to try out the translations.
   7 */
   8
   9#ifndef GETTEXT_H
  10#define GETTEXT_H
  11
  12#if defined(_) || defined(Q_)
  13#error "namespace conflict: '_' or 'Q_' is pre-defined?"
  14#endif
  15
  16#ifndef NO_GETTEXT
  17#       include <libintl.h>
  18#else
  19#       ifdef gettext
  20#               undef gettext
  21#       endif
  22#       define gettext(s) (s)
  23#       ifdef ngettext
  24#               undef ngettext
  25#       endif
  26#       define ngettext(s, p, n) ((n == 1) ? (s) : (p))
  27#endif
  28
  29#define FORMAT_PRESERVING(n) __attribute__((format_arg(n)))
  30
  31#ifndef NO_GETTEXT
  32extern void git_setup_gettext(void);
  33extern int gettext_width(const char *s);
  34#else
  35static inline void git_setup_gettext(void)
  36{
  37}
  38static inline int gettext_width(const char *s)
  39{
  40        return strlen(s);
  41}
  42#endif
  43
  44#ifdef GETTEXT_POISON
  45extern int use_gettext_poison(void);
  46#else
  47#define use_gettext_poison() 0
  48#endif
  49
  50static inline FORMAT_PRESERVING(1) const char *_(const char *msgid)
  51{
  52        if (!*msgid)
  53                return "";
  54        return use_gettext_poison() ? "# GETTEXT POISON #" : gettext(msgid);
  55}
  56
  57static inline FORMAT_PRESERVING(1) FORMAT_PRESERVING(2)
  58const char *Q_(const char *msgid, const char *plu, unsigned long n)
  59{
  60        if (use_gettext_poison())
  61                return "# GETTEXT POISON #";
  62        return ngettext(msgid, plu, n);
  63}
  64
  65/* Mark msgid for translation but do not translate it. */
  66#if !USE_PARENS_AROUND_GETTEXT_N
  67#define N_(msgid) msgid
  68#else
  69/*
  70 * Strictly speaking, this will lead to invalid C when
  71 * used this way:
  72 *      static const char s[] = N_("FOO");
  73 * which will expand to
  74 *      static const char s[] = ("FOO");
  75 * and in valid C, the initializer on the right hand side must
  76 * be without the parentheses.  But many compilers do accept it
  77 * as a language extension and it will allow us to catch mistakes
  78 * like:
  79 *      static const char *msgs[] = {
  80 *              N_("one")
  81 *              N_("two"),
  82 *              N_("three"),
  83 *              NULL
  84 *      };
  85 * (notice the missing comma on one of the lines) by forcing
  86 * a compilation error, because parenthesised ("one") ("two")
  87 * will not get silently turned into ("onetwo").
  88 */
  89#define N_(msgid) (msgid)
  90#endif
  91
  92const char *get_preferred_languages(void);
  93extern int is_utf8_locale(void);
  94
  95#endif