Forums / Developer / Storing the last language in the browser

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