[Catalyst] Multilanguage application

Renaud Drousies renaud at linuxaddicts.com
Thu Aug 10 14:44:58 CEST 2006


Hello,

I am trying to figure out what would be the best way to have a
multilanguage support in a catalyst application.

I thought using a url-based method might be better since this site could
be visited by people that do not accept cookies, or do not visit it from
their home computer (and then could not have the Accept-Language header
set correctly).

This is what I am doing for the moment: (taken from MyApp.pm)

-------

__PACKAGE__->config->{i18n}->{default_language} = 'fr';
__PACKAGE__->config->{i18n}->{available_languages} = { fr => 1, en => 1 };

sub prepare_path {

    my ($c) = shift;

    $c->NEXT::prepare_path(@_);

    my @path = split m#/#, $c->req->path;

    my $language = $c->config->{i18n}->{default_language};

    if ($path[0] && $c->config->{i18n}->{available_languages}->{$path[0]}) {
    # Check if the root dir is one of our available lang.

        # Remove the language from the path
        $language = shift @path;
        $c->req->path(join('/', @path) || '/');

    } elsif (!$path[0]) {

        $c->response->redirect('/' . $c->config->{i18n}->{default_language})

    }

    $c->languages([$language]);

    # Some values you want to use in your View

    $c->stash(language => $language, root => "/$language", path =>
$c->req->path);

}

--------

That works quite nice, the only problem is that I must take care of having
ALL my links in the template starting with href="[% root %]/foo/bar".

I was then wondering if that was the good way (and the one with less
effort) to handle multilanguage sites with catalyst, without relying on
cookies and accept-language headers. Any thoughts? :)

Thanks,
Renaud




More information about the Catalyst mailing list