Skip to content
davidmoreno edited this page May 25, 2011 · 2 revisions

Internationalization

Using otemplates, or custom handlers there is support for gettext. As gettext has severe limitations about multithreading and multi language support, this has to be 'hacked' at initialization time. The ideas here are as Django.

Programmer must create a context per language, each context is the language translation itself. The context will be called "LANGUAGE.mo", and will be placed at normal gettext location. This can be overridden and per language support is necessary.

This is an example of gettext initialization. It must be done on users code:

	setenv("LANGUAGE","locale",1);
	setlocale(LC_ALL,"");
	bindtextdomain("locale", ".");
	bindtextdomain("es", ".");
	bindtextdomain("pl", ".");
	bindtextdomain("fr", ".");
	bindtextdomain("cn", ".");
	textdomain("C");

The .mo files should be copied at ./locale/LC_MESSAGES/[LANG].mo. The language is, by the moment, only set by the headers.

The original pot files can be obtained from generated .c files from otemplate, and normal source code using gettext.

If you code wants to use gettext directly, call it through dgettext(onion_request_language(req), "Your string").

Check the fileserver_otemplate example for an example of gettext use.

Debug

Gettext is very picky about where the translation files are. If you have problems on it, check it with:

strace -e trace=open ./myprog
Clone this wiki locally