dflow Posted December 29, 2009 Share Posted December 29, 2009 i want to create a template for a website where the interface will be changed according to the LangID anyone have experience in planning such a db? Quote Link to comment https://forums.phpfreaks.com/topic/186593-advise-on-planning-multi-lingual-website-interface/ Share on other sites More sharing options...
oni-kun Posted December 29, 2009 Share Posted December 29, 2009 Depends on how your template was set up, but for navigation and such you can even make it as simple as "header.php?lang=fr" and then include variables as needed. Database wise you may want to create aliases of your tables, such as nav_en, nav_es etc. if you want to separate the strings from their languages, calling it like SELECT * FROM en_table WHERE id = ... Quote Link to comment https://forums.phpfreaks.com/topic/186593-advise-on-planning-multi-lingual-website-interface/#findComment-985477 Share on other sites More sharing options...
dflow Posted December 29, 2009 Author Share Posted December 29, 2009 how would i pinpoint specific areas in the html layout for example: GuiID=23 text_en="hello" GuiID=24 text_en="goodbye" Quote Link to comment https://forums.phpfreaks.com/topic/186593-advise-on-planning-multi-lingual-website-interface/#findComment-985505 Share on other sites More sharing options...
dflow Posted December 29, 2009 Author Share Posted December 29, 2009 how would i pinpoint specific areas in the html layout for example: GuiID=23 text_en="hello" GuiID=24 text_en="goodbye" ok im answering myself, ill need to create an array with GuiID=23-->text_en="hello" what would be the correct syntax? $query = "SELECT languages.LangID, languages.`Language`, languages.LangSymbol, interface.LangID, interface.text_en, interface.link_en, interface.text_de, interface.link_de, interface.GuiID FROM languages, interface WHERE languages.LangID=interface.LangID"; $result = mysql_query($query); while($row = mysql_fetch_array($result, MYSQL_NUM)) $GuiID=interface.GuiID; { echo "text_en: {$row[$GuiID]} <br>" . } Quote Link to comment https://forums.phpfreaks.com/topic/186593-advise-on-planning-multi-lingual-website-interface/#findComment-985514 Share on other sites More sharing options...
ignace Posted December 29, 2009 Share Posted December 29, 2009 I strongly disadvice using oni-kun's recommendation as what about user created content like a blog post or a page? Or what about having multiple sources of translation eg lang_fr.php and the db table pages and the db table blog_posts? Instead keep everything in your database like this: CREATE TABLE language ( id tinyint NOT NULL auto_increment, name varchar(32), -- native format Français name_translated(32), -- understandable format French PRIMARY KEY (id)); CREATE TABLE translation ( id integer NOT NULL auto_increment, language_id tinyint, message text, message_translated text, KEY translation_language_id_fk (language_id), PRIMARY KEY (id)); Now you create your website/application like you would normally with a few exceptions: <?php if (translation_exists($row['title']) && translation_exists($row['content'])): ?> <h2><?php print translate($row['title']); ?></h2> <p><?php print translate($row['content']); ?></p> <?php endif; ?> You can also leave the translation_exists() out and your translate() function would then return the original contents because it could not find a translation. However that may be unwanted behavior. The same applies for common GUI items (you may prefer using translate() without the translation_exists() option): <li><?php print translate($row['menu_label']); ?></li> Quote Link to comment https://forums.phpfreaks.com/topic/186593-advise-on-planning-multi-lingual-website-interface/#findComment-985522 Share on other sites More sharing options...
Psycho Posted December 29, 2009 Share Posted December 29, 2009 how would i pinpoint specific areas in the html layout for example: GuiID=23 text_en="hello" GuiID=24 text_en="goodbye" Not sure what you mean by that. But, I'll throw out some ideas. In my opinion there is no one right way to do this. The best solution will depend on factors such as how big is the website, how many pages are there, how many languages will there be, and how often you will add languages or modify the site. To begin, you should create all your pages with placeholders where the text will be. Example: echo "$__SALUTATION__, $username"; where $__SALUTATION__ is a placeholder which will come from the language data. The next step is to determine how you will store the language content. You can store the language content in separate files for each module. Just create a directory structure where the folders are named according to the language (en, de, sp, fr, etc) and create the PHP code to pull the right file for the appropriate language. Each file has the value for each placeholder used in that module for the language. This is probably the easiest solution as it is easy to maintain. Alternatively, you can store the language data in the database. I would probably do something similar as above by storing the language data in a single table with columsn such as "module", "language", "placeholder", "text". Because you don't need ALL the text on any given page, you can query just the language data for the module that you are in. Then insert the values in place of the placeholder. A database has the advatage that you can add/remove languages easily (assuming you already have the translations). One note of caution: creating a site in multiple languages isn't as straitforward as doing a literal translation. If you have sentences that are dynamic (uses a person's or product's name, includes dates, etc) the placement and gender of words can be quite different from one language to another. And, something as simple as a link to the home page can't be literally translated. For example, in English you might just have a link that says "Home". But, home in English really has multiple meanings: it can be a physical structure or a place/concept. The literal translation to Spanish would be "Casa", a physical structure. And, that would make no sense as a home page for a website. Instead, Spanish uses something like "página inicial" or "Inicio". So, try to think critically of any text content you create to try and avoid these pitfalls. Also, be sure to plan the "layout" to accomodate different lengths of text. What may be a short word in one language may be quite long in another. If the layout isn't dynamic enough a long translation can screw up the layout. For example, for forms it is best to put the label above the field instead of to the left of the field. Quote Link to comment https://forums.phpfreaks.com/topic/186593-advise-on-planning-multi-lingual-website-interface/#findComment-985536 Share on other sites More sharing options...
Psycho Posted December 29, 2009 Share Posted December 29, 2009 Here is a function (with example usage) I have used in the past to determine the correct language to show a user on page load. You need to give the user a method of choosing their language (or you can try and dynamically determine it through browser settings via JS or PHP). The script will assign the users "selected language" if chosen, if not selection was made it will chack if there is a selected language for the session, if not it will check if a cookie is set, if not the default language is used. <?php // Function: getLanguage($languageList [, $selectedLang] [, $defaultLang]) // // Parameters: // - $languageList: (Required) An array of all available languages for the user // - $selectedLang: (Optional) The language the user has selected (GET or POST) // - $defaultLang: (Optional) the default language to use if unable to determine // user's language from seleted or saved values. function getLanguage($languageList, $selectedLang=null, $defaultLang=null) { //Set the default value (or first option in $languageList) $userLanguage = (!in_array($defaultLang, $languageList)) ? $languageList[0] : $defaultLang; //Detemine selected/saved user language if (!is_null($selectedLang) && in_array($selectedLang, $languageList)) { //Request was made to change the language $userLanguage = $selectedLang; setcookie('language', $userLanguage, time()+3600*24*365); //Expires in 1 year $_SESSION['language'] = $userLanguage; } else if (isset($_SESSION['language']) && in_array($_SESSION['language'], $languageList)) { //There is a saved language value in the SESSION data $userLanguage = $_SESSION['language']; } else if (isset($_COOKIE['language']) && in_array($_COOKIE['language'], $languageListAry)) { //There is a saved language value in the COOKIE data $userLanguage = $_COOKIE['language']; $_SESSION['language'] = $userLanguage; } //return the user's language return $userLanguage; } //Example usage // //Create list of available languages $languages = array ('Spanish'=>'sp', 'French'=>'fr', 'English'=>'en'); //Get the language to show the user $currentLanguage = getLanguage($languages, $_GET['lang'], 'en'); //Create vars for illustrative purposes $sessionLang = (isset($_SESSION['language'])) ? $_SESSION['language'] : 'Not set' ; $cookieLang = (isset($_COOKIE['language'])) ? $_COOKIE['language'] : 'Not set' ; ?> <html> <body> Current language: <?php echo array_search($currentLanguage, $languages) . " ($currentLanguage)"; ?> <br /><br /> $_GET['lang']: <?php echo $_GET['lang']; ?><br /> Session language: <?php echo $sessionLang; ?><br /> Cookie language: <?php echo $cookieLang; ?><br /><br /> Change Language <?php foreach ($languages as $name => $value) { echo "<a href=\"?lang={$value}\">{$name}</a> "; } ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/186593-advise-on-planning-multi-lingual-website-interface/#findComment-985577 Share on other sites More sharing options...
dflow Posted January 4, 2010 Author Share Posted January 4, 2010 thanks ill give it a shot Quote Link to comment https://forums.phpfreaks.com/topic/186593-advise-on-planning-multi-lingual-website-interface/#findComment-988261 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.