If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > PHP > Cookies and Languages (dual language website)

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-06-03, 12:45
crighton crighton is offline
Registered User
 
Join Date: Feb 2002
Posts: 12
Cookies and Languages (dual language website)

Hi,

I'm getting a little paranoid with a dual language website I built.

What I want to happen:

If a user arrives with an EN browser or a browser with EN as the primary language setting then the language of the site is in English.

If any other language then the default language of the site is ES (Spanish).

In both cases a cookie is set to store the data.

In both cases the user has the option to change the language (and the cookie be updated).

I thought I had this working, but have noted erratic behaviour with languages in the last few days (language not being set, changing from page to page).

My first code was as follows:

//SET LANGUAGE
if(isset($setlang)) {
$lang = $setlang;
setcookie ("langset", "$setlang");
} else {
if(isset($langset)) {
$lang = $langset;
} else {
if (!isset($lang)) $lang=substr($HTTP_ACCEPT_LANGUAGE,0,2);
setcookie ("langset", "$lang");
}
}

One problem I quickly realsed with this version was that it did not take account of users with browsers that were *not* ES or EN. So a modified version was produced to set the language to ES where the ACCEPT_LANGUAGE request was neither ES or EN:

//SET LANGUAGE
if(isset($setlang)) {

// IF LANG IS NOT ES OR EN SET TO ES
// ADDED 03032003 TO FIX LANG ERRORS
if (($setlang != "en") && ($setlang != "es")) {
$setlang = "es";
}

$lang = $setlang;
setcookie ("langset", "$setlang");
} else {
if(isset($langset)) {
$lang = $langset;
} else {
if (!isset($lang)) $lang=substr($HTTP_ACCEPT_LANGUAGE,0,2);
// IF LANG IS NOT ES OR EN SET TO ES
// ADDED 03032003 TO FIX LANG ERRORS
if (($lang != "en") && ($lang != "es")) {
$lang = "es";
}

setcookie ("langset", "$lang");
}
}


Now, after all is said and done I'm a little confused as the newer script still seems to give erratic behaviour and I've been looking at it too long to see clearly.

Can anyone offer advice or suggest a better way to do this?

The site is question (now back to version one of the script) is at http://www.circulodelarte.com/

Many thanks,

Gary Crighton
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On