Apache::LangPrefCookie - implant a language-preference given by cookie into httpd's representation of the Accept-Language HTTP-header.
<Location /> PerlInitHandler Apache::LangPrefCookie </Location> <Location /foo> # optionally set a custom cookie-name, default is "prefer-language" PerlSetVar LangPrefCookieName "foo-pref" </Location>
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.
Accept-Language
After that, it's up to httpd's mod_negotiation to choose the best deliverable representation.
I had demands to let users switch language 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 menu, maybe even misguiding the user in his selections. (See http://ppewww.ph.gla.ac.uk/~flavell/www/lang-neg.html, especially the section Language subset selections, for examples.)
There might also be scenarios where one wants to let users set a different preference just for certain realms within one site.
I dislike solutions involving virtual paths, because they normally lengthen and multiply URIs for a given resource.
prefer-language=x-klingon;expires=Saturday 31-Dec-05 24:00:00 GMT;path=/
Optionally, the default cookie name prefer-language can be overridden by setting the LangPrefCookieName variable:
prefer-language
LangPrefCookieName
PerlSetVar LangPrefCookieName "mypref"
mypref=x-klingon;expires=Saturday 31-Dec-05 24:00:00 GMT;path=/
mod_perl(3)
http://httpd.apache.org/docs/1.3/content-negotiation.html
http://httpd.apache.org/docs/1.3/mod/mod_negotiation.html
http://ppewww.ph.gla.ac.uk/~flavell/www/lang-neg.html
http://www.w3.org/TR/2004/WD-webarch-20040705/#avoid-uri-aliases
Apache2 has native means to the same end: http://httpd.apache.org/docs/2.2/content-negotiation.html#better
Hansjoerg Pehofer, <hansjoerg.pehofer@uibk.ac.at>
Copyright (C) 2005-2008 by Hansjoerg Pehofer
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.7 or, at your option, any later version of Perl 5 you may have available.
To install Apache::LangPrefCookie, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Apache::LangPrefCookie
CPAN shell
perl -MCPAN -e shell install Apache::LangPrefCookie
For more information on module installation, please visit the detailed CPAN module installation guide.