Auto-detect language from browser accept language

Author Message

Sébastien Hordeaux

Wednesday 22 August 2007 6:40:18 am

Hello,

How can eZ publish display localized information based on user's AcceptLanguage settings in the browser?

If it is not possible, is there a way to redirect user to a different site access based on this?

Thanks you by advance for any hint :)

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.

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

eZ debug

Timing: Jan 18 2025 18:16:45
Script start
Timing: Jan 18 2025 18:16:45
Module start 'layout'
Timing: Jan 18 2025 18:16:45
Module start 'content'
Timing: Jan 18 2025 18:16:47
Module end 'content'
Timing: Jan 18 2025 18:16:47
Script end

Main resources:

Total runtime1.5113 sec
Peak memory usage4,096.0000 KB
Database Queries59

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0060 588.0625152.6406
Module start 'layout' 0.00600.0031 740.703139.4766
Module start 'content' 0.00911.5007 780.1797532.9141
Module end 'content' 1.50980.0015 1,313.093812.1250
Script end 1.5113  1,325.2188 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00350.2341160.0002
Check MTime0.00130.0848160.0001
Mysql Total
Database connection0.00080.052310.0008
Mysqli_queries1.455096.2751590.0247
Looping result0.00060.0384570.0000
Template Total1.465897.020.7329
Template load0.00220.146120.0011
Template processing1.463696.842720.7318
Template load and register function0.00010.009710.0001
states
state_id_array0.00130.087710.0013
state_identifier_array0.00350.231120.0017
Override
Cache load0.00190.1237250.0001
Sytem overhead
Fetch class attribute can translate value0.00070.043430.0002
Fetch class attribute name0.00140.090830.0005
XML
Image XML parsing0.00030.023130.0001
class_abstraction
Instantiating content class attribute0.00000.000630.0000
General
dbfile0.00060.0428100.0001
String conversion0.00000.000440.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
3content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
6content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
3content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 15
 Number of unique templates used: 6

Time used to render debug report: 0.0001 secs