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

eZ debug

Timing: Jan 19 2025 05:16:18
Script start
Timing: Jan 19 2025 05:16:18
Module start 'content'
Timing: Jan 19 2025 05:16:20
Module end 'content'
Timing: Jan 19 2025 05:16:20
Script end

Main resources:

Total runtime1.3835 sec
Peak memory usage4,096.0000 KB
Database Queries78

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0056 589.0859180.8125
Module start 'content' 0.00561.3748 769.8984664.6563
Module end 'content' 1.38040.0030 1,434.554754.6953
Script end 1.3835  1,489.2500 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00260.1851140.0002
Check MTime0.00110.0784140.0001
Mysql Total
Database connection0.00060.045210.0006
Mysqli_queries1.291893.3722780.0166
Looping result0.00070.0530760.0000
Template Total1.356798.120.6783
Template load0.00180.132020.0009
Template processing1.354997.926920.6774
Template load and register function0.00010.006410.0001
states
state_id_array0.00100.071410.0010
state_identifier_array0.00170.122220.0008
Override
Cache load0.00170.1209410.0000
Sytem overhead
Fetch class attribute can translate value0.00040.029130.0001
Fetch class attribute name0.00120.0849120.0001
XML
Image XML parsing0.02782.007830.0093
class_abstraction
Instantiating content class attribute0.00000.0027180.0000
General
dbfile0.00140.1037310.0000
String conversion0.00000.000330.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
9content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
9content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
11content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
1content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
1content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 33
 Number of unique templates used: 7

Time used to render debug report: 0.0001 secs