Finally, i've got it with POST, so no any chunks anymore.
$input = 'text to translate';
$post_data = array('v' => '1.0', 'langpair' => '.$source_lang.'|'.
$target_lang, 'q' => $input);
$url = "http://ajax.googleapis.com/ajax/services/language/translate";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_REFERER, "your website name");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
$body = curl_exec($ch);
curl_close($ch);
Big thanx to Jeremy as to my guiding star!
On Oct 13, 1:27 pm, Jeremy Geerdes <[email protected]> wrote:
> You can find documentation on the curl_setopt command here:
>
> http://www.php.net/manual/en/function.curl-setopt.php
>
> Jeremy R. Geerdes
> Effective website design & development
> Des Moines, IA
>
> For more information or a project
> quote:http://jgeerdes.home.mchsi.comhttp://jgeerdes.blogspot.comhttp://jgeerdes.wordpress.com
> [email protected]
>
> Unless otherwise noted, any price quotes contained within this
> communication are given in US dollars.
>
> If you're in the Des Moines, IA, area, check out Debra Heights
> Wesleyan Church!
>
> And check out my blog, Adventures in Web Development,
> athttp://jgeerdes.blogspot.com
> !
>
> On Oct 13, 2009, at 4:21 AM, Contrasso wrote:
>
>
>
> > Thanx Jeremy.
>
> > I'm using PHP and found this much faster than server-client-api-client
> > exchange with JS.
> > The only thing is i didn't found anything about POST method using with
> > PHP in the documentation. "Other" section for flash and php takes
> > smallest part of whole doc. Will try to search more thoroughly.
> > Just one request instead of N GET chunks should be even faster + less
> > google server load.
>
> > Will be grateful if you can give me direction on finding info about
> > POST.
>
> > Again thanx for your reply.
>
> > On Oct 12, 7:45 pm, Jeremy Geerdes <[email protected]> wrote:
> >> Depending on how you use the Language API, you could be right on.
> >> Technically speaking, there is a 5,000-character limit on the
> >> urlencoded string you can translate. But to utilize that full 5,000
> >> characters, you have to submit the request via the POST method. In
> >> other words, you can't use the JS side of the API. If you're wanting
> >> to roll the translations client-side, the limit is a bit tougher to
> >> nail down, but 256 symbols should be good. In most cases, they should
> >> urlencode out to 1,000 or fewer characters, which is about as many as
> >> you want. The trick in both cases is that you'll want to split the
> >> string by character length, but also by syntax. In other words, you
> >> want to keep sentences and clauses together because the machine
> >> translation matrix on the backend works significantly better with a
> >> complete thought than with just pieces.
>
> >> Jeremy R. Geerdes
> >> Effective website design & development
> >> Des Moines, IA
>
> >> For more information or a project quote:http://jgeerdes.home.mchsi.comhttp
> >> ://jgeerdes.blogspot.comhttp://jgeerdes.wordpress.com
> >> [email protected]
>
> >> Unless otherwise noted, any price quotes contained within this
> >> communication are given in US dollars.
>
> >> If you're in the Des Moines, IA, area, check out Debra Heights
> >> Wesleyan Church!
>
> >> And check out my blog, Adventures in Web Development,
> >> athttp://jgeerdes.blogspot.com
> >> !
>
> >> On Oct 12, 2009, at 11:08 AM, Contrasso wrote:
>
> >>> Hi, i've just made website multilanguage version using translate api
> >>> and php.
>
> >>> Next i thought that it could have sence to check service
> >>> availability
> >>> each time user opens my website and IF NOT AVAILABLE hide language
> >>> switch feature from a page.
>
> >>> Q1: is there is way to check language API availability?
>
> >>> 2nd thing is string length. I didn't found info about limitation in
> >>> the documentation, though this is more HTML thing than API's.
> >>> Nayways,
> >>> intuitively i splitted string into smaller chains.
>
> >>> Q2: Is that optimal way to split string into chunks of 256 symbols
> >>> and
> >>> call api for each chunk?
>
> >>> Thanx for replies.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google AJAX APIs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/google-ajax-search-api?hl=en
-~----------~----~----~----~------~----~------~--~---