Apache-LangPrefCookie
view release on metacpan or search on metacpan
DESCRIPTION
This module looks for a cookie providing a language-code as its value.
This preference is then implanted into httpd's representation of the
Accept-Language header, just as if the client had asked for it as #1
choice. The original preferences are still present, albeit with lowered
q-values. The cookie's name is configurable, as described in the
examples. Setting/modifying/deleting such a cookie is to be handled
separately; Apache::LangPrefCookie just consumes it.
After that, it's up to httpd's mod_negotiation to choose the best
deliverable representation.
CHANGES
0.05 - first released Version.
1.00 - fix typo in regexp
- cleanup Makefile.PL, Perl >= 5.6.0 required.
- fix README, docs clarification
- more tests
lib/Apache/LangPrefCookie.pm view on Meta::CPAN
# RFC 2616 states: "If no Accept-Language header is present in
# the request, the server SHOULD assume that all languages are
# equally acceptable." Since we are going to fool httpd into
# thinking there is one, we respect the original demand by
# inserting '*'.
@ua_lang_prefs = q/*/;
}
# Now: unless the cookie wants a language that would be the
# best matching anyway, rebuild the list of language-ranges
unless ( $cookie_pref_lang eq $ua_lang_prefs[0] ) {
my ( $qvalue, $language_ranges ) = ( 1, '' );
map {
if (m/^(?:\w{1,8}(?:-\w{1,8})*|\*)$/)
{
$language_ranges .= "$_;q=$qvalue, ";
$qvalue *= .9;
}
} ( $cookie_pref_lang, @ua_lang_prefs );
$language_ranges =~ s/,\s*$//;
lib/Apache/LangPrefCookie.pm view on Meta::CPAN
=head1 DESCRIPTION
This module looks for a cookie providing a language-code as its value.
This preference is then implanted into httpd's representation of the
C<Accept-Language> header, just as if the client had asked for it as #1
choice. The original preferences are still present, albeit with lowered
q-values. The cookie's name is configurable, as described in the
examples. Setting/modifying/deleting such a cookie is to be handled
separately; F<Apache::LangPrefCookie> just consumes it.
After that, it's up to httpd's mod_negotiation to choose the best
deliverable representation.
=head2 WHY?
I had demands to let users switch language I<once> for a given site.
Additionally, the availability and languages of translations offered
vary over places within this site.
In theory a user-agent should help its users to set a reasonable choice
of languages. In practice, the dialog is hidden in the 3rd level of some
( run in 0.294 second using v1.01-cache-2.11-cpan-501359838a1 )