medit/moo/mooutils/mooi18n.c

96 lines
2.3 KiB
C
Raw Normal View History

/*
* mooi18n.c
*
* Copyright (C) 2004-2008 by Yevgen Muntyan <muntyan@tamu.edu>
*
* This file is part of medit. medit is free software; you can
* redistribute it and/or modify it under the terms of the
* GNU Lesser General Public License as published by the
* Free Software Foundation; either version 2.1 of the License,
* or (at your option) any later version.
*
* You should have received a copy of the GNU Lesser General Public
* License along with medit. If not, see <http://www.gnu.org/licenses/>.
*/
#include "mooutils/mooi18n.h"
2006-12-10 16:52:08 -06:00
#include "mooutils/mooutils-misc.h"
#include <glib.h>
2007-06-20 13:46:26 -05:00
#ifdef ENABLE_NLS
2007-06-18 05:18:02 -05:00
static void
init_gettext (void)
{
static gboolean been_here = FALSE;
if (!been_here)
{
been_here = TRUE;
bindtextdomain (GETTEXT_PACKAGE, moo_get_locale_dir ());
2007-06-18 05:18:02 -05:00
bindtextdomain (GETTEXT_PACKAGE "-gsv", moo_get_locale_dir ());
2006-12-10 16:52:08 -06:00
#ifdef HAVE_BIND_TEXTDOMAIN_CODESET
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
2007-06-18 05:18:02 -05:00
bind_textdomain_codeset (GETTEXT_PACKAGE "-gsv", "UTF-8");
2006-12-10 16:52:08 -06:00
#endif
}
2007-06-18 05:18:02 -05:00
}
2007-06-20 13:46:26 -05:00
#endif /* ENABLE_NLS */
2007-06-18 05:18:02 -05:00
const char *
moo_gettext (const char *string)
{
#ifdef ENABLE_NLS
g_return_val_if_fail (string != NULL, NULL);
init_gettext ();
return dgettext (GETTEXT_PACKAGE, string);
2006-08-05 02:07:56 -05:00
#else /* !ENABLE_NLS */
return string;
#endif /* !ENABLE_NLS */
}
2007-05-27 15:08:41 -05:00
2007-06-18 05:18:02 -05:00
const char *
_moo_gsv_gettext (const char *string)
{
#ifdef ENABLE_NLS
g_return_val_if_fail (string != NULL, NULL);
init_gettext ();
return dgettext (GETTEXT_PACKAGE "-gsv", string);
#else /* !ENABLE_NLS */
return string;
#endif /* !ENABLE_NLS */
}
2007-05-27 15:08:41 -05:00
char *
2007-06-18 05:18:02 -05:00
_moo_gsv_dgettext (const char *domain, const char *string)
2007-05-27 15:08:41 -05:00
{
#ifdef ENABLE_NLS
gchar *tmp;
const gchar *translated;
g_return_val_if_fail (string != NULL, NULL);
2007-06-18 05:18:02 -05:00
init_gettext ();
2007-05-27 15:08:41 -05:00
if (domain == NULL)
2007-06-18 05:18:02 -05:00
return g_strdup (_moo_gsv_gettext (string));
2007-05-27 15:08:41 -05:00
translated = dgettext (domain, string);
if (strcmp (translated, string) == 0)
2007-06-18 05:18:02 -05:00
return g_strdup (_moo_gsv_gettext (string));
2007-05-27 15:08:41 -05:00
if (g_utf8_validate (translated, -1, NULL))
return g_strdup (translated);
tmp = g_locale_to_utf8 (translated, -1, NULL, NULL, NULL);
if (tmp == NULL)
return g_strdup (string);
else
return tmp;
#else
return g_strdup (string);
#endif /* !ENABLE_NLS */
}