janggu Posted January 30, 2008 Share Posted January 30, 2008 Hi there, I need to create a language swticher script between English and French content. I am kind of stuck how I can approach this. Is using PHP cookie the best way - I need to triger the switcher by clicking English/French link? Has anyone done this type of work? Thanks a lot for your help in advance! Link to comment https://forums.phpfreaks.com/topic/88625-a-language-switcher-between-english-and-french/ Share on other sites More sharing options...
cooldude832 Posted January 30, 2008 Share Posted January 30, 2008 Store it in sessions Link to comment https://forums.phpfreaks.com/topic/88625-a-language-switcher-between-english-and-french/#findComment-453805 Share on other sites More sharing options...
atlanta Posted January 30, 2008 Share Posted January 30, 2008 Yea sessions would be the best way.... and if the site is member based have it where members can set the variable in the database and have the page check to see what language they want... Link to comment https://forums.phpfreaks.com/topic/88625-a-language-switcher-between-english-and-french/#findComment-453806 Share on other sites More sharing options...
janggu Posted January 30, 2008 Author Share Posted January 30, 2008 Thank you! Any examples you guys can share... Link to comment https://forums.phpfreaks.com/topic/88625-a-language-switcher-between-english-and-french/#findComment-453811 Share on other sites More sharing options...
cooldude832 Posted January 30, 2008 Share Posted January 30, 2008 the way you initally posted suggested you had a way to translate between langauges so that is what you need to tell us is how you are or how you plan to translate. Link to comment https://forums.phpfreaks.com/topic/88625-a-language-switcher-between-english-and-french/#findComment-453813 Share on other sites More sharing options...
janggu Posted January 31, 2008 Author Share Posted January 31, 2008 This is what have so far. Basically, I have two links of English/French with a query string called "lang". When one of these links is clicked, my script is supposed to create or update the session variables. Howerver, this is not working... PLEASE HELP!!! <? session_start(); $lg = $_GET['lang']; if (!isset($_SESSION["lang"])) { $_SESSION['lang'] = "en"; } else { if ($_SESSION["lang"] == "en" && $lg == "fr") { session_destroy(); $_SESSION["lang"] = "fr"; } if ($_SESSION["lang"] == "fr" && $lg == "en") { session_destroy(); $_SESSION["lang"] = "en"; } } ?> Link to comment https://forums.phpfreaks.com/topic/88625-a-language-switcher-between-english-and-french/#findComment-454062 Share on other sites More sharing options...
cooldude832 Posted January 31, 2008 Share Posted January 31, 2008 <?php session_start(); $langs = array("ENG","FRA"): if(in_array($_GET['lang'],$langs)){ $_SESSION['Lang'] = $_GET['lang']; } if(in_array($_SESSION['Lang'],$langs)){ $_SESSION['Lang'] = $langs[0]; } ?> That will do it it will verify a get version is legit if the session isn't set or is invalid it resets it to the default first value. You can add more languages very easily with this. Make sure all this appears pre any headers being sent so the page is reflective of the new header data. Link to comment https://forums.phpfreaks.com/topic/88625-a-language-switcher-between-english-and-french/#findComment-454069 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.