1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-05-06 15:46:41 +02:00
git/gettext.h
Johannes Schindelin b524e896b6 Sync with 2.30.9
* maint-2.30: (23 commits)
  Git 2.30.9
  gettext: avoid using gettext if the locale dir is not present
  apply --reject: overwrite existing `.rej` symlink if it exists
  http.c: clear the 'finished' member once we are done with it
  clone.c: avoid "exceeds maximum object size" error with GCC v12.x
  range-diff: use ssize_t for parsed "len" in read_patches()
  range-diff: handle unterminated lines in read_patches()
  range-diff: drop useless "offset" variable from read_patches()
  t5604: GETTEXT_POISON fix, conclusion
  t5604: GETTEXT_POISON fix, part 1
  t5619: GETTEXT_POISON fix
  t0003: GETTEXT_POISON fix, conclusion
  t0003: GETTEXT_POISON fix, part 1
  t0033: GETTEXT_POISON fix
  http: support CURLOPT_PROTOCOLS_STR
  http: prefer CURLOPT_SEEKFUNCTION to CURLOPT_IOCTLFUNCTION
  http-push: prefer CURLOPT_UPLOAD to CURLOPT_PUT
  ci: install python on ubuntu
  ci: use the same version of p4 on both Linux and macOS
  ci: remove the pipe after "p4 -V" to catch errors
  github-actions: run gcc-8 on ubuntu-20.04 image
  ...
2023-04-17 21:15:44 +02:00

94 lines
2.1 KiB
C

/*
* 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
#if defined(_) || defined(Q_)
#error "namespace conflict: '_' or 'Q_' is pre-defined?"
#endif
#ifndef NO_GETTEXT
# include <libintl.h>
#else
# ifdef gettext
# undef gettext
# endif
# define gettext(s) (s)
# ifdef ngettext
# undef ngettext
# endif
# define ngettext(s, p, n) ((n == 1) ? (s) : (p))
#endif
#define FORMAT_PRESERVING(n) __attribute__((format_arg(n)))
#ifndef NO_GETTEXT
extern int git_gettext_enabled;
void git_setup_gettext(void);
int gettext_width(const char *s);
#else
#define git_gettext_enabled (0)
static inline void git_setup_gettext(void)
{
}
static inline int gettext_width(const char *s)
{
return strlen(s);
}
#endif
static inline FORMAT_PRESERVING(1) const char *_(const char *msgid)
{
if (!*msgid)
return "";
if (!git_gettext_enabled)
return msgid;
return gettext(msgid);
}
static inline FORMAT_PRESERVING(1) FORMAT_PRESERVING(2)
const char *Q_(const char *msgid, const char *plu, unsigned long n)
{
if (!git_gettext_enabled)
return n == 1 ? msgid : plu;
return ngettext(msgid, plu, n);
}
/* Mark msgid for translation but do not translate it. */
#if !USE_PARENS_AROUND_GETTEXT_N
#define N_(msgid) msgid
#else
/*
* Strictly speaking, this will lead to invalid C when
* used this way:
* static const char s[] = N_("FOO");
* which will expand to
* static const char s[] = ("FOO");
* and in valid C, the initializer on the right hand side must
* be without the parentheses. But many compilers do accept it
* as a language extension and it will allow us to catch mistakes
* like:
* static const char *msgs[] = {
* N_("one")
* N_("two"),
* N_("three"),
* NULL
* };
* (notice the missing comma on one of the lines) by forcing
* a compilation error, because parenthesised ("one") ("two")
* will not get silently turned into ("onetwo").
*/
#define N_(msgid) (msgid)
#endif
const char *get_preferred_languages(void);
int is_utf8_locale(void);
#endif