I developed a forum in php that works only in English but I wanted to make it work in another language as per the user request can anyone please tell me how. thanx in advance

Do you want to create a separate forum for each language? Or do you want to translate the same forum to different languages? I think the latter would be much much harder...

Its the latter that I want to do

I cheat,
created a form that chooses the 'to' language and pass the page to Yahoo translator babelfish
Its in menu.inc.php so appears in every page, and links etc work in the translated language, and subsequent pages are translated
google translator also works, but you have to find the url, urself
replace mysite.com with your site

<form action="http://babelfish.yahoo.com/translate_url?doit=done&tt=url&intl=1&fr=bf-home&btnTrUrl=Translate&trurl=http://www.mysite.com<?php echo$_SERVER['PHP_SELF']; ?>" method='post'>
<select name='lp'>
<option selected title='La traduction est automatique, confirment svp les details essentiels dans la version Anglaise originale' value='en_fr'>Fran&ccedil;ais</option>
<option value='en_de' title='Die &Uuml;bersetzung ist, best&auml;tigen bitte wesentliche Details in der englischen Version automatisch'>Deutsch</option>
<option value='en_es' title='La traduccion es automatica, confirma por favor los detalles esenciales en la version Inglesa original'>Espa&ntilde;ol</option>
<option value='en_it' title='La traduzione &egrave; automatica, prego conferma i particolari essenziali nella versione inglese'>Italiano</option>
<option value='en_nl' title='De vertaling is automatisch, te bevestigen gelieve essenti&euml;le details in de Engelse versie'>Nederlands</option>
<option value='en_ru' title='& #1055;& #1077;& #1088;& #1077;& #1074;& #1086;& #1076; & #1072;& #1074;& #1090;& #1086;& #1084;& #1072;& #1090;& #1080;& #1095;& #1077;& #1089;& #1082;& #1080;& #1081;, & #1087;& #1086;& #1078;& #1072;& #1083;& #1091;& #1081;& #1089;& #1090;& #1072; & #1087;& #1086;& #1076;& #1090;& #1074;& #1077;& #1088;& #1078;& #1076;& #1072;& #1077;& #1090; & #1085;& #1077;& #1086;& #1073;& #1093;& #1086;& #1076;& #1080;& #1084;& #1099;& #1077; & #1076;& #1077;& #1090;& #1072;& #1083;& #1080; & #1074; & #1072;& #1085;& #1075;& #1083;& #1080;& #1081;& #1089;& #1082;& #1086;& #1081; & #1074;& #1077;& #1088;& #1089;& #1080;& #1080;'>& #1056;& #1091;& #1089;& #1089;& #1082;& #1086;</option></select>
<input type='submit' value='Translate'></form>

Cyrillic has to be escaped daniweb doesnt allow escapes inside code blocks so this (line 8) is broken, to put it back together

replace all
ampersand space pound // & #
with
ampersand pound // &#

thank you! but I wanted to display the change without going to yahoo
on the page itself the language is Amharic(ethiopian language) and I have the translator what I want to know is how to use it.

A simple way to develop a multilanguage script is to define every text as a variable...
Example:

echo "title";
echo "text";
echo "comments";

Should be replaced by:

include 'en.php'; // or fr.php, de.php, etc...
echo $msg[0];
echo $msg[1];
echo $msg[2];

Create a en.php where the variables are defined as...

$msg[0] = "title";
$msg[1] = "text";
$msg[2] = "comments";

Create a fr.php (french) where the variables are defined as...

$msg[0] = "titre";
$msg[1] = "texte";
$msg[2] = "commentaires";

etc...
Consider the option to put the language choice in a config.php file...

Although as previously mentioned, you may use arrays to select a language, that may not always be a possible option if other users submit content. To solve this with a bit of extra cpu, you may use the google translator via php without leaving the website. The script is as follows:

