954,561 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

About language translotor??

Hi,
I want to do like
1> drop down menu for language selection
2> If select language convert whole page text to that language
selected language.

So how to add or use translator( converter )
how to use google translator??
How to do that??

Aamit
Posting Whiz
342 posts since Apr 2008
Reputation Points: 3
Solved Threads: 15
 
<a href='http://babelfish.yahoo.com/translate_url?doit=done&tt=url&intl=1&fr=bf-home<strong>&lp=en_fr</strong>&btnTrUrl=Translate&trurl=<?php echo urlencode('$_SERVER['SERVER_NAME'].$_SERVER['PHP_SELF']); ?>' title='La traduction est automatique, confirment svp les details essentiels dans la version Anglaise originale'><font size='-2'>Fran&ccedil;ais</font></a>

<a href='http://babelfish.yahoo.com/translate_url?doit=done&tt=url&intl=1&fr=bf-home<strong>&lp=en_es</strong>&btnTrUrl=Translate&trurl=<?php echo urlencode('$_SERVER['SERVER_NAME'].$_SERVER['PHP_SELF']); ?>' title='La traduccion es automatica, confirma por favor los detalles esenciales en la version Inglesa original'><font size='-2'>Espa&ntilde;ol</font></a>


for a html select
each would be coded the same as above, changing the language pair &lp= and of course altering the title prompt

most people use a translator

almostbob
Posting Sensei
3,149 posts since Jan 2009
Reputation Points: 571
Solved Threads: 376
 

I want to translate whole page..text ...not redirect page to translator...

Aamit
Posting Whiz
342 posts since Apr 2008
Reputation Points: 3
Solved Threads: 15
 
I want to translate whole page..text ...not redirect page to translator...


You dont already have a frame breaker in your ?

<script language='Javascript' type='text/javascript'>
<!-- 
if (top.location != self.location) { top.location = self.location.href }
//--> 
</script>
almostbob
Posting Sensei
3,149 posts since Jan 2009
Reputation Points: 571
Solved Threads: 376
 

Hi,
I added frame breaker.
and execute code by selecting option value.
It translate page to selected language

But problem is it translates my all options name also. i.e. language name which is in drop down list.

How to solve this??

Aamit
Posting Whiz
342 posts since Apr 2008
Reputation Points: 3
Solved Threads: 15
 

I modified my code instead of drop down i used images

<?
$URL="http://". $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"];

?>
<table style="text-align: left; width: 150px;" border="0"
cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td><a href=
"http://72.14.235.100/translate_c?hl=en&amp;langpair=en%7Cfr&amp;&u=<? echo $URL;?>">
<img src=
"images/frenchflag.jpg" alt=
"Fran&ccedil;ais/French" width="20" height="10" style="border: 0px solid ; width: 20px; height: 10px;"></a></td>
<td><a href=
"http://72.14.235.100/translate_c?hl=en&amp;langpair=en%7Cde&amp;u=<? echo $URL;?>">
<img style="border: 0px solid ; width: 20px; height: 10px;" alt=
"Deutsch/German" src=
"images/germanflag.jpg"></a></td>
<td><a href=
"http://72.14.235.100/translate_c?hl=en&amp;langpair=en%7Cit&amp;u=<? echo $URL;?>">
<img style="border: 0px solid ; width: 20px; height: 10px;" alt=
"Italiano/Italian" src=
"images/italianflag.jpg"></a></td>
<td><a href=
"http://72.14.235.100/translate_c?hl=en&amp;langpair=en%7Cnl&amp;u=<? echo $URL;?>">
<img title="Netherlands/Dutch" style=
"border: 0px solid ; width: 20px; height: 10px;" alt=
"Netherlands/Dutch" src=
"images/flag-netherlands.jpg"></a></td>
<td><a href=
"http://72.14.235.100/translate_c?hl=en&amp;langpair=en%7Ces&amp;u=<? echo $URL;?>">
<img style="border: 0px solid ; width: 20px; height: 10px;" alt=
"Espa&ntilde;ol/Spanish" src=
"images/spanishflag.jpg"></a></td>
<td><a href=
"http://72.14.235.100/translate_c?hl=en&amp;langpair=en%7Cpt&amp;u=<? echo $URL;?>">
<img style="border: 0px solid ; width: 20px; height: 10px;" alt=
"Portugu&ecirc;s/Portuguese" src=
"images/portugeseglag.jpg"></a></td>
</tr><tr>
<td><a href=
"http://72.14.235.100/translate_c?hl=en&amp;langpair=en%7Cko&amp;u=<? echo $URL;?>">
<img style="border: 0px solid ; width: 20px; height: 10px;" alt=
"&iacute;&bull;&oelig;&ecirc;&micro;&shy;&igrave;&ndash;&acute;/Korean"
src="images/koreanflag.jpg"></a></td>
<td><a href=
"http://72.14.235.100/translate_c?hl=en&amp;langpair=en%7Czh-CN&amp;u=<? echo $URL;?>">
<img style="border: 0px solid ; width: 20px; height: 10px;" alt=
"&auml;&cedil;&shy;&aelig;&ndash;&Dagger;&iuml;&frac14;&circ;&ccedil;&reg;&euro;&auml;&frac12;&ldquo;&iuml;&frac14;&permil;/Chinese Simplified"
src="images/chineseflag.jpg"></a></td>
<td><a href=
"http://72.14.235.100/translate_c?hl=en&amp;langpair=en%7Cja&amp;u=<? echo $URL;?>">
<img style="border: 0px solid ; width: 20px; height: 10px;" alt=
"&aelig;&mdash;&yen;&aelig;&oelig;&not;&egrave;&ordf;ž/Japanese"
src="images/japanflag.jpg"></a></td>
<td><a href=
"http://72.14.235.100/translate_c?hl=en&amp;langpair=en%7Cel&amp;u=<? echo $URL;?>">
<img style="border: 0px solid ; width: 20px; height: 10px;" alt=
"Greek" src="images/greekflag.gif"></a></td>
<td><a href=
"http://72.14.235.100/translate_c?hl=en&amp;langpair=en%7Car&amp;u=<? echo $URL;?>">
<img title="Arabic / UAE" style=
"border: 0px solid ; width: 20px; height: 10px;" alt="Arabic / UAE"
src="images/arabic_flag.bmp"></a></td>
<td><a href=
"http://72.14.235.100/translate_c?hl=en&amp;langpair=en%7Cru&amp;u=<? echo $URL;?>">
<img title="Russia/Russian" style=
"border: 0px solid ; width: 20px; height: 10px;" alt=
"Russia/Russian" src=
"images/russia.gif"></a></td>
</tr>
</table>


