2007-06-06 20:12:30 +02:00
|
|
|
/* i18n.c - gettext initialization
|
|
|
|
* Copyright (C) 2007 Free Software Foundation, Inc.
|
|
|
|
*
|
|
|
|
* This file is part of GnuPG.
|
|
|
|
*
|
|
|
|
* GnuPG is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
2007-07-04 21:49:40 +02:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2007-06-06 20:12:30 +02:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* GnuPG is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2007-07-04 21:49:40 +02:00
|
|
|
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
2007-06-06 20:12:30 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
2007-10-19 17:58:38 +02:00
|
|
|
#ifdef HAVE_LOCALE_H
|
|
|
|
#include <locale.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_LANGINFO_CODESET
|
|
|
|
#include <langinfo.h>
|
|
|
|
#endif
|
2007-06-06 20:12:30 +02:00
|
|
|
|
2007-10-19 17:58:38 +02:00
|
|
|
#include "util.h"
|
2007-06-06 20:12:30 +02:00
|
|
|
#include "i18n.h"
|
|
|
|
|
2007-10-19 17:58:38 +02:00
|
|
|
|
2007-06-06 20:12:30 +02:00
|
|
|
void
|
|
|
|
i18n_init (void)
|
|
|
|
{
|
|
|
|
#ifdef USE_SIMPLE_GETTEXT
|
2008-11-04 20:54:02 +01:00
|
|
|
bindtextdomain (PACKAGE_GT, gnupg_localedir ());
|
2007-06-06 20:12:30 +02:00
|
|
|
#else
|
|
|
|
# ifdef ENABLE_NLS
|
|
|
|
setlocale (LC_ALL, "" );
|
|
|
|
bindtextdomain (PACKAGE_GT, LOCALEDIR);
|
|
|
|
textdomain (PACKAGE_GT);
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2007-10-19 17:58:38 +02:00
|
|
|
|
|
|
|
/* The Assuan agent protocol requires us to transmit utf-8 strings
|
2008-04-18 11:20:25 +02:00
|
|
|
thus we need a way to temporary switch gettext from native to
|
2007-10-19 17:58:38 +02:00
|
|
|
utf8. */
|
|
|
|
char *
|
|
|
|
i18n_switchto_utf8 (void)
|
|
|
|
{
|
2008-04-18 11:20:25 +02:00
|
|
|
#ifdef USE_SIMPLE_GETTEXT
|
|
|
|
gettext_select_utf8 (1);
|
2008-05-27 14:03:50 +02:00
|
|
|
return NULL;
|
2008-04-21 21:13:36 +02:00
|
|
|
#elif defined(ENABLE_NLS)
|
2007-10-19 17:58:38 +02:00
|
|
|
char *orig_codeset = bind_textdomain_codeset (PACKAGE_GT, NULL);
|
2008-04-18 11:20:25 +02:00
|
|
|
# ifdef HAVE_LANGINFO_CODESET
|
2007-10-19 17:58:38 +02:00
|
|
|
if (!orig_codeset)
|
|
|
|
orig_codeset = nl_langinfo (CODESET);
|
2008-04-18 11:20:25 +02:00
|
|
|
# endif
|
2007-10-19 17:58:38 +02:00
|
|
|
if (orig_codeset)
|
|
|
|
{ /* We only switch when we are able to restore the codeset later.
|
|
|
|
Note that bind_textdomain_codeset does only return on memory
|
|
|
|
errors but not if a codeset is not available. Thus we don't
|
|
|
|
bother printing a diagnostic here. */
|
|
|
|
orig_codeset = xstrdup (orig_codeset);
|
|
|
|
if (!bind_textdomain_codeset (PACKAGE_GT, "utf-8"))
|
|
|
|
{
|
|
|
|
xfree (orig_codeset);
|
|
|
|
orig_codeset = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return orig_codeset;
|
|
|
|
#else
|
|
|
|
return NULL;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Switch back to the saved codeset. */
|
|
|
|
void
|
|
|
|
i18n_switchback (char *saved_codeset)
|
|
|
|
{
|
2008-04-18 11:20:25 +02:00
|
|
|
#ifdef USE_SIMPLE_GETTEXT
|
2008-05-27 14:03:50 +02:00
|
|
|
(void)saved_codeset;
|
2008-04-18 11:20:25 +02:00
|
|
|
gettext_select_utf8 (0);
|
|
|
|
#elif defined(ENABLE_NLS)
|
2007-10-19 17:58:38 +02:00
|
|
|
if (saved_codeset)
|
|
|
|
{
|
|
|
|
bind_textdomain_codeset (PACKAGE_GT, saved_codeset);
|
|
|
|
xfree (saved_codeset);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
(void)saved_codeset;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Gettext variant which temporary switches to utf-8 for string. */
|
|
|
|
const char *
|
|
|
|
i18n_utf8 (const char *string)
|
|
|
|
{
|
|
|
|
char *saved = i18n_switchto_utf8 ();
|
|
|
|
const char *result = _(string);
|
|
|
|
i18n_switchback (saved);
|
|
|
|
return result;
|
|
|
|
}
|