text representation in gtk+ 1.3.x



I have a question in gtk+'s UTF-8 switching related to message localization
with gettext().

In 1.2.x, gtk widgets take native encoding for text representation in
public APIs such as gtk_label_set_text, gtk_entry_set_text, but in
1.3.x, they always take "UTF-8" encoding, and my understanding is
applications must take care of code conversion to "UTF-8" to use these
APIs.

If bind_textdomain_codeset() is available, it won't have much impact,
but we cannot assume it is always the case, so a sample gtk programming
to take care of other case will become like below. 

Do I really have to do like this or is there any good MACRO or something to
avoid much of coding?

thanks,
-toshi
--------

 1.2.x
 		textdomain(APPLICATION_PACKAGE);
 		...
		gtk_label_new(gettext("Hello"));
 1.3.x
 		textdomain(APPLICATION_PACKAGE);
#ifdef HAVE_BIND_TEXTDOMAIN_CODESET
		bind_textdomain_codeset(APPLICATION_PACKAGE, "UTF-8");
		...
		gtk_label_new(gettext("Hello"));
#else
		...
		{
		gchar *utf8_str = NULL;
		gchar *native_str = gettext("Hello");
		GError *error;
		gchar *charset;
		
		g_get_charset(&charset);
		utf8_str = g_convert(native_str, -1, "UTF-8", charset,
			            NULL, NULL, &error);
		if (!utf8_str)		            
		    {
	         g_warning ("Cannot convert text from UTF-8 to %s: %s",
			   charset, error->message);
	         g_error_free (error);
		 utf8_str = g_strdup("Hello");  // fallback
	        } 
	        gtk_label_new(utf8_str);
		g_free(utf8_str);
		}
#endif





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]