File: sample.html

Recommend this page to a friend!
  Classes of Juraj Puchký  >  jsgtv2c  >  sample.html  >  Download  
File: sample.html
Role: Example script
Content type: text/plain
Description: Class file
Class: jsgtv2c
Translate texts using Google Translate API
Author: By
Last change: Fixed sample
Date: 9 years ago
Size: 4,337 bytes
 

Contents

Class file image Download
<!--
 Java Script Google Translate V2 API Client
 @Description Google Translate V2 API Client
 @File sample.html
 @Autor Juraj Puchký - Devtech <sjurajpuchky@seznam.cz>
 @Home http://www.devtech.cz
 @SVN  svn checkout svn://svn.code.sf.net/p/jsgtv2c/code/trunk jsgtv2c-code
 @Donation 5$ over there -> https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=H2T85LJ5L9XVL  then i can give more time to improove code.
 @Version 1.0.0
 @Created 9.10.2012
 @Licence GPLv3 or later
-->
<!DOCTYPE html>
<html>
    <head>
        <title>Sample of usage Google Translate V2 API Client Jsgtv2c</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <script type="text/javascript" src="jshttpclient.js"></script>
        <script type="text/javascript" src="jsgtv2c.js"></script>
        <script type="text/javascript">
            var apiKey = '<!-- Enter YOUR Google API-Key from https://code.google.com/apis/console -->'; // enter your API-key
            var supportedLanguages = new Jsgtv2cSupportedLanguages(apiKey);
            var detect = new Jsgtv2cDetect(apiKey);
            var translate = new Jsgtv2cTranslate(apiKey);

            /**
  * 
  */
            function CustomGoogleTranslateHandler() {
                this.onSupportedLanguagesChanged = function(client) {
                    e = document.getElementById("languages");
                    languages = client.getSupportedLanguages();
                    for (var lang in languages) {
                        e.innerHTML += languages[lang].name + "<br>";
                    }
                };

                this.onDetectedLanguagesChanged = function(client) {
                    e = document.getElementById("detection");
                    detections = client.getDetectedLanguages();
                    for (var detc in detections) {
                        for (var d in detections[detc]) {
                            e.innerHTML += detections[detc][d].language + "<br>";
                        }
                    }
                };

                this.onTranslatedTextChanged = function(client) {
                    e = document.getElementById("translate");
                    translation = client.getTranslatedText();
                    e.innerHTML = translation;
                };
            }

            function init() {
                supportedLanguages.customGoogleTranslateApiHandler = new CustomGoogleTranslateHandler();
                supportedLanguages.setTargetLanguage("en");
                supportedLanguages.doCalculateOfSupportedLanguages();
                detect.customGoogleTranslateApiHandler = new CustomGoogleTranslateHandler();
                detect.setText("Hello world");
                detect.doDetection();
                translate.customGoogleTranslateApiHandler = new CustomGoogleTranslateHandler();
                translate.setSourceLanguage("en");
                translate.setTargetLanguage("cs");
                translate.setText("Hello");
                translate.doTranslate();
            }
        </script>              
    </head>
    <body onload="init();">
        <H1>Sample of usage Google Translate V2 API Client Jsgtv2c</H1>
        Distributed under GPLv3 licence any time you wish you can donate only 5$ to this project, then i can give more time to improove the code.

        Any questions or needs, just ask me.

        <form action="https://www.paypal.com/cgi-bin/webscr" method="post">
            <input type="hidden" name="cmd" value="_s-xclick">
            <input type="hidden" name="hosted_button_id" value="H2T85LJ5L9XVL">
            <input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
            <img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
        </form>       
        <H2>Supported languages</H2>    
        <div id="languages">
        </div>          
        <H2>Language detection</H2>    
        <div id="detection">
        </div>    
        <H2>Translation</H2>    
        <div id="translate">
        </div>               
    </body>
</html>