1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
|
/*
This file is part of GNUnet.
(C) 2010, 2011 Christian Grothoff (and other contributing authors)
GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
by the Free Software Foundation; either version 2, or (at your
option) any later version.
GNUnet 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
along with GNUnet; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
/**
* @file src/lib/nls.c
* @brief natural language support
* @author Christian Grothoff
*/
#include "gnunet_gtk.h"
#if ENABLE_NLS
#include <locale.h>
#endif
/**
* Initialize GNU gettext for message translation.
*/
void
GNUNET_GTK_setup_nls ()
{
#if ENABLE_NLS
char *path;
setlocale (LC_ALL, "");
GNUNET_asprintf (&path, "%s/%s/locale/", GNUNET_GTK_get_data_dir (),
PACKAGE_NAME);
bindtextdomain ("gnunet-gtk", path);
textdomain ("gnunet-gtk");
bind_textdomain_codeset ("GNUnet", "UTF-8");
bind_textdomain_codeset ("gnunet-gtk", "UTF-8");
GNUNET_free (path);
#else
fprintf (stderr,
"WARNING: gnunet-gtk was compiled without i18n support (did CFLAGS contain -Werror?).\n");
#endif
}
char *
GNUNET_GTK_from_utf8_to_loc (gchar *str_utf8)
{
char *str_loc;
const char *loc_charset;
gboolean is_UTF8;
if (NULL == str_utf8)
return NULL;
is_UTF8 = g_get_charset (&loc_charset);
if (is_UTF8)
str_loc = GNUNET_strdup (str_utf8);
else
str_loc = GNUNET_STRINGS_from_utf8 (str_utf8, strlen (str_utf8), loc_charset);
return str_loc;
}
char *
GNUNET_GTK_from_loc_to_utf8 (gchar *str_loc)
{
char *str_utf8;
const char *loc_charset;
gboolean is_UTF8;
if (NULL == str_loc)
return NULL;
is_UTF8 = g_get_charset (&loc_charset);
if (is_UTF8)
str_utf8 = GNUNET_strdup (str_loc);
else
str_utf8 = GNUNET_STRINGS_to_utf8 (str_loc, strlen (str_loc), loc_charset);
return str_utf8;
}
/* This is copied from GLib */
static gboolean
get_filename_charset (const gchar **filename_charset)
{
const gchar **charsets;
gboolean is_utf8;
is_utf8 = g_get_filename_charsets (&charsets);
if (filename_charset)
*filename_charset = charsets[0];
return is_utf8;
}
char *
GNUNET_GTK_from_filename_to_utf8 (gchar *filename)
{
char *str_utf8;
const char *filename_charset;
gboolean is_UTF8;
if (NULL == filename)
return NULL;
is_UTF8 = get_filename_charset (&filename_charset);
if (is_UTF8)
str_utf8 = GNUNET_strdup (filename);
else
str_utf8 = GNUNET_STRINGS_to_utf8 (filename, strlen (filename), filename_charset);
return str_utf8;
}
char *
GNUNET_GTK_from_utf8_to_filename (gchar *str_utf8)
{
char *filename;
const char *filename_charset;
gboolean is_UTF8;
if (NULL == str_utf8)
return NULL;
is_UTF8 = get_filename_charset (&filename_charset);
if (is_UTF8)
filename = GNUNET_strdup (str_utf8);
else
filename = GNUNET_STRINGS_from_utf8 (str_utf8, strlen (str_utf8), filename_charset);
return filename;
}
char *
GNUNET_GTK_from_loc_to_filename (gchar *str_loc)
{
char *filename;
const char *filename_charset;
const char *loc_charset;
gboolean is_filename_UTF8, is_loc_UTF8;
if (NULL == str_loc)
return NULL;
is_filename_UTF8 = get_filename_charset (&filename_charset);
is_loc_UTF8 = g_get_charset (&loc_charset);
if (is_filename_UTF8 && is_loc_UTF8)
filename = GNUNET_strdup (str_loc);
else if (is_filename_UTF8)
filename = GNUNET_STRINGS_to_utf8 (str_loc, strlen (str_loc), loc_charset);
else if (is_loc_UTF8)
filename = GNUNET_STRINGS_from_utf8 (str_loc, strlen (str_loc), filename_charset);
else
/* Pray that iconv() knows these charsets */
filename = GNUNET_STRINGS_conv (str_loc, strlen (str_loc), loc_charset, filename_charset);
return filename;
}
char *
GNUNET_GTK_from_filename_to_loc (gchar *filename)
{
char *str_loc;
const char *loc_charset;
const char *filename_charset;
gboolean is_loc_UTF8, is_filename_UTF8;
if (NULL == filename)
return NULL;
is_filename_UTF8 = get_filename_charset (&filename_charset);
is_loc_UTF8 = g_get_charset (&loc_charset);
if (is_loc_UTF8 && is_filename_UTF8)
str_loc = GNUNET_strdup (filename);
else if (is_loc_UTF8)
str_loc = GNUNET_STRINGS_to_utf8 (filename, strlen (filename), filename_charset);
else if (is_filename_UTF8)
str_loc = GNUNET_STRINGS_from_utf8 (filename, strlen (filename), loc_charset);
else
/* Pray that iconv() knows these charsets */
str_loc = GNUNET_STRINGS_conv (filename, strlen (filename), filename_charset, loc_charset);
return str_loc;
}
/* Returns filename form filechooser, encoded in locale-dependent
* encoding, suitable to be given to CRT and/or GNUnet
*/
char *
GNUNET_GTK_filechooser_get_filename_loc (GtkFileChooser *fc)
{
char *filename_loc;
gchar *filename = gtk_file_chooser_get_filename (fc);
filename_loc = GNUNET_GTK_from_filename_to_loc (filename);
g_free (filename);
return filename_loc;
}
gchar *
GNUNET_GTK_filechooser_get_filename_utf8 (GtkFileChooser *fc)
{
char *filename_utf8;
gchar *filename = gtk_file_chooser_get_filename (fc);
filename_utf8 = GNUNET_GTK_from_filename_to_utf8 (filename);
g_free (filename);
return filename_utf8;
}
/* end of nls.c */
|