bullchina Posted August 20, 2006 Share Posted August 20, 2006 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 https://forums.phpfreaks.com/topic/18093-language-choosing-on-a-multilingual-website/ Share on other sites More sharing options...
hitman6003 Posted August 20, 2006 Share Posted August 20, 2006 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. Link to comment https://forums.phpfreaks.com/topic/18093-language-choosing-on-a-multilingual-website/#findComment-77543 Share on other sites More sharing options...
bullchina Posted August 22, 2006 Author Share Posted August 22, 2006 I tried out this tutorial:http://www.cwhnetworks.com/forums/index.php?showtopic=3004and 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 englishif (isset($_COOKIE['language']) || $cookieflag) { $lang = $_COOKIE['language']; } else { $lang = "en"; }$cookieflag=false;//now call all the pages according to the language, default case is englishswitch ($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 https://forums.phpfreaks.com/topic/18093-language-choosing-on-a-multilingual-website/#findComment-78375 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.