janggu Posted February 12, 2008 Share Posted February 12, 2008 Hi there, I was wondering if anyone could help me with creating a script for switching two languages. I am thinking of using a folder structure or an extension of file names in URL. For example, this script will look for the different extension or the folder structure as follow. about-e.php | about-f.php or en/about.php | fr/about.php I am open for any other suggestions and thank you! Quote Link to comment https://forums.phpfreaks.com/topic/90681-how-to-create-a-script-for-switching-two-languages/ Share on other sites More sharing options...
Cognito Posted February 12, 2008 Share Posted February 12, 2008 have a look into php templating. that way you will only have 1page but the option of 2values eng of fr heres an example: index.php <?php $lang = ""; include("variables.php"); if $lang = "EN"; { include("templateEN.html"); } else include("templateFR.html"); } ?> variables.php <?php $TPLEN["title"] = "This is Magic!"; $TPLFR["title"] = "This is Magic!"; $TPLEN["HEADLINE"] = "Hello"; // This is ENGLISH $TPLFR["HEADLINE"] = "Bonjour"; // This is FRENCH ?> templateEN.html <html> <head><title><?=$TPLEN["title"]?></title></head> <body> <H1><?=$TPLEN["HEADLINE"]?></H1> </body> </html> templateFR.html <html> <head><title><?=$TPLFR["title"]?></title></head> <body> <H1><?=$TPLFR["HEADLINE"]?></H1> </body> </html> You can then goto - http://www.yourdomain.com/index.php?lang=EN Quote Link to comment https://forums.phpfreaks.com/topic/90681-how-to-create-a-script-for-switching-two-languages/#findComment-464824 Share on other sites More sharing options...
GameYin Posted February 12, 2008 Share Posted February 12, 2008 Brilliant answer. Applauds. Quote Link to comment https://forums.phpfreaks.com/topic/90681-how-to-create-a-script-for-switching-two-languages/#findComment-464843 Share on other sites More sharing options...
Cognito Posted February 12, 2008 Share Posted February 12, 2008 Execuse any messy code im still a newb and only been messing around with php for about 1yr I'm sure half the way I code things can be done alot easier. Quote Link to comment https://forums.phpfreaks.com/topic/90681-how-to-create-a-script-for-switching-two-languages/#findComment-464849 Share on other sites More sharing options...
blackcell Posted February 12, 2008 Share Posted February 12, 2008 IMO, easy isn't a matter of finding the way that the majority considers easy. It is how you like it and how it will make it easy to maintain the code. Quote Link to comment https://forums.phpfreaks.com/topic/90681-how-to-create-a-script-for-switching-two-languages/#findComment-464852 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.