Last active
December 25, 2015 20:49
-
-
Save fastcodecoq/7037486 to your computer and use it in GitHub Desktop.
Gomosoft I/O Translate
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| GOMOSOFT I/O Translate | |
| GET https://io.gomosoft.com/translate | |
| @params | |
| lf (String): es la logica para la traducción, ej es|en, puedes usar auto|es, | |
| para que el API detecte el lenguaje del texto automaticamente y lo traduzca a un lenguaje destino. | |
| text (String): Es el mensaje a traducir, se permite un máximo de 500 caracteres por petición. | |
| ej. del GET | |
| https://io.gomosoft.com/translate?lf=es|en&text={aquí tu texto a traducir} | |
| */ | |
| //Ejemplo de uso desde Javascript Usando jQuery | |
| function translate(data, callback){ | |
| if(! (callback instanceof Function) ) | |
| { | |
| console.log("you must specify, a callback function"); | |
| return false; | |
| } | |
| if(!data) | |
| return false; | |
| var query = "https://io.gomosoft.com/translate?lf=" + data.lf + "&text=" + encodeURI(data.text) + "&callback=?"; // si decides hacer jsonp cambiar callback=? por el nombre de tu función ej. successTranslation, | |
| $.getJSON( query, function(rs){ | |
| if(callback instanceof Function) | |
| callback(data, rs); | |
| }); | |
| } | |
| translate( { lf : "auto|es" , text : "lorem ipsum dolor sit amet"} , function(data, rs){ | |
| alert("Tu mensaje: " + data.text + " - Traducción: " + rs.rs.translation); | |
| }); | |
| //Ejemplo usando JSONP | |
| function successTranslation( rs ){ | |
| alert("Traducción: " + rs.rs.translation); | |
| } | |
| function callJSONP(data){ | |
| var query = "https://io.gomosoft.com/translate?lf=" + data.lf + "&text=" + encodeURI(data.text) + "&callback=successTranslation"; | |
| $.ajax({ | |
| type: 'GET', | |
| url: query, | |
| async: false, | |
| contentType: "application/json", | |
| dataType: 'jsonp' | |
| }); | |
| } | |
| callJSONP({lf : "auto|en" , text : "Hello world"}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment