Jump to content

Archived

This topic is now archived and is closed to further replies.

bullchina

language choosing on a multilingual website

Recommended Posts

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:

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

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
I tried out this tutorial:

http://www.cwhnetworks.com/forums/index.php?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:

[code]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;
}
[/code]

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

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.