At first time it translate language correctly
image shows link
http://72.14.235.100/translate_c?hl=en&langpair=en|fr&u=http://www.xyx.com/&usg=ALkJrhgoRPxFWQuYskMr6qlwsRRh7r9jOg

but if again translate to another language...
it gives error ..
bcoz image shows

http://72.14.235.100/translate_c?hl=en&langpair=en|fr&u=http://72.14.235.100/translate_c%3Fhl%3Den%26langpair%3Den%257Cde%26u%3Dhttp://www.xyz.com/&usg=ALkJrhjgP4Jsyj2DmWP9GfOLrxa-BrVRVA

How to rewrite url or solve this??
How to do this??

Aamit
Posting Whiz
342 posts since Apr 2008
Reputation Points: 3
Solved Threads: 15
 

keep dropdpwn names written in the target language.
Francais
Espanol
deutsch
suomi
with the greves & cedillas carets etc
They are not words in the source of the language pair so are skipped in translation, the labels dont change.

If you examine the sample link title text and innerHtml both are written in the the target language, so the labels do not alter.
a user looking for a german translation of your site for readability, expects to see 'deutsch', not allemande german njemački německy

google translate Babelfish, already offer their sites localized, so all language pairs are available to all persons pretty much in their own language.

$_SERVER['request_url'] is the url requesting the page, if the translator is working it is the translator.
the original was PHP_SELF which works
If you change something and it ceases to work, then the change is the fault

almostbob
Posting Sensei
3,149 posts since Jan 2009
Reputation Points: 571
Solved Threads: 376
 

Hi almostbob,
can you explain this
with the greves & cedillas carets etc ??

Aamit
Posting Whiz
342 posts since Apr 2008
Reputation Points: 3
Solved Threads: 15
 

Also to consider is the google AJAX language API.

It offers translation of a block of text to different languages through a JavaScript API, or through a REST interface.

Here's documentation:
http://code.google.com/apis/ajaxlanguage/documentation/

If you want to use PHP, you can use the REST interface. The response format is JSON.

eg:
http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=hello%20world&langpair=en|it

With PHP, to achieve the same:

<?php

$text = 'hello world';
$response = file_get_contents('http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q='.urlencode($text).'&langpair=en|it';

?>


The response looks like:

{"responseData": {"translatedText":"ciao mondo"}, "responseDetails": null, "responseStatus": 200}


So you need a JSON parser to convert this to PHP objects, and get the "translatesdText".

PHP5 supports JSON natively. With PHP4 you can compile PHP with the JSON extension: http://pecl.php.net/package/json (which is now used in PHP5)
You can also use JSON libs written in PHP such as:
http://pear.php.net/pepr/pepr-proposal-show.php?id=198
Here is a comparison:
http://gggeek.altervista.org/sw/article_20061113.html

You could also use regex to parse the JSON response.

A very simple example:

<?php

$text = 'hello world';
$response = file_get_contents('http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q='.urlencode($text).'&langpair=en|it';

if (preg_match("/{\"translatedText\":\"(.*?)\"}/i", $response, $matches)) {
$text = $matches[1];
} else {
// error occurred
}

?>
digital-ether
Nearly a Posting Virtuoso
Moderator
1,293 posts since Sep 2005
Reputation Points: 461
Solved Threads: 101
 
Aamit
Posting Whiz
342 posts since Apr 2008
Reputation Points: 3
Solved Threads: 15
 

Thought I'd write a PHP implementation of the Google Language 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);
	}
}