function translate($sentence,$languagefrom,$languageto)
{
$homepage = file_get_contents('http://translate.google.com/translate_t');
if ($homepage==false) {$homepage='';}
preg_match_all("/<form[^>]+ction=\"\/translate_t\".*<\/form>/",$homepage,$botmatch);
$botmatch[0][0]=preg_replace("/<\/form>.*/",'',$botmatch[0][0]);
preg_match_all("/<input[^>]+>/",$botmatch[0][0],$botinput);
$id=0;
while (isset($botinput[0][$id]))
	{
	preg_match_all("/value=(\"|'|[^\"'])[^\"']+(\"|'|[^\"'])?( |>|	)/",$botinput[0][$id],$tmp);
	$tmp[0][0]=preg_replace('/((\'|")?[^\'"]+)/','$1',$tmp[0][0]);
	$tmp[0][0]=preg_replace('/(\'|")/','',$tmp[0][0]);
	$tmp[0][0]=preg_replace('/.*value=/i','',$tmp[0][0]);
	$len=strlen($tmp[0][0]);
	$len-=1;
	$tmp[0][0]=substr($tmp[0][0],0,$len);
 
	preg_match_all("/name=(\"|'|[^\"'])[^\"']+(\"|'|[^\"'])?( |>|	)/",$botinput[0][$id],$tmpname);
	$tmpname[0][0]=preg_replace('/((\'|")?[^\'"]+)/','$1',$tmpname[0][0]);
	$tmpname[0][0]=preg_replace('/(\'|")/','',$tmpname[0][0]);
	$tmpname[0][0]=preg_replace('/.*name=/i','',$tmpname[0][0]);
	$len=strlen($tmpname[0][0]);
	$len-=1;
	$tmpname[0][0]=substr($tmpname[0][0],0,$len);
 
	if (strlen($tmpname[0][0])>0 && !in_array($tmpname[0][0],array('text','sl','tl')))
		{
		$vars.=$tmpname[0][0]."=".$tmp[0][0].'&';
		}
	unset($tmp);
	unset($tmpname);
	$id+=1;
}
$curl_handle=curl_init('http://translate.google.com/translate_t');
curl_setopt($curl_handle, CURLOPT_HEADER, true);
curl_setopt($curl_handle, CURLOPT_FAILONERROR, true);
curl_setopt($curl_handle, CURLOPT_HTTPHEADER, 
Array("User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.15) Gecko/20080623 Firefox/2.0.0.15") );   
curl_setopt($curl_handle, CURLOPT_POST, true);
curl_setopt($curl_handle, CURLOPT_POSTFIELDS, $vars.'text='.$sentence.'&sl='.$languagefrom.'&tl='.$languageto);
curl_setopt($curl_handle, CURLOPT_NOBODY, false);
curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,false);
curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);
$buffer = curl_exec($curl_handle);
curl_close($curl_handle);
 
$buffer=strip_tags($buffer,'<div>');
preg_match_all("/\<div id\=result_box dir\=\"[^\"]+\"\>[^<]+\<\/div\>/",$buffer,$match);
$match[0][0]=strip_tags($match[0][0]);
return $match[0][0];
}

Then the language option and the abbreviations that you place into the function are as follows:

ar = Arabic
bg = Bulgarian
ca = Catalan
zh-CN = Chinese
hr = Croatian
cs = Czech
da = Danish
nl = Dutch
en = English
tl = Filipino
fi = Finnish
fr = French
de = German
el = Greek
iw = Hebrew
hi = Hindi
id = Indonesian
it = Italian
ja = Japanese
ko = Korean
lv = Latvian
lt = Lithuanian
no = Norwegian
pl = Polish
pt = Portuguese
ro = Romanian
ru = Russian
sr = Serbian
sk = Slovak
sl = Slovenian
es = Spanish
sv = Swedish
uk = Ukrainian
vi = Vietnamese

And to use the function the following is an example:

echo translate('This is the text','en','zh-CN');

However the function does take a couple of seconds to process. Just don't use that function too many times on the one page.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.