Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
This plugin MooTools works with the Google Language API and can be used to translate a text in all the languages provided by the API.
PHP JavaScript
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
PHP/google-translate
Source
demos
docs
README.md
package.yml

README.md

GoogleLanguage

This plugin works with the Google Language API and can be used to translate a text in all the languages provided by the API.

Screenshot

How to use

First you must to include the JS files in the head of your HTML document.

    #HTML
    <script type="text/javascript" src="mootools-core.js"></script>
    <script type="text/javascript" src="GoogleLanguage.js"></script>

In your JS.

    #JS
    window.addEvent('domready', function(){
      //source language text
      var from = "en", 
      //target language    
          to = "fr", 
      //grab the original text
          text = document.id('input').get('value'),
          //classical usage
          try = new GoogleLanguage({text: text,from: from, to: to, 
                  onRequest: function() {
                      //do something here while loading
                  },
                  onSuccess: function(resp) {
                      //put the translated text where you want.
                      document.id('results').set('text', resp);
                  }
          });
          document.id('trans').addEvent('click', function(){
                  try.translate();
          });

          //you can use setting up the element with setter and getter as below
          $('text1').set('translate',{from: 'ro',
                                      to:'en',
                                      onRequest: function(){ 
                                          //do something onLoading
                                      },
                                      onComplete: function(){ 
                                          //do something when has completed
                                      }
                        });

          $('text1').addEvent('click', function(){
                     $('text1').translate();
          }); 

          $('text2').set('translate',{from: 'ro',
                                      to:'en',
                                      onRequest: function(){ 
                                          //do something onLoading
                                      },
                                      onComplete: function(){ 
                                          //do something when has completed
                                      }
                        });

          $('text2').addEvent('click', function(){
                     $('text2').translate();
          }); 
    });

In your HTML

    #html
    <textarea id="input"></textarea>
    <input type="button" id="trans" />   
    <div id="results"></div> 
    <div id="text1"></div>
    <div id="text2"></div>

Notes:

You can view in action:

Something went wrong with that request. Please try again.