barney0o0 Posted February 26, 2008 Share Posted February 26, 2008 Hi Folks. Ive looked around the forums, but im still unsure about the correct methods for constructing a multilanguage site. The site will be databse driven, and the database table (in this exmaple content) would be; CONTENT id | Pageid | Language | Title | maintext 1 | 1 | En | English title | English text 2 | 1 | It | Italian title | Italian text 3 Initially, it would be just 2 languages, however, thinking laterally, this may increase in the near future. Now, questions... What would be the best way to set the default language of the site (italian) ...something like... <?php SESSION_START(); if (isset($_GET['lang'])) { $lang=$_GET['lang']; $_SESSION['lang'] = $lang; } if(!isset($_SESSION['lang'])){ $lang="it"; }else{ $lang = $_SESSION['lang']; } ?> For the language buttons, is it good practice to use; <a href="?lang=it">Italiano</a> to set the SESSION? Many thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/93074-multi-language-site-newbie/ Share on other sites More sharing options...
uniflare Posted February 26, 2008 Share Posted February 26, 2008 personally i would store all content into a database table, then have multiple table names: content_en content_fr content_it etc etc. Where a page required content you would add a suffix to all your db queries, eg: $suffix = mysql_escape_string($_SESSION['lang']); $query = "SELECT * FROM `content_".$suffix."` WHERE `page`='pagename';"; you could then add as many languages as you want, just add a new table in mysql (or even copy an existing table and edit to a different language), hope this helps, PS; When take arguments from $_GET/$_POST or $_REQUEST,- in fact anything directly rom the user MUST be treated with extreme caution when you use those variables, notice i used "mysql_escape_string" on a session variable, this should not really be needed as when a session variable is set it should always be checked for invalid characters and patterns. for example if you _know_ you "lang" variable is only going to have 2 characters, you could use "strlen()" to count the characters in the string. Quote Link to comment https://forums.phpfreaks.com/topic/93074-multi-language-site-newbie/#findComment-476867 Share on other sites More sharing options...
barney0o0 Posted February 26, 2008 Author Share Posted February 26, 2008 Cheers Uniflare That seems a good idea....at least it wont overload the tables and adding an additional launguage would seem to be rather straight forward. With reference to the buttons (to select language and ultimatley the session value), would the code on my first post be adequate (or is there a better solution (do spiders follow this))? (sorry i use a combination of handcode and DW!)...if the user presses the button does the page automatically refresh to show the content in the correct language? Thanks alot Quote Link to comment https://forums.phpfreaks.com/topic/93074-multi-language-site-newbie/#findComment-476890 Share on other sites More sharing options...
uniflare Posted February 26, 2008 Share Posted February 26, 2008 depends how you handle the query. the html code is adequete its the same type of url i use in all of my scripts. you could do: if($_GET['lang']){ $suffix = $_GET['lang']; } then use html as you stated before for the link. hope this helps, Quote Link to comment https://forums.phpfreaks.com/topic/93074-multi-language-site-newbie/#findComment-476894 Share on other sites More sharing options...
Julius Posted December 9, 2011 Share Posted December 9, 2011 Question: i was thinking, how should forum that supports multiple languages look like: posts should be saved in in one table for all languages or each language should have it's own tables in mysql? Quote Link to comment https://forums.phpfreaks.com/topic/93074-multi-language-site-newbie/#findComment-1296268 Share on other sites More sharing options...
scootstah Posted December 9, 2011 Share Posted December 9, 2011 That would be a looooooooot of tables depending how many languages you support. I would just add a flag to the post that denotes its language, and then you can simply use a WHERE clause in the query to get posts with that language. Quote Link to comment https://forums.phpfreaks.com/topic/93074-multi-language-site-newbie/#findComment-1296292 Share on other sites More sharing options...
Julius Posted December 9, 2011 Share Posted December 9, 2011 but what if one guy from spain wants to get in touch with someone from england in that forum? he should change his language to english? and what if there are forums that should be displayed in only one language, not all? Quote Link to comment https://forums.phpfreaks.com/topic/93074-multi-language-site-newbie/#findComment-1296310 Share on other sites More sharing options...
scootstah Posted December 9, 2011 Share Posted December 9, 2011 Well users wouldn't necessarily have to be sorted by language, so they could still private message and such. But to view other language's forums I would imagine they should have to change the sites language. Maybe make it a convenient dropdown box or something. If you don't want the change for all forums then put the flag in the forum table instead. Quote Link to comment https://forums.phpfreaks.com/topic/93074-multi-language-site-newbie/#findComment-1296312 Share on other sites More sharing options...
Julius Posted December 9, 2011 Share Posted December 9, 2011 thank you for your thoughts Quote Link to comment https://forums.phpfreaks.com/topic/93074-multi-language-site-newbie/#findComment-1296314 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.