ChooseLanguage - Perl extension for accessing different versions of a website based on the user preferred language
use Apache::ChooseLanguage;
# Initialise the language chooser handler PerlTransHandler Apache::ChooseLanguage # Behaviour flags ( 0 = no, 1 = yes ) PerlSetVar ChooseBrowser 1 # Use the browser's language preference PerlSetVar ChooseFuzzy 1 # Use fuzzy language selection # ( treat en-US as en, fr-CA as fr ) PerlSetVar ChooseCookie 1 # Set a cookie to remember the user choice PerlSetVar ChooseNoCache 1 # Prevent the browser from caching "ChooseRoot" # Cookie settings PerlSetVar ChooseDomain "www.yourdomain.com" PerlSetVar ChooseExpire "+1M" # Root URL for this handler to react PerlSetVar ChooseRoot "/" # This URL has to be typed exactly for # the handler to react # What's the language selection page PerlSetVar ChoosePage "/index.html" # Define a perl hash, languages as keys and URLs as values PerlSetVar ChooseIndexes "en => /en/index.html,\ fr => /fr/bienvenue.html"
<H2>Please choose your prefered language</H2> <!-- If activated, the cookie sender will be activated by the following links --> <A HREF="/en/index.html">English</A> <A HREF="/fr/bienvenue.html>Francais</A>
This is an Apache translation handler. It will react to ChooseRoot URL requests, and it always return DECLINED to let the normal (or your own) handler find the actual file to return.
Depending on your config, this module will check the client's browser language preference and/or our cookie. The fuzzy flag (recommended for most setups) will allow you to treat all sub-languages or regional versions as a single general language.
Setting ChooseNoCache to a true value will prevent the broser from caching the pages sent by this handler. If unset, the client may see the previously selected page after choosing a different one.
If using cookies, you have to manually set your domain and expiration data. The language cookie will be sent when: 1- A page refered by the ChooseIndexes PerlVar is accessed 2- The ChooseCookie PerlVar is set 3- This cookie dosen't already exists and contain the correct value
Both index (language choice and language-specific) should be relative to your document root, since apache's translation handler will do it's job after this one.
Billy Nadeau <bill@sanac.net>
To install Apache::ChooseLanguage, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Apache::ChooseLanguage
CPAN shell
perl -MCPAN -e shell install Apache::ChooseLanguage
For more information on module installation, please visit the detailed CPAN module installation guide.