mirror of
git://git.gnupg.org/gnupg.git
synced 2025-07-02 22:46:30 +02:00
Factored utf8 switching code out to i18n.c.
This commit is contained in:
parent
259a40c830
commit
c12ce55b25
12 changed files with 107 additions and 184 deletions
|
@ -1,3 +1,7 @@
|
|||
2007-10-19 Werner Koch <wk@g10code.com>
|
||||
|
||||
* i18n.c (i18n_switchto_utf8, i18n_switchback): New.
|
||||
|
||||
2007-10-01 Werner Koch <wk@g10code.com>
|
||||
|
||||
* sysutils.h (FD2INT, INT2FD): New.
|
||||
|
|
|
@ -18,9 +18,17 @@
|
|||
*/
|
||||
|
||||
#include <config.h>
|
||||
#ifdef HAVE_LOCALE_H
|
||||
#include <locale.h>
|
||||
#endif
|
||||
#ifdef HAVE_LANGINFO_CODESET
|
||||
#include <langinfo.h>
|
||||
#endif
|
||||
|
||||
#include "util.h"
|
||||
#include "i18n.h"
|
||||
|
||||
|
||||
void
|
||||
i18n_init (void)
|
||||
{
|
||||
|
@ -35,3 +43,59 @@ i18n_init (void)
|
|||
#endif
|
||||
}
|
||||
|
||||
|
||||
/* The Assuan agent protocol requires us to transmit utf-8 strings
|
||||
thus we need a fucntion to temporary switch gettext from native to
|
||||
utf8. */
|
||||
char *
|
||||
i18n_switchto_utf8 (void)
|
||||
{
|
||||
#ifdef ENABLE_NLS
|
||||
char *orig_codeset = bind_textdomain_codeset (PACKAGE_GT, NULL);
|
||||
#ifdef HAVE_LANGINFO_CODESET
|
||||
if (!orig_codeset)
|
||||
orig_codeset = nl_langinfo (CODESET);
|
||||
#endif
|
||||
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)
|
||||
{
|
||||
#ifdef ENABLE_NLS
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -39,6 +39,9 @@
|
|||
#endif /*!USE_SIMPLE_GETTEXT*/
|
||||
|
||||
void i18n_init (void);
|
||||
char *i18n_switchto_utf8 (void);
|
||||
void i18n_switchback (char *saved_codeset);
|
||||
const char *i18n_utf8 (const char *string);
|
||||
|
||||
|
||||
#endif /*GNUPG_COMMON_I18N_H*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue