0

hello...
anybody give suggestion..
i am doing one task what it zzz means my site is in english. i have dropdown list having multiple languages. if anybody changes language option site all pages change to that language. any body knows how to do it?

Votes + Comments
didn't show effort
8
Contributors
58
Replies
61
Views
7 Years
Discussion Span
Last Post by muralikalpana
Featured Replies
  • 1
    diafol 3,720   7 Years Ago

    Just a word from somebody who has to create bilingual sites: Google translate is fine if you label it such - i.e. the user knows that it is a page translated by Google. If you hide the frame and do not make it clear that the page is an on-the-fly, … Read More

0

I'd use sessions
and some function, that receives some alias, checks variable in session and gives text. And in every page text like

echo ffff('alias1');

or simply different page variants, and script gives us one

0

I'd use sessions
and some function, that receives some alias, checks variable in session and gives text. And in every page text like

echo ffff('alias1');

or simply different page variants, and script gives us one

i didnt understood any thing. but i want to do exactly like this. any help.
http://www.click2translate.com/quote/quick_quote.asp

Edited by muralikalpana: n/a

0

here i didnt saw anything about language translate.

I understood, I suggested only the way

0

I understood, I suggested only the way

ok. where to start in that way. now i have blank mind. suggest me right way.

0

ei dude theres no function or whatsoever that automatically change it's context language... its a tough job... u had to manually code it to translate every context on different language... you can save the data into the database and query them upon changing the language setting.

0

ei dude theres no function or whatsoever that automatically change it's context language... its a tough job... u had to manually code it to translate every context on different language... you can save the data into the database and query them upon changing the language setting.

so it takes lots of tim to change every page. is there any another choice.

0

google toolbar is a frameset
put a framebreaker in your menu include, no more toolbar

<script type='text/javascript'>
if (window != top) {top.location.replace(self.location.href);}
</script>

Edited by almostbob: n/a

0

google toolbar is a frameset
put a framebreaker in your menu include, no more toolbar

<script type='text/javascript'>
if (window != top) {top.location.replace(self.location.href);}
</script>

yaa.....i put it this code. but no change. still toolbar is coming no change.

1

Just a word from somebody who has to create bilingual sites:

Google translate is fine if you label it such - i.e. the user knows that it is a page translated by Google. If you hide the frame and do not make it clear that the page is an on-the-fly, automated translation, users could decide that you are a cowboy outfit with a very poor grasp of their language and do not deserve their time of day.

I suggest that if you offer a Google translate service via widget/link - say so.

If you need to build multilingual sites from scratch and have proper translations (your own) - you need to ensure appropriate (x)html language tagging (meta and html tags, language attributes for general tags):

e.g. for Welsh:

<html xmlns="http://www.w3.org/1999/xhtml" lang="cy-GB" xml:lang="cy-GB">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<meta http-equiv="Content-Language" content="cy-GB"/>
...(rest of head/page)...

When using alternative language, in this case, Italian, tag attributes should be used:

<p>Erbyn hyn mae XHTML wedi sefydlu ei hun fel y <em lang="it" xml:lang="it">lingua franca</em> o dudalenau'r we.</p>

In this way, you can use CSS for language-specific formatting - so you wouldn't really need <em> - you could use <span> instead and then specify the formatting via CSS rules like this:

span:lang(it){
  color:green;
  font-weight:bold;
}

In order to keep your translations in order, you need to have language files or db fields that are loaded depending on the chosen language. These can be determined by session / cookie variables. Cookies are useful for returning users - so that their chosen language is selected automatically. Sessions generally useful. You need to check for post language variables when an user selects a language from a dropdown - set the cookie and session variables.

0

Hello Ardav......i put this code in my code. but google iframe comming. is there any chance to breakout google frame. actually i am trying like this as your said.

<?php
	session_start();
	require_once("index.conf");
	$language = new Language();
	$lang = $language->getLanguage(@$_POST['lang']);
