gc40 Posted January 24, 2008 Share Posted January 24, 2008 Greetings all, I have made a CMS for a site where the admin can update text content on the home page.... They login to the admin panel and enter a title, and the body. However, the client wants to offer two languages now. One English, and one French.. Therefore, I made the database changes by adding one extra field called body_french and changed body to body_english... Now the admin enters the body for both english and french... The problem comes when I display the database information on the home page. How should I allow the client to select between English and French? Should I use sessions? Or should I use a simple PHP If else fucntion? Also, if I use sessions, can someone direct me how to start? I have never used sessions. Quote Link to comment https://forums.phpfreaks.com/topic/87495-two-langauges-one-site/ Share on other sites More sharing options...
cooldude832 Posted January 24, 2008 Share Posted January 24, 2008 your over working yourself here I'm going to explain a much more generic solution to you that will save you a bunch of work when they want German Spanish and simplified Chinese also this is one way to do it 1) Make all your dynamic language areas into a database 2) Send this data through a translator (such as google translator) before echoing it out 3) Display data normally so it be like <?php $string = "Hello World" $string = lang_trans($string); function lang_trans($string){ if(!ISSET($_SESSION['language'])){ $lang = DEFAULT_LANG; } else{ $lang = $_SESSION['language']; } //Now send the string and language to go to to your translator and get it returned as $string return $string } ?> The way you translate is up to you some people have develop php string langauge translator, but you can probably use cURL to send data to google and get it translated back (this might be slow) Alternatively you can store statics in the translations, but this will be very space consuming if you expanding beyond 2 languages. But to answer your question a session is the best mode (dual it with cookies if you want a stronger method) Another way to do it is on every page load simply replace the entire page with the frame removed google translate version of it (very common solution and practical) however this only works if your CMS is set up to display the page dynamically. Quote Link to comment https://forums.phpfreaks.com/topic/87495-two-langauges-one-site/#findComment-447540 Share on other sites More sharing options...
maxudaskin Posted January 24, 2008 Share Posted January 24, 2008 What I would do if I were you is have a function that is put on a page that is required() in all pages. The function would be like so... <?php session_start(); if(empty ($_SESSION['lang'])){ if(!empty($_GET['lang'])){ $_SESSION['lang'] = $_GET['lang']; }else{ echo '<form id="lang" name="lang" method="get" action="'.$PHP_SELF.'">'; echo '<select name="lang">'; echo '<option value="en">English</option>'; echo '<option value="fr">Français</option>'; echo '</select>'; echo '<button type="submit">Submit</button>'; echo '</form>'; }}else{ $lang = $_SESSION['lang']; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/87495-two-langauges-one-site/#findComment-447544 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.