[Catalyst] Re: Catalyst::Plugin::PageCache with I18N
Fayland Lam
fayland at gmail.com
Mon May 7 13:41:58 GMT 2007
Fayland Lam wrote:
> hey, it seems that Catalyst::Plugin::PageCache can NOT get along well
> with the I18N.
>
> to let the PageCache get along with languages, I patched the PageCache
> for a bit.
>
> sub _get_page_cache_key {
> my ($c) = @_;
> my $key = $c->next::method(@_);
> my $langs = $c->languages();
> $key .= '#' . join( '-', @$langs ) if ($langs);
> return $key;
> }
>
mm, fixes.
sub _get_page_cache_key {
my ($c) = @_;
my $key = $c->next::method(@_);
my $lang = $c->req->cookie('pref_lang')->value if
($c->req->cookie('pref_lang'));
$lang ||= $c->user->lang if ($c->user_exists);
$lang ||= $c->config->{default_pref_lang};
if (my $set_lang = $c->req->param('set_lang')) {
$set_lang =~ s/\W+//isg;
if (length($set_lang) == 2) {
$lang = $set_lang;
}
}
$key .= '#' . $lang if ($lang);
return $key;
}
> I have something like as follows in Root.pm sub auto
>
> # internationalization
> $c->stash->{lang} = $c->req->cookie('pref_lang')->value if
> ($c->req->cookie('pref_lang'));
> $c->stash->{lang} ||= $c->user->lang if ($c->user_exists);
> $c->stash->{lang} ||= $c->config->{default_pref_lang};
> if (my $lang = $c->req->param('set_lang')) {
> $lang =~ s/\W+//isg;
> if (length($lang) == 2) {
> $c->res->cookies->{pref_lang} = { value => $lang };
> $c->stash->{lang} = $lang;
> }
> }
> $c->languages( [ $c->stash->{lang} ] );
>
> but it seems that sub dispatch { in PageCache.pm is called before
> Root.pm sub auto.
> so the $key = $c->_get_page_cache_key; in sub dispatch is different from
> the $key in sub finalize.
>
> any hints for suggestion are welcome. Thanks a lot.
>
--
Fayland Lam // http://www.fayland.org/
More information about the Catalyst
mailing list