?>
<html xmlns="http://www.w3.org/1999/xhtml" lang="cy-GB" xml:lang="cy-GB">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<meta http-equiv="Content-Language" content="cy-GB"/>
<title>Untitled Document</title>
<style type="text/css">
span:lang(it){
  color:green;
  font-weight:bold;
}
</style>
<script type='text/javascript'>
if (window != top) {top.location.replace(self.location.href);}
</script>
</head>

<body>
<form name="language" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
	<select onchange = "document.language.submit()" name="lang">
    	<option selected="selected">select-language</option>
        <option value="en">English</option>
        <option value="es">Spanish</option>
        <option value="fr">French</option>
     </select>

<p>Erbyn hyn mae XHTML wedi sefydlu ei hun fel y <em lang="it" xml:lang="it">lingua franca</em> o dudalenau'r we.</p>
</form>
</body>
</html>

is there any chance to breakout google iframe. and using below dropdown can we make exactly same functionality. i mean from this dropdown , can we redirect to google?

<select onchange = "document.language.submit()" name="lang">
    	<option selected="selected">select-language</option>
        <option value="en">English</option>
        <option value="es">Spanish</option>
        <option value="fr">French</option>
     </select>

Edited by muralikalpana: n/a

0

Hmmm, you're mixing two different approaches here Mura. You've combined the manual method with the Goggle translate method - that's not what I was proposing. Unfortunately, when you use Google translate, you're left at the mercy of its output, with little control of the tagging - it usually leaves that intact. I assume from your post that you need Google translate as you're not able to do that yourself. In which case, you could disregard the majority of my post - unless you do some js scripting to change the tag attributes prior to letting Google translate do its stuff. I don't know whether those changes would be retained though.

I'll give you an example from my Science Club Blog (http://cymercem.blogspot.com/):

<a style="cursor: pointer;" href="http://www.blogger.com/rearrange?blogID=4297613348291744433&amp;action=editWidget&amp;sectionId=sidebartop&amp;widgetType=null&amp;widgetId=HTML4#" target="_blank" rel="nofollow" title="Google-Translate - Welsh to English" onclick="window.open('http://www.google.com/translate?u='+encodeURIComponent(location.href)+'&amp;sl=cy&amp;tl=en&amp;hl=en&amp;ie=UTF8'); return false;">ENGLISH</a>

This is the code form the first translation link in the screenshot. This is obviously for a list item, but could easily modified for a dropdown.
I have to admit that the code isn't mine and I only have a passing understanding of how it works.

It does seem that Google is holding all the other frames as opposed to my blog site holding the Google frame. Don't know if this makes any difference.

Edited by diafol: n/a

Attachments gt.jpg 14.53 KB
0

This is a quote from my website

On an advanced content management system, you may want to offer a feature to convert text into different languages. Well I have created a script which uses the google translator to translate your data and send the translation to your website. So first copy the below function into the header of your php file.

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 to use the translator, you call the function like below and below is an example of english to chinese:

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

The first field in the above function is the text to convert, second field language from, third field is language to. All languages are abbrievated. So below are the abbrievations you may use and that is it. It is as simple as that.

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

Enjoy

0

I thought you'd near to cURL to avoid frame problem - anyway couldn't get your code to fly. Doesn't return anything.

0

I thought you'd near to cURL to avoid frame problem - anyway couldn't get your code to fly. Doesn't return anything.

Doesn't return anything... That annoying google making things difficult. digital-either made a good post some time ago and posted the following api.

/**
 * Translating language with Google API
 * @author gabe@fijiwebdesign.com
 * @version $id$
 * @license - Share-Alike 3.0 (http://creativecommons.org/licenses/by-sa/3.0/)
 * 
 * Google requires attribution for their Language API, please see: http://code.google.com/apis/ajaxlanguage/documentation/#Branding
 * 
 */
class Google_Translate_API {

