Mutley Posted March 1, 2007 Share Posted March 1, 2007 I've got 3 languages for products on a site in a database (English, German, French). English is the default language. I was considering using variables so when they click say the French flag, it pulls the french language out of the database for that product but this started to get messy. Should I use Cookies or Sessions, how would you do it? Quote Link to comment https://forums.phpfreaks.com/topic/40710-best-way-to-change-language/ Share on other sites More sharing options...
willpower Posted March 1, 2007 Share Posted March 1, 2007 Id use sessions lets say that you have identical data in 3 tables...1 table for each language. tables english, french, german I'd set the Session['lang'] to default to "english" $lang=$_SESSION['lang'] then i'd "SELECT products from '$lang' WHERE...." then if someone clicks a button (flag) reset the $Session to the relevant language. That could be one solution. it kinda depends on what table format you have. Quote Link to comment https://forums.phpfreaks.com/topic/40710-best-way-to-change-language/#findComment-197064 Share on other sites More sharing options...
Gruzin Posted March 1, 2007 Share Posted March 1, 2007 Id use sessions lets say that you have identical data in 3 tables...1 table for each language. tables english, french, german I'd set the Session['lang'] to default to "english" $lang=$_SESSION['lang'] then i'd "SELECT products from '$lang' WHERE...." then if someone clicks a button (flag) reset the $Session to the relevant language. That could be one solution. it kinda depends on what table format you have. ummm..... In that case if one of the table rows will be deleted, everything will go wrong (ID's won't match). Quote Link to comment https://forums.phpfreaks.com/topic/40710-best-way-to-change-language/#findComment-197071 Share on other sites More sharing options...
willpower Posted March 1, 2007 Share Posted March 1, 2007 now...with the greatest of respect....we cant help with that sort of response. You have given no indication of a) how your tables are set up...and b) how you come to your next problems about deletion. Lets start again. Try and be more precise in the environment that you are working and the specific issue(s) that you have. Everything will go wrong is a little but vague...lol Quote Link to comment https://forums.phpfreaks.com/topic/40710-best-way-to-change-language/#findComment-197072 Share on other sites More sharing options...
Mutley Posted March 1, 2007 Author Share Posted March 1, 2007 Sorry, bit of a brain fart. The database has a table called "products" with fields such as: id | number | name | description | descriptiong | descriptionf (descriptiong = german, descriptionf = french ) The language isn't needed to be change else where but, if I wanted a certain page to change as well, that would be helpful, I imagine the session would be easy like variables where it would change what is called? Quote Link to comment https://forums.phpfreaks.com/topic/40710-best-way-to-change-language/#findComment-197077 Share on other sites More sharing options...
dsaba Posted March 1, 2007 Share Posted March 1, 2007 i'm doing something similar in my website, i also have seperate tables for each language i'm going to use cookies however, because I want to encourage the user to be comfortable in his own language, so when he revisits the page it will still be in his language, that way he won't have to continue to change the language to his language every time he access the page Quote Link to comment https://forums.phpfreaks.com/topic/40710-best-way-to-change-language/#findComment-197081 Share on other sites More sharing options...
Gruzin Posted March 1, 2007 Share Posted March 1, 2007 OK, I'll explain it.... say we have 3 tables, with different languages and the ID (autoincreament value) fileds are the same. example: home - (ID=1, lang=eng) home - (ID=1, lang=ger) and now, if I want to delete English "home" , ID will change and will not be equivalent to German "home", is that right? so how can I determine on wich page I am? Kindest regards Quote Link to comment https://forums.phpfreaks.com/topic/40710-best-way-to-change-language/#findComment-197088 Share on other sites More sharing options...
willpower Posted March 1, 2007 Share Posted March 1, 2007 so you currently echo the results from ['description']? just add a conditional. if ($_Session['lang']=="en") { echo //english description;} if ($_Session['lang']=="fr") { echo //french description;} if ($_Session['lang']=="gr") { echo //german description;} PS last post just came up. Yes if you did that ID's would be a problem....but y would you delete 1 descrition and not all. Anyway youur table is fine. Quote Link to comment https://forums.phpfreaks.com/topic/40710-best-way-to-change-language/#findComment-197089 Share on other sites More sharing options...
Mutley Posted March 1, 2007 Author Share Posted March 1, 2007 I'm not doing seperate tables though, I don't see the point it means duplicating the product information like price and name ? Quote Link to comment https://forums.phpfreaks.com/topic/40710-best-way-to-change-language/#findComment-197091 Share on other sites More sharing options...
mbtaylor Posted March 1, 2007 Share Posted March 1, 2007 I have recently written a multi lingual CMS system. The approach I used was to COMPLETELY SEPARATE the content and other structure. You would have one table containing say your productID, price, etc and a linking languageID which would link to a product_content table containing all the translations and text content for your products. The separate languages would be separated by languageID and products linked to the product_content table by productID. They would be linked using a JOIN SQL statement. So with this approach, you are not needing a separate table for each language, and are not duplicating anything in nice relational design. It works in a similar way for pages and page content. Pages are definated in 1 table, and link to the language in a page_content table via pageID and languageID. Does that make sense? Its basically using a 1:Many relationship for the product:text. You then also need to think about labels, things like "Submit" etc on buttons. For that I had a labels table, which defined labels and the language text for each. You can then lookup the label text based on a keyword using an sql query. Quote Link to comment https://forums.phpfreaks.com/topic/40710-best-way-to-change-language/#findComment-197127 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.