Auto-detect language from browser accept language

Auto-detect language from browser accept language

Wednesday 22 August 2007 6:40:18 am - 2 replies

Author Message

Lazaro Ferreira

Wednesday 22 August 2007 9:36:24 am

Hi Sebastien

You can create a template operator to detect the HTTP_ACCEPT_LANGUAGE, sent by the browser, the following php code get the information :

<?php
echo $_SERVER['HTTP_ACCEPT_LANGUAGE'];
?>

 

Then you can program your pagelayout.tpl to redirect based on the operator output, you can create your own redirect operator, or use the one at the contributions

Regards

Lazaro
http://www.mzbusiness.com

Andrey Astakhov

Wednesday 22 August 2007 12:14:21 pm

Hello, Sébastien

I implemented it so:

1. Update your httpd.conf (or .htaccess)

        RewriteCond %{HTTP:Accept-Language} ^ru.* [NC]
        RewriteRule (.*) - [E=SITEACCESS:siteaccess_ru]

        RewriteCond %{HTTP:Accept-Language} ^en.* [NC]
        RewriteRule (.*) - [E=SITEACCESS:siteaccess_en]

"ru" and "en" are languages of my site.
It adds appropriate server variable depending of user Accept-Language.

2. Update your settings/override/site.ini.append

MatchOrder=servervar;host
ServerVariableName=SITEACCESS
HostMatchMapItems[]=www.yoursite.com;siteaccess_default

Now users with Accept-Language = ru* see siteaccess_ru siteaccess, users with Accept-Language = en* see siteaccess_en siteaccess, any other users see siteaccess_default.

You could also change rewriterules to minimize set of rules and with site.ini settings to create other siteaccess matching.

You must be logged in to post messages in this topic!

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.