Jump to content


Photo

language choosing on a multilingual website


  • Please log in to reply
2 replies to this topic

#1 bullchina

bullchina
  • Members
  • PipPip
  • Member
  • 19 posts
  • LocationHouston

Posted 20 August 2006 - 12:32 PM

I'm just starting a website that has to be in three languages, and  i decided to try out smarty templates. I have read some tutorials on how to do language switching, and it all seems to make sense, except the part about ensuring that if a user is on a certain page, and they switch languages, they will go back to that same page...

If I am passing a ?lang=en variable in the get string to determine the language, but I am also passing get string variables to determine what content goes into the page, how do I make sure that lang=en and say, pageid=587 both get passed, for example.  do i have to do something like:

<a href="<? echo $_SERVER['DOCUMENT_ROOT']."?lang=en"; ?>" >switch to english</a>

in the above example, what if the server[doc_root] variable already has lang=en in the string? then each time it would be adding "lang=en" to the string, and that seems wrong...

i think the examples i've seen are just too simple to explain that, or maybe i'm still a little confused.

the page is for an architect, and i'd like to store all the projects in three xml files, one for english, one for spanish, and one for catalan, and then use php to read the xml, sort it, display it however the user wants it displayed (by location, by type, by date, etc...), but i don't want to get too ahead of myself before I really understand how language switching works. thanks for the help,
dave

#2 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 20 August 2006 - 01:25 PM

I would recommend that once the user has selected their language via a "Switch to Language" link, set either a cookie or session variable that keeps track of that setting for them.  Then you won't have to attach a "lang=en" onto every url.

#3 bullchina

bullchina
  • Members
  • PipPip
  • Member
  • 19 posts
  • LocationHouston

Posted 22 August 2006 - 12:52 AM

I tried out this tutorial:

http://www.cwhnetwor...?showtopic=3004

and i used all the code they provided, with a few modifcations, and it doesn't seem to work properly.

it seems that when i click a language button, it doesn't change the language until the page is refreshed or reloaded one more time. my code looks like this:

if (isset($_GET['lang'])) {
    $lang = $_GET['lang'];
    setcookie("language", "$lang", time()+36000);
	}

//check cookie, if not set, default language is english
if (isset($_COOKIE['language']) || $cookieflag) {
    $lang = $_COOKIE['language'];
    } 
else {
    $lang = "en";
    }

$cookieflag=false;

//now call all the pages according to the language, default case is english
switch ($lang) {
    case "en":	require_once('includes/en.php');
    	break;
    case "es":	require_once('includes/es.php');
    	break;
    case "ca":  require_once('includes/ca.php');
    	break;
	default:	require_once('includes/en.php');
		break;
}

is the problem that the cookie is not set that quickly that you can just immediately check if it is set, right after setting it? i have no clue, thanks for the help...

the link to the site is here, but it's not done yet: http://dave.showviz.net/bet2




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users