balazs-endresz / jquery-translate

Automatically exported from code.google.com/p/jquery-translate
5 stars 5 forks source link

support for Google v2 API #76

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Already implemented, I'll commit it soon.

Original issue reported on code.google.com by balazs.endresz on 6 Nov 2011 at 4:21

GoogleCodeExporter commented 9 years ago
When will this be committed?

Original comment by sofia.chiang on 9 Nov 2011 at 10:59

GoogleCodeExporter commented 9 years ago
In the weekend probably, unless I'll be moving to the new house then. Or if I 
don't have to spend a day persuading Windows to log in instead of showing a 
blank screen with a mouse pointer like last weekend.

Original comment by balazs.endresz on 9 Nov 2011 at 12:41

GoogleCodeExporter commented 9 years ago
Then I hope you will make it this weekend.

Original comment by sofia.chiang on 11 Nov 2011 at 12:08

GoogleCodeExporter commented 9 years ago
Hello!

Thanks a lot for your effort with v2 API.

We will be very grateful if  you can make the commit this weekend. ;)

Best regards,
Frankai

Original comment by frank...@gmail.com on 12 Nov 2011 at 6:12

GoogleCodeExporter commented 9 years ago
You can give it a try now, it hasn't been tested much at all so any feedback is 
welcome.

Original comment by balazs.endresz on 13 Nov 2011 at 5:56

GoogleCodeExporter commented 9 years ago
Im not really sure how to invoke version 2:

I am trying this:

 $.translate.load('09389083jhih3839hihi3h8-A', "2");

And I get:

Uncaught Error: Module: 'language' with version: '2' not found!
(anonymous function)

09389083jhih3839hihi3h8-A is of course not my API-key

I

Original comment by axelsson...@gmail.com on 14 Nov 2011 at 3:07

GoogleCodeExporter commented 9 years ago
I'd say check the request in the network tab in the dev tools first, or if you 
don't mind you can send your API key by email as well to 
balazs.endresz@gmail.com.

Original comment by balazs.endresz on 14 Nov 2011 at 3:31

GoogleCodeExporter commented 9 years ago
One thing that needs to be fixed up is the API request currently expects a 
successful response, but a "success" may contain an error response.

In this section, the action response does not necessarily have data, but may 
have an error. In fact, it always has for me to this point :-)

In var tr = response.data.translations[0].translatedText

there is no "data", just "errors"

    $.ajax({
                url:  "https://www.googleapis.com/language/translate/v2",
                dataType: "jsonp",
                jsonp: "callback",
                crossDomain: true,
                context: this,
                data: {"key": key, source: this.from, target: this.to, q: src},
                success: function(response){
                    var tr = response.data.translations[0].translatedText
                    this.queue[i] = tr || this.rawSourceSub;
                    //this.detectedSourceLanguage = result.detectedSourceLanguage;
                    this._check();
                }

Original comment by ra...@randyfay.com on 15 Nov 2011 at 3:39

GoogleCodeExporter commented 9 years ago
I'll fix the error handling tonight.

Original comment by balazs.endresz on 15 Nov 2011 at 7:54

GoogleCodeExporter commented 9 years ago
@ra...@randyfay.com: That should be fixed now.

Original comment by balazs.endresz on 15 Nov 2011 at 9:10

GoogleCodeExporter commented 9 years ago
Hi,

You can discard my previous post. I was using release 1.4.7 not the trunk.

So to my new issue. I ve downloaded trunk ( 
http://jquery-translate.googlecode.com/svn/trunk/jquery.translate-debug-all.js 
revision: 247 ). At line 661 to 690 the code is out commented and the version 
argument is never used in "load". 

This is not right is it?

BR
paera

Original comment by axelsson...@gmail.com on 17 Nov 2011 at 2:56

GoogleCodeExporter commented 9 years ago
That's because recently I've removed support for the Google v1 API, and now the 
version number is unnecessary. I'll clean these things up when there aren't any 
issues with the new APIs.

Original comment by balazs.endresz on 17 Nov 2011 at 5:02

GoogleCodeExporter commented 9 years ago
Thanks again for all your work on this.

Currently, if you call _translate without a this.from (if fromOriginal:true), 
it formats the REST request with &source=&, which is a failure for the Google 
API. To use the detected source language you have to leave out the &source 
argument.

So right now, if you leave the from language empty, this request is generated:

https://www.googleapis.com/language/translate/v2?callback=jsonp1322241205714&_=1
322241210290&key=XXXXXXBwT3hoRXWU1UkYIBK5Mm_tdpdRbXXXXXX&source=&target=es&q=Thi
s%20is%20a%20test

and it's invalid. It gets a response of:

// API callback
jsonp1322241205714({
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "invalid",
    "message": "Invalid Value"
   }
  ],
  "code": 400,
  "message": "Invalid Value"
 }
}
);

