1 /* i18n.c - gettext initialization
2 * Copyright (C) 2007 Free Software Foundation, Inc.
4 * This file is part of GnuPG.
6 * GnuPG is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * GnuPG is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
24 #ifdef HAVE_LANGINFO_CODESET
35 #ifdef USE_SIMPLE_GETTEXT
36 set_gettext_file (PACKAGE_GT
, "Software\\GNU\\GnuPG");
39 setlocale (LC_ALL
, "" );
40 bindtextdomain (PACKAGE_GT
, LOCALEDIR
);
41 textdomain (PACKAGE_GT
);
47 /* The Assuan agent protocol requires us to transmit utf-8 strings
48 thus we need a fuctnion to temporary switch gettext from native to
51 i18n_switchto_utf8 (void)
54 char *orig_codeset
= bind_textdomain_codeset (PACKAGE_GT
, NULL
);
55 #ifdef HAVE_LANGINFO_CODESET
57 orig_codeset
= nl_langinfo (CODESET
);
60 { /* We only switch when we are able to restore the codeset later.
61 Note that bind_textdomain_codeset does only return on memory
62 errors but not if a codeset is not available. Thus we don't
63 bother printing a diagnostic here. */
64 orig_codeset
= xstrdup (orig_codeset
);
65 if (!bind_textdomain_codeset (PACKAGE_GT
, "utf-8"))
77 /* Switch back to the saved codeset. */
79 i18n_switchback (char *saved_codeset
)
84 bind_textdomain_codeset (PACKAGE_GT
, saved_codeset
);
85 xfree (saved_codeset
);
93 /* Gettext variant which temporary switches to utf-8 for string. */
95 i18n_utf8 (const char *string
)
97 char *saved
= i18n_switchto_utf8 ();
98 const char *result
= _(string
);
99 i18n_switchback (saved
);