[dancer-users] playing with path_info before matching routes
WK
wanradt at gmail.com
Tue Dec 3 11:26:50 GMT 2013
Hi!
I try to build multi-language site, where i could include laguages
code into path, like this:
www.exemple.com/en/some_page
www.exemple.com/de/some_page
www.exemple.com/fr/some_page
www.exemple.com/fi/some_page
www.exemple.com/ru/some_page
etc
I want to handle part of the path after language abbreviation in one
route for every language and only render page with lang-specific
template.
I thought that best place to get language part from path is in before hook but :
* it is fired just after checking routes
* after modifiyng path_info before hook is fired again
I wrote simple code like this:
use Dancer ':syntax';
our $VERSION = '0.1';
my $lang;
hook 'before' => sub {
my $path = request->path_info();
if ( $path =~ s| ^/ (?<lang> [[:ascii:]]{2} ) / |/|x ) {
$lang = $+{lang};
}
request->path_info( $path );
};
get '/some_page' => sub {
template ("$lang/some_page");
};
And basically it works fine.
Still i'd like to get lang part out before trying match routes. Or is
there at least a way that before hook is not fired again?
And maybe there is even better way to achieve my goal?
--
Wbr,
Kõike hääd,
Gunnar
More information about the dancer-users
mailing list