The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Apache::LangPrefCookie - implant a language-preference given by cookie into httpd's representation of the Accept-Language HTTP-header.

SYNOPSIS

  <Location />
     PerlInitHandler  Apache::LangPrefCookie
  </Location>

  <Location /foo>
     # optionally set a custom cookie-name, default is "prefer-language"
     PerlSetVar LangPrefCookieName "foo-pref"
  </Location>

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.

WHY?

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.

EXAMPLE COOKIE

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:

PerlSetVar LangPrefCookieName "mypref"

mypref=x-klingon;expires=Saturday 31-Dec-05 24:00:00 GMT;path=/

SEE ALSO

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

AUTHOR

Hansjoerg Pehofer, <hansjoerg.pehofer@uibk.ac.at>

COPYRIGHT AND LICENSE

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.