1 package MojoX
::FilterChain
::DetectLang
;
6 use base
'MojoX::FilterChain::Base';
8 use MojoX
::FilterChain
::Constants
;
10 __PACKAGE__
->attr('languages', default => sub {[]});
11 __PACKAGE__
->attr('stash_key', default => 'language');
17 if (my $path = $c->tx->req->url->path) {
18 my $part = $path->parts->[ 0 ];
20 if ( $part && grep { $part eq $_ } @
{ $self->languages } ) {
22 shift @
{ $path->parts };
24 $c->stash->{ $self->stash_key } = $part;
36 MojoX::FilterChain::DetectLang - Detect client language filter
41 ->add(MojoX::FilterChain::DetectLang->new(languages => [qw/ en de /]));
47 $c->stash->{language}; # undef
51 $c->stash->{language}; # en
55 $c->stash->{language}; # de
59 L<MojoX::FilterChain::DetectLang> is a filter for detecting client language
63 L<MojoX::FilterChain::DetectLang> inherits all methods from
64 L<MojoX::FilterChain::Base> and implements the following ones.
68 Languages that your website can handle.
72 Stash variable name where language will be stored.