Storing the last language in the browser

Author Message

Tony Wood

Tuesday 23 November 2004 7:10:41 am

Hi,

Has anyone delevoped a mechanism in eZ to store the last viewed language on a site?

The senerio for use would be a anonymous spanish visitors sets spanish as his language and whenver he comes back to the site then the language would default to spanish.

Any thoughts anyone?

tony

Tony Wood : twitter.com/tonywood
Vision with Technology
Experts in eZ Publish consulting & development

Power to the Editor!

Free eZ Training : http://www.VisionWT.com/training
eZ Future Podcast : http://www.VisionWT.com/eZ-Future

Łukasz Serwatka

Tuesday 23 November 2004 7:21:32 am

Hi,

You can use JavaScript with cookies
Cookie: Name1=value1; Name2=value2;
Check the cookie and redirct user to right language

function createCookie(name,value,days)
{
        if (days)
        {
                var date = new Date();
                date.setTime(date.getTime()+(days*24*60*60*1000));
                var expires = "; expires="+date.toGMTString();
        }
        else var expires = "";
        document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name)
{
        var nameEQ = name + "=";
        var ca = document.cookie.split(';');
        for(var i=0;i < ca.length;i++)
        {
                var c = ca[i];
                while (c.charAt(0)==' ') c = c.substring(1,c.length);
                if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
        }
        return null;
}

function eraseCookie(name)
{
        createCookie(name,"",-1);
}

I found this in network ...

Personal website -> http://serwatka.net
Blog (about eZ Publish) -> http://serwatka.net/blog

Tony Wood

Tuesday 23 November 2004 7:34:21 am

Thanks Luke. Wouldn't it be nice to have this in eZ by default? then we would not have to do a js check on very page load...

Tony Wood : twitter.com/tonywood
Vision with Technology
Experts in eZ Publish consulting & development

Power to the Editor!

Free eZ Training : http://www.VisionWT.com/training
eZ Future Podcast : http://www.VisionWT.com/eZ-Future

Kåre Køhler Høvik

Tuesday 23 November 2004 8:02:18 am

Try using the build in preferences : http://ez.no/ez_publish/documentation/incoming/user_preferences

Kåre Høvik

Tony Wood

Tuesday 23 November 2004 8:13:17 am

Thanks Kåre

I would love to but these users are anonymous :(

Tony Wood : twitter.com/tonywood
Vision with Technology
Experts in eZ Publish consulting & development

Power to the Editor!

Free eZ Training : http://www.VisionWT.com/training
eZ Future Podcast : http://www.VisionWT.com/eZ-Future

Kåre Køhler Høvik

Tuesday 23 November 2004 8:22:01 am

From the documentation of the functionality : <i>If the user is not logged in the preferences is stored in sesssion.</i>

So it should work for anonymous users.

Kåre Høvik

Tony Wood

Tuesday 23 November 2004 8:35:45 am

That is a really good point :) Thanks

Can you give me a hint as to the code location and what sort of code would you use to inact the language change.

Tony Wood : twitter.com/tonywood
Vision with Technology
Experts in eZ Publish consulting & development

Power to the Editor!

Free eZ Training : http://www.VisionWT.com/training
eZ Future Podcast : http://www.VisionWT.com/eZ-Future

Kåre Køhler Høvik

Tuesday 23 November 2004 10:26:42 am

How do you seperate between the language versions ?

Kåre Høvik

Tony Wood

Tuesday 23 November 2004 10:44:07 am

Currently we use URL so /en english /fr French etc.

Tony Wood : twitter.com/tonywood
Vision with Technology
Experts in eZ Publish consulting & development

Power to the Editor!

Free eZ Training : http://www.VisionWT.com/training
eZ Future Podcast : http://www.VisionWT.com/eZ-Future

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 19 2025 06:28:20
Script start
Timing: Jan 19 2025 06:28:20
Module start 'layout'
Timing: Jan 19 2025 06:28:20
Module start 'content'
Timing: Jan 19 2025 06:28:20
Module end 'content'
Timing: Jan 19 2025 06:28:20
Script end

Main resources:

Total runtime0.0153 sec
Peak memory usage2,048.0000 KB
Database Queries3

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0059 589.2891152.6406
Module start 'layout' 0.00590.0030 741.929739.4766
Module start 'content' 0.00890.0045 781.4063101.4922
Module end 'content' 0.01340.0019 882.898446.3047
Script end 0.0152  929.2031 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.002516.3205140.0002
Check MTime0.00117.3142140.0001
Mysql Total
Database connection0.00085.520710.0008
Mysqli_queries0.003019.918330.0010
Looping result0.00000.090510.0000
Template Total0.001510.110.0015
Template load0.00074.847010.0007
Template processing0.00085.187010.0008
Override
Cache load0.00053.323410.0005
General
dbfile0.00031.660980.0000
String conversion0.00000.062440.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0001 secs