	/**
	 * Translate a piece of text with the Google Translate API
	 * @return String
	 * @param $text String
	 * @param $from String[optional] Original language of $text. An empty String will let google decide the language of origin
	 * @param $to String[optional] Language to translate $text to
	 */
	function translate($text, $from = '', $to = 'en') {
		$url = 'http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q='.rawurlencode($text).'&langpair='.rawurlencode($from.'|'.$to);
		$response = file_get_contents(
			$url,
			null,
			stream_context_create(
				array(
					'http'=>array(
					'method'=>"GET",
					'header'=>"Referer: http://".$_SERVER['HTTP_HOST']."/\r\n"
					)
				)
			)
		);
		if (preg_match("/{\"translatedText\":\"([^\"]+)\"/i", $response, $matches)) {
			return self::_unescapeUTF8EscapeSeq($matches[1]);
		}
		return false;
	}
	
	/**
	 * Convert UTF-8 Escape sequences in a string to UTF-8 Bytes
	 * @return UTF-8 String
	 * @param $str String
	 */
	function _unescapeUTF8EscapeSeq($str) {
		return preg_replace_callback("/\\\u([0-9a-f]{4})/i", create_function('$matches', 'return html_entity_decode(\'&#x\'.$matches[1].\';\', ENT_NOQUOTES, \'UTF-8\');'), $str);
	}
}

Then to use it

$text = 'Welcome to my website.';
$trans_text = Google_Translate_API::translate($text, '', 'it');
if ($trans_text !== false) {
	echo $trans_text;
}

However it is limited on how much data you can input. Not to say how many translation requests you can make though. Hopefully that should work.

0

This is a quote from my website

Enjoy

i am getting this error.

Call to undefined function curl_init() in C:\wamp\www\addmultiplelanguajes-2009-08-15\k1.php on line 36

thanks for ur reply....

actually i would like to translate the whole page at once. is this translate the whole page at once with out google frame. or else call this function for each and every bit of word translate? this is full doubt of me......

Edited by muralikalpana: n/a

0

You probably don't have curl installed but try the code in post #23. (My previous post). It should work without curl as long as your using php5.

0

You probably don't have curl installed but try the code in post #23. (My previous post). It should work without curl as long as your using php5.

ya...it is working. but i am trying for translate the whole page at once with using google apis. but topof the page not come google frame. i would like to create static dropdown box for selecting languages. is there any chance to do like this.
exactly like this http://www.click2translate.com/quote/quick_quote.asp

Edited by muralikalpana: n/a

0

Why not use the translate function like the echo take so depending on the language input into the url it will translate to that language. Example:
URL=example.com/index.php?language=it

<?php
/**
 * Translating language with Google API
 * @author gabe@fijiwebdesign.com
 * @version $id$
 * @license - Share-Alike 3.0 (http://creativecommons.org/licenses/by-sa/3.0/)
 * 
 * Google requires attribution for their Language API, please see: http://code.google.com/apis/ajaxlanguage/documentation/#Branding
 * 
 */
class Google_Translate_API {

	/**
	 * Translate a piece of text with the Google Translate API
	 * @return String
	 * @param $text String
	 * @param $from String[optional] Original language of $text. An empty String will let google decide the language of origin
	 * @param $to String[optional] Language to translate $text to
	 */
	function translate($text, $from = '', $to = 'en') {
		$url = 'http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q='.rawurlencode($text).'&langpair='.rawurlencode($from.'|'.$to);
		$response = file_get_contents(
			$url,
			null,
			stream_context_create(
				array(
					'http'=>array(
					'method'=>"GET",
					'header'=>"Referer: http://".$_SERVER['HTTP_HOST']."/\r\n"
					)
				)
			)
		);
		if (preg_match("/{\"translatedText\":\"([^\"]+)\"/i", $response, $matches)) {
			return self::_unescapeUTF8EscapeSeq($matches[1]);
		}
		return false;
	}
	