However, if you just change this to 

https://www.googleapis.com/language/translate/v2?callback=jsonp1322241205714&_=1
322241210290&key=XXXXXXBwT3hoRXWU1UkYIBK5Mm_tdpdRbXXXXXX&target=es&q=This%20is%2
0a%20test

it works perfectly (removing the source=)

Original comment by ra...@randyfay.com on 25 Nov 2011 at 5:20

GoogleCodeExporter commented 9 years ago
Nice catch! Fixed at r248.

Original comment by balazs.endresz on 26 Nov 2011 at 11:04

GoogleCodeExporter commented 9 years ago
The interaction with the google api is now working, THANKS!.

The next problem is that in the code below we get

this.queue is undefined
[Break On This Error] this.queue[i] = tr || this.rawSourceSub; 

success: function(response){
if(response.error){
return this.options.error.call(this, response.error, this.rawSourceSub, 
this.from, this.to, this.options);
}
var tr = response.data.translations[0].translatedText
this.queue[i] = tr || this.rawSourceSub; 

Original comment by ra...@randyfay.com on 26 Nov 2011 at 4:24

GoogleCodeExporter commented 9 years ago
That just can't be happening. Could you please send me the page via email or 
somehow?

Original comment by balazs.endresz on 26 Nov 2011 at 4:36

GoogleCodeExporter commented 9 years ago
Sent a firebug screenshot showing the state at the time of the #fail. Thanks.

Original comment by ra...@randyfay.com on 26 Nov 2011 at 5:03

GoogleCodeExporter commented 9 years ago
It seems like the `context` option in $.ajax has no effect in you're case. What 
version of jQuery are you using?

Original comment by balazs.endresz on 26 Nov 2011 at 5:22

GoogleCodeExporter commented 9 years ago
Ah great question. This test was with 1.2.6, which is what this site has always 
used with jquery.translate. If I have to, I can push it up to 1.3.2 using an 
adapter module (jquery_update), but no farther for Drupal 6.

Original comment by ra...@randyfay.com on 26 Nov 2011 at 5:36

GoogleCodeExporter commented 9 years ago
It should work with r249.

Original comment by balazs.endresz on 26 Nov 2011 at 5:43

GoogleCodeExporter commented 9 years ago
And it does! Yay! balazs.endresz++ Thanks so much.

Original comment by ra...@randyfay.com on 26 Nov 2011 at 5:56

GoogleCodeExporter commented 9 years ago
Great! :)

Original comment by balazs.endresz on 26 Nov 2011 at 6:16

GoogleCodeExporter commented 9 years ago
Drupal 6 and Drupal 7 versions of http://drupal.org/project/translatableregions 
are working and checked in! Yay. And the $20/MB that Google charges may not 
bankrupt the site that uses this.

Original comment by ra...@randyfay.com on 26 Nov 2011 at 6:33

GoogleCodeExporter commented 9 years ago
Oh, and I almost forgot that the MS API seems to accept arbitrary long text, 
which makes it actually usable because otherwise it can't always handle HTML 
split into multiple parts: 
http://code.google.com/p/jquery-translate/issues/detail?id=75
So that seems like a good alternative as well. I'll try to work on it tomorrow.

Original comment by balazs.endresz on 26 Nov 2011 at 8:14

GoogleCodeExporter commented 9 years ago
Great - I'll try to test after you do. Unfortunately I *think* Microsoft's 
offerings are less advantageous economically. You pay them by the month as 
opposed to paying Google by the MB. And the entry point after 2000 transactions 
(for MS) is $40/month.

Since you've made all this great progress it would be good to update the main 
page as well.

Original comment by ra...@randyfay.com on 26 Nov 2011 at 11:28