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??
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??
<a href='http://babelfish.yahoo.com/translate_url?doit=done&tt=url&intl=1&fr=bf-home[B]&lp=en_fr[/B]&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çais</font></a>
<a href='http://babelfish.yahoo.com/translate_url?doit=done&tt=url&intl=1&fr=bf-home[B]&lp=en_es[/B]&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ñol</font></a>
for a html select
each <option> would be coded the same as <A> above, changing the language pair &lp= and of course altering the title prompt
most people use a translator
I want to translate whole page..text ...not redirect page to translator...
I want to translate whole page..text ...not redirect page to translator...
You dont already have a frame breaker in your <head> ?
<script language='Javascript' type='text/javascript'>
<!--
if (top.location != self.location) { top.location = self.location.href }
//-->
</script>
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??
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&langpair=en%7Cfr&&u=<? echo $URL;?>">
<img src=
"images/frenchflag.jpg" alt=
"Franç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&langpair=en%7Cde&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&langpair=en%7Cit&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&langpair=en%7Cnl&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&langpair=en%7Ces&u=<? echo $URL;?>">
<img style="border: 0px solid ; width: 20px; height: 10px;" alt=
"Español/Spanish" src=
"images/spanishflag.jpg"></a></td>
<td><a href=
"http://72.14.235.100/translate_c?hl=en&langpair=en%7Cpt&u=<? echo $URL;?>">
<img style="border: 0px solid ; width: 20px; height: 10px;" alt=
"Português/Portuguese" src=
"images/portugeseglag.jpg"></a></td>
</tr><tr>
<td><a href=
"http://72.14.235.100/translate_c?hl=en&langpair=en%7Cko&u=<? echo $URL;?>">
<img style="border: 0px solid ; width: 20px; height: 10px;" alt=
"한국어/Korean"
src="images/koreanflag.jpg"></a></td>
<td><a href=
"http://72.14.235.100/translate_c?hl=en&langpair=en%7Czh-CN&u=<? echo $URL;?>">
<img style="border: 0px solid ; width: 20px; height: 10px;" alt=
"中文(简体)/Chinese Simplified"
src="images/chineseflag.jpg"></a></td>
<td><a href=
"http://72.14.235.100/translate_c?hl=en&langpair=en%7Cja&u=<? echo $URL;?>">
<img style="border: 0px solid ; width: 20px; height: 10px;" alt=
"日本語/Japanese"
src="images/japanflag.jpg"></a></td>
<td><a href=
"http://72.14.235.100/translate_c?hl=en&langpair=en%7Cel&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&langpair=en%7Car&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&langpair=en%7Cru&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
How to rewrite url or solve this??
How to do this??
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 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
Hi almostbob,
can you explain this
with the greves & cedillas carets etc ??
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
}
?>
After convert language
Url is:- http://72.14.235.100/translate_c?hl=en&langpair=en|fr&u=http://www.xyx.com/&usg=ALkJrhgoRPxFWQuYskMr6qlwsRRh7r9jOg
How to rewrite url to
Url:- http://www.xyx.com
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
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??
hi,digital-ether
I want to do like this
http://demo.oscommerce.com/index.phpIn 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=enit 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.
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...
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...
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.
But My problem is when translate from one to another language...
It shows link...
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=
How to rewrite this to ....
http://www.daniweb.com/forums/thread168756-2.html
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
Hi,
Link for rewrite url
http://www.blog.highub.com/apache/http-server/google-text-translation-using-htaccess/
http://perishablepress.com/press/2006/12/18/automatic-language-translation-methods/
So
After convert language
Url is:- 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=
How to rewrite url to
Url:- http://www.daniweb.com/forums/thread168756-2.html
Please help me to rewrite url
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?
I answered a simular question on phpfreaks.com about embedding the google translator into your website and the script I came up with is as follows:
<?php
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") ); // request as if Firefox
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];
}
//now to use the translate function
echo translate('This is the text','en','iw');
?>
And of course another option is you can also convert the ajax function to a php function like the member Daniel0 on phpfreaks did and is as follows:
<?php
function translate($textSource, $langSource, $langTarget)
{
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_URL => 'http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=' . urlencode($textSource) . '&langpair=' . urlencode($langSource . '|' . $langTarget),
CURLOPT_RETURNTRANSFER => true
));
$ret = json_decode(curl_exec($ch), true);
curl_close($ch);
if ($ret['responseStatus'] != '200') {
throw Exception('Translation failed.');
}
return $ret['responseData']['translatedText'];
}
echo translate('this is the text', 'es', 'en');
?>
Also to help understand how to use the functions above (both scripts are used the same way) is by entering the text to be translated in the first field. The language from in the second field. And the language to in the third field. REMEMBER: Languages inputed into the second and third field must be abbreviated and the abbreviations 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 translate the entire page, perhaps you can submit through the translator script every string you have on the page. Hope that helps.
hi, cwarn23
( Also to help understand how to use the functions above (both scripts are used the same way) is by entering the text to be translated in the first field. The language from in the second field. And the language to in the third field. REMEMBER: Languages inputed into the second and third field must be abbreviated )
Please post the form related to this??
hi, cwarn23
( Also to help understand how to use the functions above (both scripts are used the same way) is by entering the text to be translated in the first field. The language from in the second field. And the language to in the third field. REMEMBER: Languages inputed into the second and third field must be abbreviated )Please post the form related to this??
Please post the form related to this??
Please post the form related to this??
I shall post a page with the translator fully embeded and you can select from the menu what language you want. However this requires a $_GET variable in the url bar when not viewing english pages. The only other alternative to not having the $_GET variable in the url bar is to use sessions. Anyway below is a fully setup example that you can use.
<?php
function translate($textSource, $langSource, $langTarget='')
{
$textSource=explode('<>',$textSource);
if ($langTarget=='') {$langTarget='en';}
$idz=0;
while (isset($textSource[$idz]))
{
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_URL => 'http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=' . urlencode($textSource[$idz]) . '&langpair=' . urlencode($langSource . '|' . $langTarget),
CURLOPT_RETURNTRANSFER => true
));
$ret = json_decode(curl_exec($ch), true);
curl_close($ch);
$endresult.=$ret['responseData']['translatedText'];
$idz+=2;
}
return $endresult;
}
echo "<form method='get' style='padding:0px; margin:0px;'>
<select name='language'>
<option value='ar'>Arabic
<option value='bg'>Bulgarian
<option value='ca'>Catalan
<option value='zh-CN'>Chinese
<option value='hr'>Croatian
<option value='cs'>Czech
<option value='da'>Danish
<option value='nl'>Dutch
<option value='en'>English
<option value='tl'>Filipino
<option value='fr'>French
<option value='de'>German
<option value='el'>Greek
<option value='iw'>Hebrew
<option value='hi'>Hindi
<option value='id'>Indonesian
<option value='it'>Italian
<option value='ja'>Japanese
<option value='ko'>Korean
<option value='lv'>Latvian
<option value='lt'>Lithuanian
<option value='no'>Norwegian
<option value='pl'>Polish
<option value='pt'>Portuguese
<option value='ro'>Romanian
<option value='ru'>Russian
<option value='sr'>Serbian
<option value='sk'>Slovak
<option value='sl'>Slovenian
<option value='es'>Spanish
<option value='sv'>Swedish
<option value='uk'>Ukrainian
<option value='vi'>Vietnamese
</select><input type='submit' value='submit'></form>";
//now to use the translate function
echo translate("<font face='arial'><b>This is the text.</b>
You may place all your html in here and it will translate the text and not the code.
<br>But note that whenever you use a quote example:\" You will need a backslash before it but
that is only for the type of quote which surrounds this entire translation.</font>",'en',$_GET['language']);
?>
Just let me know if you would like more changed.
hi, cwarn23...
Sorry for late replay
In your post no--24
echo translate("<font face='arial'><b>This is the text.</b>
You may place all your html in here and it will translate the text and not the code.
<br>But note that whenever you use a quote example:\" You will need a backslash before it but
that is only for the type of quote which surrounds this entire translation.</font>",'en',$_GET['language']);
Please give me example how to place html or php file translate text??
<?
$file=$_GET['page'];
echo translate(file_get_contents($file),'en',$_GET['language']);
?>
To make life easier, I have made an example of another way to use the function so that you can include an external php (or html) file to include the contents instead of having to worry about escaping the quotes. So basically, you have one or more page(s) that contains just that function and nothing else. Then when linking to another page, just link to index.php?page=newpage.php to load the the page named newpage.php in the same directory. And that may seem ugly so you can then use a htaccess file the rewrite the url to something more pritty like /newpage/.
So basically, the example above acts like the include() function which will translate while including. That will give you something to fiddle with. Hope it helps solve the puzzle.
Edit: You will need the full fuction code in index.php or whatever page the above example which was provided earlier.
Hi,
my file is at C:\xampp\htdocs\translator\xyz.php
I putting all code ...here
please tell me what is wrong in this code......
i am not getting correct output.
not changing body text also....
<?php
function translate($textSource, $langSource, $langTarget='')
{
$textSource=explode('<>',$textSource);
if ($langTarget=='') {$langTarget='en';}
$idz=0;
while (isset($textSource[$idz]))
{
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_URL => 'http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=' . urlencode($textSource[$idz]) . '&langpair=' . urlencode($langSource . '|' . $langTarget),
CURLOPT_RETURNTRANSFER => true
));
$ret = json_decode(curl_exec($ch), true);
curl_close($ch);
$endresult.=$ret['responseData']['translatedText'];
$idz+=2;
}
return $endresult;
}
echo "<form method='get' style='padding:0px; margin:0px;'>
<select name='language'>
<option value='ar'>Arabic
<option value='bg'>Bulgarian
<option value='ca'>Catalan
<option value='zh-CN'>Chinese
<option value='hr'>Croatian
<option value='cs'>Czech
<option value='da'>Danish
<option value='nl'>Dutch
<option value='en'>English
<option value='tl'>Filipino
<option value='fr'>French
<option value='de'>German
<option value='el'>Greek
<option value='iw'>Hebrew
<option value='hi'>Hindi
<option value='id'>Indonesian
<option value='it'>Italian
<option value='ja'>Japanese
<option value='ko'>Korean
<option value='lv'>Latvian
<option value='lt'>Lithuanian
<option value='no'>Norwegian
<option value='pl'>Polish
<option value='pt'>Portuguese
<option value='ro'>Romanian
<option value='ru'>Russian
<option value='sr'>Serbian
<option value='sk'>Slovak
<option value='sl'>Slovenian
<option value='es'>Spanish
<option value='sv'>Swedish
<option value='uk'>Ukrainian
<option value='vi'>Vietnamese
</select><input type='submit' value='submit'></form>";
//now to use the translate function
/* $url=$_SERVER['PHP_SELF'];
$uu=$_SERVER['REQUEST_URI'];
$urls .= $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']);*/
echo $url = $_SERVER['REQUEST_URI'] ;
$urls = preg_split('/\?/', $url);
echo print_r($urls);
echo $url = $urls[0];
//echo '$_SERVER[PHP_SELF]: ' . $_SERVER['PHP_SELF'] . '<br />';
$url1="C:\\xampp\htdocstranslator/xyz.php";
//echo 'Dirname($_SERVER[PHP_SELF]: ' . dirname($_SERVER['PHP_SELF']) . '<br>';
echo $p_file = dirname(__FILE__)."$url";
/* echo translate(file_get_contents($url1),'en',$_GET['language']); */
echo translate("<font face='arial'><b>This is the text.</b>
You may place all your html in here and it will translate the text and not the code.
<br>But note that whenever you use a quote example:\" You will need a backslash before it but
that is only for the type of quote which surrounds this entire translation.\
</font>",'en',$_GET['language']);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
</head>
<body>
<div align="left" style="color:gray; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:10px; text-align:justify" >
<span class="bluenormal"> Formally, DFS is an uninformed search that progresses by expanding the first child node of the search tree that appears and thus going deeper and deeper until a goal node is found, or until it hits a node that has no children. Then the search backtracks, returning to the most recent node it hadn't finished exploring. In a non-recursive implementation, all freshly expanded nodes are added to a LIFO stack for exploration. </span><br/><br/>
</div>
</body>
</html>
hi,
I posted code in post in-28
please tell me what is wrong in this code......
i am not getting correct output.
not changing body text also....
I had a try at embeding it in myself and descovered a few bugs but have now fixed them. Also I discovered that for the translator, it can take one or two minutes to translate the entire page. The more html the longer to translate. So there are the following two pages and they must have the names I gave them unless you can alter the code to change their names but the only page visible in the url bar is index.php. To set the up, first place in index.php the following code:
<?
set_time_limit(0);
function translate($textSource, $langSource, $langTarget='')
{
if ($langTarget=='') {$langTarget='en';}
if ($langSource!==$langTarget)
{
$textSource=preg_split('/(<|>)/',$textSource);
$idz=0;
$openbracket=1;
while (isset($textSource[$idz]))
{
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_URL => 'http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=' . urlencode($textSource[$idz]) . '&langpair=' . urlencode($langSource . '|' . $langTarget),
CURLOPT_RETURNTRANSFER => true
));
$ret = json_decode(curl_exec($ch), true);
curl_close($ch);
if ($openbracket==1)
{
$bracket='<';
$openbracket=0;
$endresult.=$ret['responseData']['translatedText'].$bracket;
} else {
$bracket='>';
$openbracket=1;
$endresult.=$textSource[$idz].$bracket;
}
$idz+=1;
}
$endresult=preg_replace('/(.*)\</','$1',$endresult);
return $endresult;
} else {
return $textSource;
}
}
if (!isset($_GET['page']))
{
$file='default.php';
} else {
$file=$_GET['page'];
}
$data=file_get_contents('http://'.preg_replace('/(.*)\/[^\/]+/','$1/',$_SERVER['SERVER_NAME'].$_SERVER['PHP_SELF']).$file);
echo translate($data,'en',$_GET['language']);
?>
Then in the same directory as index.php place in default.php the following code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
</head>
<body>
<form method='get' style='padding:0px; margin:0px;' action='index.php'>
<select name='language'>
<option value='ar'>Arabic
<option value='bg'>Bulgarian
<option value='ca'>Catalan
<option value='zh-CN'>Chinese
<option value='hr'>Croatian
<option value='cs'>Czech
<option value='da'>Danish
<option value='nl'>Dutch
<option value='en'>English
<option value='tl'>Filipino
<option value='fr'>French
<option value='de'>German
<option value='el'>Greek
<option value='iw'>Hebrew
<option value='hi'>Hindi
<option value='id'>Indonesian
<option value='it'>Italian
<option value='ja'>Japanese
<option value='ko'>Korean
<option value='lv'>Latvian
<option value='lt'>Lithuanian
<option value='no'>Norwegian
<option value='pl'>Polish
<option value='pt'>Portuguese
<option value='ro'>Romanian
<option value='ru'>Russian
<option value='sr'>Serbian
<option value='sk'>Slovak
<option value='sl'>Slovenian
<option value='es'>Spanish
<option value='sv'>Swedish
<option value='uk'>Ukrainian
<option value='vi'>Vietnamese
</select><input type='submit' value='submit'><input type=hidden value='<? echo basename($_SERVER['REQUEST_URI']); ?>' name='page'></form><br>
<div align="left" style="color:gray; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:10px; text-align:justify" >
<span class="bluenormal"> Formally, DFS is an uninformed search that progresses by expanding the first child node of the search tree that appears and thus going deeper and deeper until a goal node is found, or until it hits a node that has no children. Then the search backtracks, returning to the most recent node it hadn't finished exploring. In a non-recursive implementation, all freshly expanded nodes are added to a LIFO stack for exploration. </span><br/><br/>
</div>
</body>
</html>
Also when creating links, just link to the page like index.php?page=pagename.php
That will link to a page within the same directory or for a page in a subdirectory the url will be index.php?page=directoryname/pagename.php
Note: You can also use html files
Hope that helps.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.