Request.DetectLanguage v1.0

This class allows you to detect the language of blocks of text within a webpage. It uses Google AJAX Language API for Detection.



Details

Author
Adrian Statescu
Current version
v1.0
GitHub
thinkphp/mooDetectLanguage
Downloads
1661
Category
Utilities
Tags
Report
GitHub Issues

Releases


Dependencies

  • core/1.3: *

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.js"></script>
        <script type="text/javascript" src="DetectLanguage.js"></script>

In your JS:

       #JS
       window.addEvent('domready',function(){                  
              var d = new Request.DetectLanguage({
                      url: 'detect.php',
                      onSuccess: function(resp, origresp) {
                            if(window.console){console.log(origresp)} 
                            var resp = resp[0],
                                result = document.id('result'),
                                output = '<div><b>Language:</b> '+ resp.l + 
                                         ', <b>isReliable:</b> '+ resp.r +
                                         ', <b>confidence:</b> '+ resp.c; 
                            result.fade('hide');
                            result.fade(1);
                            result.set('html',output);                                 
                      } 
              });
              d.detect(document.id('input_text').get('value'));
              $('detect').addEvent('click',function(){
                       var val = document.id('input_text').get('value');
                       if(val){
                         d.detect(val);
                       }
              });
       }); 

In your body HTML:

 #HTML 
 <textarea rows="10" cols="105" id="input_text">Mootools est un framework Javascript compact, modulaire, oriente objet.</textarea>
 <br/>
 <input type="button" id="detect" value="detect"> 
 <div id="result"></div>

Discuss

A note on comments here: These comments are moderated. No comments will show up until they are approved. Comments that are not productive (i.e. inflammatory, rude, etc) will not be approved.

Found a bug in this plugin? Please report it this repository's Github Issues.

blog comments powered by Disqus