Saturday, January 23, 2010

I18N for HTML::Mason

in the folder where I keep the virtual host data:

locale/ro/LC_MESSAGES/ is where the messages.mo file goes


drwxrwxr-x 1 emilper www-data 4096 2010-01-22 04:53 apache_conf
drwxrwxr-x 1 emilper www-data 4096 2010-01-22 05:48 htdocs
drwxrwxr-x 1 emilper www-data 4096 2008-07-16 18:37 lib
drwxr-xr-x 1 emilper emilper 4096 2010-01-22 02:33 locale
drwxrwxr-x 1 emilper www-data 4096 2008-07-19 02:13 log
drwxrwxr-x 1 emilper www-data 4096 2010-01-22 04:54 mason


in my Apache VirtualHost config:

PerlSetVar GettextLocalesDir /home/www/mysite/locale/
PerlSetVar GettextDomain messages


in my Mason request class (MasonRequestClass set in apache conf) :


$self->{'i18n'} = Locale::gettext->domain($self->apache_req->dir_config('GettextDomain'));
$self->{'i18n'}->dir($self->apache_req->dir_config('GettextLocalesDir'));


and


sub _t {
my ($self, $string) = @_;
return $self->{'i18n'}->get($string);
}


in my code:


$page_title = $m->_t("String to translate");


As of now, I have difficulties persuading xgettext to extract the strings from autohandlers, .mas files, and .html files. Until I write my own extractor, I add the strings by hand to a "messages.po" file, which I compile to a "messages.mo" file that can be used by gettext with:


msgfmt messages.po

No comments:

Post a Comment