Below is a quick example I used to test with. I am not sure why a cfhttp call
would be treated differently than the php fileGetContent call, but it seems
like it is. Some other examples I have found seemed to show developers using
various screen scrapping methods to get the translated text. I canât believe
Google does not have an API for this.
<cfset selectedLangPair = "en|fr">
<cfset textToTranslate = "Some Simple text">
<cfhttp url="http://google.com/translate_t" method="get"
result="googleTranslatedText" resolveurl="no" throwonerror="yes" >
<cfhttpparam name="langpair" type="formfield"
value="#urlEncodedFormat(selectedLangPair)#">
<cfhttpparam name="text" type="formfield"
value="#urlEncodedFormat(textToTranslate)#">
</cfhttp>
I also found the following example using C, that is supposed to work, but I
have not tried it yet.
Translate your text using Google Api's
Here is how you can translate a Text using Google's "Unofficial" API's.
The URL for Google Translate is -
http://www.google.com/translate_t?hl=en&ie=UTF8&text={0}&langpair={1}
"text" is your input string which needs to be translated.
langpair is the language pairs involved in the tranlsation. E.g. "ar|en" means
translate from Arabic to English.
The result when you browse to the URL is a HTML page. You will have to do
screen scraping to get your translated text.
Below is a C# function which translates, scrapes and gives you the result. I am
using String.Substring function but you can use Regex too.
<summary>
Translate Text using Google Translate API's
Google URL -
http://www.google.com/translate_t?hl=en&ie=UTF8&text={0}&langpair={1}
</summary>
<param name="input">Input string</param>
<param name="languagePair">2 letter Language Pair, delimited by "|".
/// E.g. "ar|en" language pair means to translate from Arabic to English</param>
<returns>Translated to String</returns> --->
public string TranslateText(
string input,
string languagePair)
{
string url =
String.Format("http://www.google.com/translate_t?hl=en&ie=UTF8&text={0}&langpair={1}",
input, languagePair);
WebClient webClient = new WebClient();
webClient.Encoding = System.Text.Encoding.UTF8;
string result = webClient.DownloadString(url);
result = result.Substring(result.IndexOf("id=result_box") + 22,
result.IndexOf("id=result_box") + 500);
result = result.Substring(0, result.IndexOf("</div"));
return result;
}
-----Original Message-----
From: Eric Haskins [mailto:[EMAIL PROTECTED]
Sent: Friday, June 15, 2007 4:28 PM
To: CF-Talk
Subject: Re: Translation WebService
hmmmm 403 I am at the office and dont have my laptop (which has CF on it) I
will whip something up.
Forget the API.js for now and just get the post working to Google. with the
correct fields
$in = @file_get_contents("
http://google.com/translate_t?langpair=".urlencode($lp)."&text=".urlencode($text
));
Is what I use in php
<CFHTTP
url="http://google.com/translate_t<http://google.com/translate_t?langpair=".urlencode($lp)."&text=".urlencode($text>"
method="GET" resolveurl="yes" throwonerror="yes" redirect="yes">
<CFHTTPPARAM type="FORMFIELD" name="langpair" value="en|es"> <!--- English
to Spanish --->
<CFHTTPPARAM type="FORMFIELD" name="text" value="Hello World">
</CFHTTP>
The result should be in CFHTTP.FileContent. Then use a regex to get it out
the Div <div id=result_box dir=ltr>(.*?)</div>
I will test when I get home
Eric Haskins
Web Application Developer
Directnic.com <http://directnic.com/> / Parked.com <http://parked.com/>
Convert your Parked Domains in revenue streams
http://www.parked.com/tour/?promo=455BD4CABB
On 6/15/07, Michael Eger <[EMAIL PROTECTED]> wrote:
>
> I tested a cfhttp approach to retrieve the text, but am getting a 403
> error saying I do not have permission. I do not want to implement a PHP
> solution for this, so I need to find another solution. Any other ideas?
>
>
>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
ColdFusion MX7 and Flex 2
Build sales & marketing dashboard RIAâs for your business. Upgrade now
http://www.adobe.com/products/coldfusion/flex2?sdid=RVJT
Archive:
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:281335
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4