Jump to content

language choosing on a multilingual website


bullchina

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.