	/**
	 * Convert UTF-8 Escape sequences in a string to UTF-8 Bytes
	 * @return UTF-8 String
	 * @param $str String
	 */
	function _unescapeUTF8EscapeSeq($str) {
		return preg_replace_callback("/\\\u([0-9a-f]{4})/i", create_function('$matches', 'return html_entity_decode(\'&#x\'.$matches[1].\';\', ENT_NOQUOTES, \'UTF-8\');'), $str);
	}
}



function display($input) {
$trans_text = Google_Translate_API::translate($input, '', $_GET['language']);
    if ($trans_text !== false) {
        echo $trans_text;
    }
}

//html still must use echo function
echo '<b>';
//now to echo non-html or text to translate
display("this is a test");
echo '</b>';

You will see at the bottom of that file how you can echo some text which will display in whatever language is selected in the url. Is that any more helpful as that would be the best solution if your designing from scratch.

0

Why not use the translate function like the echo take so depending on the language input into the url it will translate to that language. Example:
URL=example.com/index.php?language=it
i used like this my url. just see once and tell me how to implement that. here is my page.

<?

/**
 * Translating language with Google API
 * @author gabe@fijiwebdesign.com
 * @version $id$
 * @license - Share-Alike 3.0 (http://creativecommons.org/licenses/by-sa/3.0/)
 * 
 * Google requires attribution for their Language API, please see: http://code.google.com/apis/ajaxlanguage/documentation/#Branding
 * 
 */
class Google_Translate_API {

	/**
	 * Translate a piece of text with the Google Translate API
	 * @return String
	 * @param $text String
	 * @param $from String[optional] Original language of $text. An empty String will let google decide the language of origin
	 * @param $to String[optional] Language to translate $text to
	 */
	function translate($text, $from = '', $to = 'en') {
		$url = 'http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q='.rawurlencode($text).'&langpair='.rawurlencode($from.'|'.$to);
		$response = file_get_contents(
			$url,
			null,
			stream_context_create(
				array(
					'http'=>array(
					'method'=>"GET",
					'header'=>"Referer: http://".$_SERVER['HTTP_HOST']."/\r\n"
					)
				)
			)
		);
		if (preg_match("/{\"translatedText\":\"([^\"]+)\"/i", $response, $matches)) {
			return self::_unescapeUTF8EscapeSeq($matches[1]);
		}
		return false;
	}
	
	/**
	 * Convert UTF-8 Escape sequences in a string to UTF-8 Bytes
	 * @return UTF-8 String
	 * @param $str String
	 */
	function _unescapeUTF8EscapeSeq($str) {
		return preg_replace_callback("/\\\u([0-9a-f]{4})/i", create_function('$matches', 'return html_entity_decode(\'&#x\'.$matches[1].\';\', ENT_NOQUOTES, \'UTF-8\');'), $str);
	}
}


$input= "http://localhost/addmultiplelanguajes-2009-08-15/k1.php";
function display($input) {
$trans_text = Google_Translate_API::translate($input, '', $_GET['language']);
    if ($trans_text !== false) {
        echo $trans_text;
    }
}


?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<form name="language" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
	<select onchange = "document.language.submit()"  name="lang">
    	<option selected="selected">select-language</option>
        <option value="en"<? if($_POST && $_POST['lang']=="en"){?> selected="selected"<? }?>>English</option>
        <option value="es"<? if($_POST && $_POST['lang']=="es"){?> selected="selected"<? }?>>Spanish</option>
        <option value="fr"<? if($_POST && $_POST['lang']=="fr"){?> selected="selected"<? }?>>French</option>
     </select><br>

<p>Larry Brandt grew up in a small rural town in Missouri where hunting, fishing and outdoor life was an everyday experience.He was fortunate to live close to the Swan Lake National Wildlife Refuge.The Refuge is over 10,000 acres and provides nesting, resting and feeding areas for Waterfowl, primarily ducks.

