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


Class file image Download
 Java Script Google Translate V2 API Client
 @Description Google Translate V2 API Client
 @File sample.html
 @Autor Juraj Puchký - Devtech <>
 @SVN  svn checkout svn:// jsgtv2c-code
 @Donation 5$ over there ->  then i can give more time to improove code.
 @Version 1.0.0
 @Created 9.10.2012
 @Licence GPLv3 or later
<!DOCTYPE html>
        <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 -->'; // 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();
                detect.customGoogleTranslateApiHandler = new CustomGoogleTranslateHandler();
                detect.setText("Hello world");
                translate.customGoogleTranslateApiHandler = new CustomGoogleTranslateHandler();
    <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="" method="post">
            <input type="hidden" name="cmd" value="_s-xclick">
            <input type="hidden" name="hosted_button_id" value="H2T85LJ5L9XVL">
            <input type="image" src="" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
            <img alt="" border="0" src="" width="1" height="1">
        <H2>Supported languages</H2>    
        <div id="languages">
        <H2>Language detection</H2>    
        <div id="detection">
        <div id="translate">