Example use:

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


I've added this to the snippets section: http://www.daniweb.com/code/showsnippet.php?codeid=1069

digital-ether
Nearly a Posting Virtuoso
Moderator
1,293 posts since Sep 2005
Reputation Points: 461
Solved Threads: 101
 

hi,digital-ether
I want to do like this
http://demo.oscommerce.com/index.php

In this at right column there are languages ...
If click on image change language of whole page....

i already post my code for to images with translated link...in post no 6

when click for English language link is
http://demo.oscommerce.com/index.php?language=en

it converts that to selected language and rewrite to
suppose..
For Deutsch
http://demo.oscommerce.com/index.php?language=de


How to do like this??

Aamit
Posting Whiz
342 posts since Apr 2008
Reputation Points: 3
Solved Threads: 15
 
Aamit
Posting Whiz
342 posts since Apr 2008
Reputation Points: 3
Solved Threads: 15
 

hi,digital-ether I want to do like this http://demo.oscommerce.com/index.php

In this at right column there are languages ... If click on image change language of whole page....

i already post my code for to images with translated link...in post no 6

when click for English language link is http://demo.oscommerce.com/index.php?language=en

it converts that to selected language and rewrite to suppose.. For Deutsch http://demo.oscommerce.com/index.php?language=de

How to do like this??

With the google api you'll need to translate pieces of text from your site. You can't really translate the whole page at once.

If the content of your site is taken from a database, you can translate the content from the database before display.
It may even be good to save the translation locally.

OSCommerce works exactly in this way, but manually. There are multiple translations of their content in the database. Even menu items have different translations.

This is similar to how the Joomla CMS, Drupal CMS, etc. handle translations also, but like OSCommerce they are manual translations.

So if you have the code that retrieves the contents for your website, you can just plug in the code to translate that content there, depending on the chosen language.

digital-ether
Nearly a Posting Virtuoso
Moderator
1,293 posts since Sep 2005
Reputation Points: 461
Solved Threads: 101
 

In my page there is no data coming from database...

http://translate.google.com/translate_t?hl=en#

you can directly enter Url In Text or web tab

web page url=http://www.daniweb.com/forums/thread168756-2.html
It translates whole page....
And in Url shows link like...

http://translate.google.com/translate?prev=_t&hl=en&ie=UTF-8&u=http%3A%2F%2Fwww.daniweb.com%2Fforums%2Fthread168756-2.html&sl=en&tl=nl&history_state0=

Aamit
Posting Whiz
342 posts since Apr 2008
Reputation Points: 3
Solved Threads: 15
 

In my page there is no data coming from database...

http://translate.google.com/translate_t?hl=en#

you can directly enter Url In Text or web tab

web page url=http://www.daniweb.com/forums/thread168756-2.html It translates whole page.... And in Url shows link like...

http://translate.google.com/translate?prev=_t&hl=en&ie=UTF-8&u=http%3A%2F%2Fwww.daniweb.com%2Fforums%2Fthread168756-2.html&sl=en&tl=nl&history_state0=

Then the method suggested earlier with babelfish would probably be a better solution for you.

The other obvious option would be to manually do translations and same them as separate pages.

digital-ether
Nearly a Posting Virtuoso
Moderator
1,293 posts since Sep 2005
Reputation Points: 461
Solved Threads: 101
 
Aamit
Posting Whiz
342 posts since Apr 2008
Reputation Points: 3
Solved Threads: 15
 

Hi Sir,
i am also going to work with Language Translator...
i too dont have any idea..
the above solutions...i didnt get it..

plz help me...from starting

sarithak
Junior Poster
183 posts since Aug 2008
Reputation Points: 10
Solved Threads: 7
 
Aamit
Posting Whiz
342 posts since Apr 2008
Reputation Points: 3
Solved Threads: 15
 

http://www.blog.highub.com/apache/http-server/google-text-translation-using-htaccess/

That is a very clever solution you have linked too.

Designing a set of rewrite rules would depend entirely on how your urls are structured, and how standardized they are. The more uniform they are the easier it will be do setup.

Can you provide an example(s) of the urls your site is currently using?

mschroeder
Work Harder
Team Colleague
666 posts since Jul 2008
Reputation Points: 279
Solved Threads: 131
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You