diff --git a/docs/reference/ChangeLog b/docs/reference/ChangeLog index f9a818c01a..7f36d770d1 100644 --- a/docs/reference/ChangeLog +++ b/docs/reference/ChangeLog @@ -1,3 +1,7 @@ +2002-01-06 Havoc Pennington + + * gtk/question_index.sgml: a few more questions I thought of + 2002-01-06 Havoc Pennington * gtk/gtk-docs.sgml: remove gtk- prefix from TreeView and a few diff --git a/docs/reference/gtk/question_index.sgml b/docs/reference/gtk/question_index.sgml index ee85179f11..5ec2b48dd2 100644 --- a/docs/reference/gtk/question_index.sgml +++ b/docs/reference/gtk/question_index.sgml @@ -122,6 +122,138 @@ threading primitives. + + +How do I internationalize a GTK+ program? + + + + +Most people use GNU +gettext, already required in order to install GLib. On a UNIX +or Linux system with gettext installed, type info +gettext to read the documentation. + + +The short checklist on how to use gettext is: call +bindtextdomain() so gettext can find the files +containing your translations, call textdomain() +to set the default translation domain, then call +gettext() to look up each string to be translated +in the default domain. Conventionally, people define macros as +follows for convenience: + + + #define _(x) gettext (x) + #define N_(x) x + + +You use N_() (N stands for no-op) to mark +a string for translation in a context where a function call +to gettext() is not allowed, such as in +an array initializer. You eventually have to call +gettext() on the string to actually fetch the +translation. _() both marks the string for +translation and actually translates it. + + +Code using these macros ends up looking like this: + + + #include <libintl.h> + + #define _(x) gettext (x) + #define N_(x) x + + static const char *global_variable = N_("Translate this string"); + + static void + make_widgets (void) + { + GtkWidget *label1; + GtkWidget *label2; + + label1 = gtk_label_new (_("Another string to translate")); + label2 = gtk_label_new (_(global_variable)); +... + + + + +Libraries using gettext should use dgettext() +instead of gettext(), which allows +them to specify the translation domain each time they +ask for a translation. Libraries should also avoid calling +textdomain(), since they'll be specifying +the domain instead of using the default. +For dgettext() the _() macro +can be defined as: + + + #define _(x) dgettext ("MyDomain", x) + + + + + + + + +How do I use GTK+ with C++? + + + + +There are two ways to approach this. The GTK+ header files use the subset +of C that's also valid C++, so you can simply use the normal GTK+ API +in a C++ program. Alternatively, you can use a "C++ binding" +such as gtkmm +which provides a C++-native API. + + +When using GTK+ directly, keep in mind that only functions can be +connected to signals, not methods. So you will need to use global +functions or "static" class functions for signal connections. + + +Another common issue when using GTK+ directly is that +C++ will not implicitly convert an integer to an enumeration. +This comes up when using bitfields; in C you can write the following +code: + + + gdk_window_set_events (gdk_window, + GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK); + + +while in C++ you must write: + + + gdk_window_set_events (gdk_window, + (GdkEventMask) GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK); + + +There are very few functions that require this cast, however. + + + + + + + +How do I use GTK+ with other non-C languages? + + + + +See the list of language +bindings on http://www.gtk.org. + + + + +