gettext usage in libraries



It did not change from older gnome... because gettext is the same.

In library, you should never call gettext("blah") or _("blah"), because
then gettext returns translation from the app domain (which most
probably does not have translation of "blah").

So, libraries call dgettext (GETTEXT_PACKAGE, "blah") [1].

There are two problems with this, related with initialization of
library:

1. If library is installed other prefix that /usr, gettext does not find
the catalogs. Therefore you need to call

	bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR)

and add the line to INCLUDES in Makefile.am:

        -DGNOMELOCALEDIR=\""$(datadir)/locale"\" \

2. If .po file is in charset other than utf-8, translations are got in
wrong charset. To avoid that, you can call

	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8")


The problem is, that both things need to be called only once. So, add
them to library initialize function (do they have one, how do I find
them?), or, make the library use custom

char* libfoo_gettext (char* str) {
	static int initialized = FALSE;
	if (!initialized) {
		bind......

What is recomended, best way to do such things?

For example how such things can be broken, look at libgnomeui. It does
not 1. neither 2. So nothing is translated ("Preferences", "Exit" and
other menu items from deprecated gnome-app-helper; "Warning", "Error"
etc from deprecated gnome-dialog-util etc)

[1]: In Gnome 2, it is recommendd to use GETTEXT_PACKAGE, and not just
PACKAGE, and define GETTEXT_PACKAGE=foo-2, while PACKAGE=foo, so that
translations could be installed in parallel.

-- 
Gediminas Paulauskas
Kaunas, Lithuania



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