balazs-endresz / jquery-translate

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

cannot make it work #2

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I'm successfully using google.translate but have problem with 500+ texts on
www.vocape.com (even some shorter texts claims they are 500+, may be html)

I tried to adapt the drupal module js to use your great plugin but I'm not
good enough at js.
May be it's very simple and obvious for you?
If you find and can fix here's the js:

if (Drupal.jsEnabled) {
  $(document).ready(function(){

    var link = $("<a />")
      .attr("href", "#")
      .css({ border:"1px solid #555", padding:"1px 0.8em", margin:"1px",
font:"#dff", float:"right", fontSize:"1em", textDecoration:"none" });
    var wrapper = $("<span></span>").css({ float:"right" });
    var languages = ["it", "ja", "nl", "pt", "fr", "de", "es", "en"];

    $(".node .content").each(function (i) {    
      var w = $(wrapper).clone().insertBefore(this);

      jQuery.each(languages, function(x){
        w.append(link.clone().html(languages[x]).click(function () {
          var n = $(this).parent().next();
          google.language.translate(n.html(), "", languages[x],
function(result) {
            if (!result.error) {
              n.html(result.translation);
            } else alert(result.error.message);
          });
          this.blur();
          return false;
        }));
      });
    });
  });
}

Original issue reported on code.google.com by philouma...@gmail.com on 20 Sep 2008 at 12:49

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
After you included the plugin instead of the google.language.translate function 
use this:

n.translate(languages[x], { //here you can set some options:
  async: true, //good when there are many nodes
  error: function(error){ alert(error.message); }
})

This should do it, however, it didn't work for me on your site as you are using
jQuery 1.0.4, which is not really supported. Try it with jQuery 1.2.x!
Btw, if using the plugin you don't have to load http://www.google.com/jsapi nor
google.load("language", "1"); they are loaded automatically.

Original comment by balazs.endresz on 20 Sep 2008 at 3:05

GoogleCodeExporter commented 9 years ago
Feel free to ask if you haven't succeeded yet!

Original comment by balazs.endresz on 7 Oct 2008 at 8:47

GoogleCodeExporter commented 9 years ago

Original comment by balazs.endresz on 3 Nov 2008 at 4:31