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 bindtextdomain (PACKAGE_GT
, gnupg_localedir ());
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 way to temporary switch gettext from native to
51 i18n_switchto_utf8 (void)
53 #ifdef USE_SIMPLE_GETTEXT
54 gettext_select_utf8 (1);
56 #elif defined(ENABLE_NLS)
57 char *orig_codeset
= bind_textdomain_codeset (PACKAGE_GT
, NULL
);
58 # ifdef HAVE_LANGINFO_CODESET
60 orig_codeset
= nl_langinfo (CODESET
);
63 { /* We only switch when we are able to restore the codeset later.
64 Note that bind_textdomain_codeset does only return on memory
65 errors but not if a codeset is not available. Thus we don't
66 bother printing a diagnostic here. */
67 orig_codeset
= xstrdup (orig_codeset
);
68 if (!bind_textdomain_codeset (PACKAGE_GT
, "utf-8"))
80 /* Switch back to the saved codeset. */
82 i18n_switchback (char *saved_codeset
)
84 #ifdef USE_SIMPLE_GETTEXT
86 gettext_select_utf8 (0);
87 #elif defined(ENABLE_NLS)
90 bind_textdomain_codeset (PACKAGE_GT
, saved_codeset
);
91 xfree (saved_codeset
);
99 /* Gettext variant which temporary switches to utf-8 for string. */
101 i18n_utf8 (const char *string
)
103 char *saved
= i18n_switchto_utf8 ();
104 const char *result
= _(string
);
105 i18n_switchback (saved
);