The migrating populations of ducks and geese at Swan Lake number in the thousands.These waterfowl provided the artist great opportunities to study and learn about their species.

Although the artist has been woodcarving only a few years, he has been painting for over fifty years.</p>
</form>
</body>
</html>
0

Try this.

<?
if (!isset($_GET['language']) || empty($_GET['language'])) {
$_GET['language']='en';
}
/**
 * Translating language with Google API
 * @author gabe@fijiwebdesign.com
 * @version $id$
 * @license - Share-Alike 3.0 (http://creativecommons.org/licenses/by-sa/3.0/)
 * 
 * Google requires attribution for their Language API, please see: http://code.google.com/apis/ajaxlanguage/documentation/#Branding
 * 
 */
class Google_Translate_API {

	/**
	 * Translate a piece of text with the Google Translate API
	 * @return String
	 * @param $text String
	 * @param $from String[optional] Original language of $text. An empty String will let google decide the language of origin
	 * @param $to String[optional] Language to translate $text to
	 */
	function translate($text, $from = '', $to = 'en') {
		$url = 'http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q='.rawurlencode($text).'&langpair='.rawurlencode($from.'|'.$to);
		$response = file_get_contents(
			$url,
			null,
			stream_context_create(
				array(
					'http'=>array(
					'method'=>"GET",
					'header'=>"Referer: http://".$_SERVER['HTTP_HOST']."/\r\n"
					)
				)
			)
		);
		if (preg_match("/{\"translatedText\":\"([^\"]+)\"/i", $response, $matches)) {
			return self::_unescapeUTF8EscapeSeq($matches[1]);
		}
		return false;
	}
	
	/**
	 * Convert UTF-8 Escape sequences in a string to UTF-8 Bytes
	 * @return UTF-8 String
	 * @param $str String
	 */
	function _unescapeUTF8EscapeSeq($str) {
		return preg_replace_callback("/\\\u([0-9a-f]{4})/i", create_function('$matches', 'return html_entity_decode(\'&#x\'.$matches[1].\';\', ENT_NOQUOTES, \'UTF-8\');'), $str);
	}
}


$input= "http://localhost/addmultiplelanguajes-2009-08-15/k1.php";
function display($input) {
$trans_text = Google_Translate_API::translate($input, '', $_GET['language']);
    if ($trans_text !== false) {
        echo $trans_text;
    }
}




echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n";
echo '<html xmlns="http://www.w3.org/1999/xhtml">'."\n";
echo '<head>'."\n";
echo '<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />'."\n";
echo '<title>'; display('Untitled Document'); echo '</title>'."\n";
echo '</head>'."\n";
echo "\n";
echo '<body>'."\n";
echo '<form name="language" action="'.$_SERVER['PHP_SELF'].'" method="GET">'."\n";
echo '	<select onchange = "document.language.submit()"  name="language">'."\n";
echo '    	<option selected="selected">'; display('select-language'); echo '</option>'."\n";
echo '        <option value="en">'; display('English'); echo '</option>'."\n";
echo '        <option value="es">'; display('Spanish'); echo '</option>'."\n";
echo '        <option value="fr">'; display('French'); echo '</option>'."\n";
echo '     </select><br>'."\n";
echo "\n";
echo '<p>'; display('Larry Brandt grew up in a small rural town in Missouri where hunting, fishing and outdoor life was an everyday experience.He was fortunate to live close to the Swan Lake National Wildlife Refuge.The Refuge is over 10,000 acres and provides nesting, resting and feeding areas for Waterfowl, primarily ducks.

The migrating populations of ducks and geese at Swan Lake number in the thousands.These waterfowl provided the artist great opportunities to study and learn about their species.

Although the artist has been woodcarving only a few years, he has been painting for over fifty years.'); echo '</p>'."\n";
echo '</form>'."\n";
echo '</body>'."\n";
echo '</html>'."\n";
?>
0

Try this

thank you so much. it is amazing.
is it problem when retrivinng data from database.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.