C_ macros

This commit is contained in:
Yevgen Muntyan 2008-09-09 22:40:29 -05:00
parent 693b466485
commit dbcda6647e
4 changed files with 115 additions and 0 deletions

View File

@ -797,3 +797,47 @@ g_string_append_vprintf (GString *string,
} }
#endif /* !GLIB_CHECK_VERSION(2,14,0) */ #endif /* !GLIB_CHECK_VERSION(2,14,0) */
#if !GLIB_CHECK_VERSION(2,16,0)
#include <libintl.h>
const char *
g_dpgettext (const char *domain,
const char *msgctxtid,
gsize msgidoffset)
{
const char *translation;
translation = dgettext (domain, msgctxtid);
if (translation == msgctxtid)
{
const char *sep;
if (msgidoffset > 0)
return msgctxtid + msgidoffset;
sep = strchr (msgctxtid, '|');
if (sep)
{
/* try with '\004' instead of '|', in case
* xgettext -kQ_:1g was used
*/
gchar *tmp = g_alloca (strlen (msgctxtid) + 1);
strcpy (tmp, msgctxtid);
tmp[sep - msgctxtid] = '\004';
translation = dgettext (domain, tmp);
if (translation == tmp)
return sep + 1;
}
}
return translation;
}
#endif /* !GLIB_CHECK_VERSION(2,16,0) */

View File

@ -109,6 +109,16 @@ void g_string_append_vprintf (GString *string,
#endif /* !GLIB_CHECK_VERSION(2,14,0) */ #endif /* !GLIB_CHECK_VERSION(2,14,0) */
#if !GLIB_CHECK_VERSION(2,16,0)
#define g_dpgettext _moo_compat_g_dpgettext
const char *g_dpgettext (const char *domain,
const char *msgctxtid,
gsize msgidoffset);
#endif /* !GLIB_CHECK_VERSION(2,16,0) */
G_END_DECLS G_END_DECLS
#endif /* MOOUTILS_COMPAT_H */ #endif /* MOOUTILS_COMPAT_H */

View File

@ -15,6 +15,7 @@
#include "mooutils/mooi18n.h" #include "mooutils/mooi18n.h"
#include "mooutils/mooutils-misc.h" #include "mooutils/mooutils-misc.h"
#include "mooutils/moocompat.h"
#include <glib.h> #include <glib.h>
@ -49,6 +50,53 @@ moo_gettext (const char *string)
#endif /* !ENABLE_NLS */ #endif /* !ENABLE_NLS */
} }
const char *
moo_pgettext (const char *msgctxtid, gsize msgidoffset)
{
#ifdef ENABLE_NLS
g_return_val_if_fail (msgctxtid != NULL, NULL);
init_gettext ();
return moo_dpgettext (GETTEXT_PACKAGE, msgctxtid, msgidoffset);
#else /* !ENABLE_NLS */
return msgctxtid;
#endif /* !ENABLE_NLS */
}
const char *
moo_pgettext2 (const char *context, const char *msgctxtid)
{
#ifdef ENABLE_NLS
char *tmp;
const char *translation;
g_return_val_if_fail (msgctxtid != NULL, NULL);
init_gettext ();
tmp = g_strjoin (context, "\004", msgctxtid, NULL);
translation = dgettext (GETTEXT_PACKAGE, tmp);
if (translation == tmp)
translation = msgctxtid;
g_free (tmp);
return translation;
#else /* !ENABLE_NLS */
return msgctxtid;
#endif /* !ENABLE_NLS */
}
const char *
moo_dpgettext (const char *domain, const char *msgctxtid, gsize msgidoffset)
{
g_return_val_if_fail (domain != NULL, NULL);
g_return_val_if_fail (msgctxtid != NULL, NULL);
#ifdef ENABLE_NLS
return g_dpgettext (GETTEXT_PACKAGE, msgctxtid, msgidoffset);
#else
return msgctxtid + msgidoffset;
#endif
}
const char * const char *
_moo_gsv_gettext (const char *string) _moo_gsv_gettext (const char *string)
{ {

View File

@ -22,12 +22,16 @@
#ifdef ENABLE_NLS #ifdef ENABLE_NLS
#include <libintl.h> #include <libintl.h>
#include <string.h>
#define _(String) moo_gettext (String) #define _(String) moo_gettext (String)
#define Q_(String) g_strip_context ((String), moo_gettext (String)) #define Q_(String) g_strip_context ((String), moo_gettext (String))
#define N_(String) (String) #define N_(String) (String)
#define D_(String,Domain) dgettext (Domain, String) #define D_(String,Domain) dgettext (Domain, String)
#define QD_(String,Domain) g_strip_context ((String), D_ (String, Domain)) #define QD_(String,Domain) g_strip_context ((String), D_ (String, Domain))
#define C_(Context,String) moo_pgettext (Context "\004" String, strlen (Context) + 1)
#define NC_(Context,String) (String)
#define DC_(Context,String,Domain) moo_dpgettext (Domain, Context "\004" String, strlen (Context) + 1)
#else /* !ENABLE_NLS */ #else /* !ENABLE_NLS */
@ -38,11 +42,17 @@
#undef ngettext #undef ngettext
#undef bindtextdomain #undef bindtextdomain
#undef bind_textdomain_codeset #undef bind_textdomain_codeset
#define _(String) (String) #define _(String) (String)
#define N_(String) (String) #define N_(String) (String)
#define Q_(String) g_strip_context ((String), (String)) #define Q_(String) g_strip_context ((String), (String))
#define D_(String,Domain) (String) #define D_(String,Domain) (String)
#define QD_(String,Domain) g_strip_context ((String), (String)) #define QD_(String,Domain) g_strip_context ((String), (String))
#define C_(Context,String) (String)
#define NC_(Context,String) (String)
#define DC_(Context,String,Domain) (String)
#define textdomain(String) (String) #define textdomain(String) (String)
#define gettext(String) (String) #define gettext(String) (String)
#define dgettext(Domain,String) (String) #define dgettext(Domain,String) (String)
@ -58,6 +68,9 @@
G_BEGIN_DECLS G_BEGIN_DECLS
const char *moo_gettext (const char *string) G_GNUC_FORMAT (1); const char *moo_gettext (const char *string) G_GNUC_FORMAT (1);
const char *moo_pgettext (const char *msgctxtid, gsize msgidoffset) G_GNUC_FORMAT (1);
const char *moo_pgettext2 (const char *context, const char *msgctxtid) G_GNUC_FORMAT (2);
const char *moo_dpgettext (const char *domain, const char *msgctxtid, gsize msgidoffset) G_GNUC_FORMAT (2);
const char *_moo_gsv_gettext (const char *string) G_GNUC_FORMAT (1); const char *_moo_gsv_gettext (const char *string) G_GNUC_FORMAT (1);
char *_moo_gsv_dgettext (const char *domain, const char *string) G_GNUC_FORMAT (2); char *_moo_gsv_dgettext (const char *domain, const char *string) G_GNUC_FORMAT (2);