View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
Hansjörg Pehofer > Apache-LangPrefCookie-1.03 > Apache::LangPrefCookie



Annotate this POD

View/Report Bugs
Module Version: 1.03   Source  


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


  <Location />
     PerlInitHandler  Apache::LangPrefCookie

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


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.


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, 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:

PerlSetVar LangPrefCookieName "mypref"

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



Apache2 has native means to the same end:


Hansjoerg Pehofer, <>


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.

syntax highlighting: