Page 1 of 1

How to creata multilingual website in PHP

Posted: Wed Feb 03, 2010 1:12 am
by syamswaroop
Hi All,
I want to know how can we develop a multi lingual website.
Our requirment is to develop in french and english.
Pls tell us how many ways we can achive it and any extra s/w needed if any.
Our environment is Xampp,windows.

thanks

Re: How to creata multilingual website in PHP

Posted: Wed Feb 03, 2010 1:17 am
by swarna2004
It can only possible
, if we can thought more new concepts[/color] :roll: 8O

Re: How to creata multilingual website in PHP

Posted: Thu Feb 04, 2010 12:01 pm
by Bind
2 ways:

1. Static Language Definition Files
2. Dynamic Translation Service (like google translate)

Language Definition File examples:

Code: Select all

<?php
#
# en.php
#
DEFINE('TITLE','Web Site Name');
DEFINE('MOTTO','Web Site Motto');
DEFINE('DESCRIPTION','Web Site Description for Meta Tag Description');
DEFINE('KEYWORDS','comma,delimited,keywords,for,meta,tag,keywords';
DEFINE('MENU0','Home');
DEFINE('MENU1','About');
DEFINE('MENU2','Services');
DEFINE('MENU3','Products');
DEFINE('MENU3','Blog');
DEFINE('MENU4','Links');
DEFINE('MENU5','Contact');
DEFINE('SIDEBAR','Sponsors/Advertisements');
DEFINE('FOOTER','&copy; '.date('Y').TITLE);
?>

Code: Select all

<?php
#
# fr.php
#
DEFINE('TITLE','Nom du site');
DEFINE('MOTTO','Devise du site');
DEFINE('DESCRIPTION','Description du site Web pour Meta Description de la balise');
DEFINE('KEYWORDS','virgules, délimitée, mots clés, pour, meta, tag, mots clés';
DEFINE('MENU0','Accueil');
DEFINE('MENU1','À propos de');
DEFINE('MENU2','Services');
DEFINE('MENU3','Produits');
DEFINE('MENU3','Blog');
DEFINE('MENU4','Liens');
DEFINE('MENU5','Contact');
DEFINE('SIDEBAR','Publicités');
DEFINE('FOOTER','&copy; '.date('Y').TITLE);
?>
 
usage:

Code: Select all

<?php
if(isset($_GET['lang'] && $_GET['lang']=='fr'))
    {
        include('./includes/lang/fr.php');
    }
elseif(!isset($_GET['lang']) || $_GET['lang']=='en'))
    {
        include('./includes/lang/en.php');
    }
?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
 "http://www.w3.org/TR/html4/loose.dtd">
 
<html>
 
<head>
<title><?php  echo TITLE; ?></title>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta name="description" content="<?php echo DESCRIPTION; ?>">
<meta name="keywords" content="<?php echo KEYWORDS; ?>">
</head>
 
<body>
 
<div id="header">
    <h1><?php echo TITLE; ?></h1>
    <h5><?php echo MOTTO; ?></h5>
</div>
 
 
 
<div id="menu">
    <UL>
<?php
        for($i=0;$i<6;$i++)
            {
                echo '<li><a href="./?id='.MENU.$i.'">'.MENU.$i.'</a></li>';
            }
?>
    </UL>
</div>
 
 
<div id="sidebar">
    <?php echo SIDEBAR; ?>
</div>
 
 
<div id="content">
display this page in <a href="./?lang=fr">french</a> or <a href="./?lang=en">english</a>.
</div>
 
 
<div id="footer">
    <?php echo FOOTER; ?>
</div>
 
</body>
 
</html>
this code was written fast without processing it for errors just to give you an idea of how to do it, so it might need touched up a little.

as to the second way, the dynamic language translation services, you can import the translation html and parse for the translation value, like with google translate to either dynamically display or even to create the language definition files themselves.

for content I would use a database system, but it can be done with language definition files as well.