//* comment *// // Copyright (c) 2015 Walter Bender, Ignacio Rodriguez, Sam Parkinson // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 3 of the License, or // (at your option) any later version. // // You should have received a copy of the GNU General Public License // along with this library; if not, write to the Free Software // Foundation, 51 Franklin Street, Suite 500 Boston, MA 02110-1335 USA // Plugins are a dictionary of json-encoded components: a flow-block // dictionary, an arg-block dictionary, a block dictionary, and a // palette dictionary. The flow-block dictionary is a set of commands // that are evaluated when a flow block is run; the arg-block // dictionary is a set of commands that are evaluated when an arg // block is run; the block dictionary defines the new blocks in the // plugin; and the palette dictionary defines icons (svg) associated // with the palettes populated by the blocks found in the plugin. // The Mashape plugin provides blocks that use the mashape.com APIs. // Included here are blocks to translate strings and to poll // international weather forecasts. //* globals *// var translateMashapeKey = '3Rfxc7fwp2mshJxgtDxKSueYna8Ap1qZfAcjsn2hjpuWPuBCrI'; var translatePublicKey = 'nGhwbdV7TrtzC9qLp3DZ'; var translateSecretKey = '3b68e1d00446eed728cdda66280a8312'; //* flow:setlang *// fromLang = logo.parseArg(logo, turtle, logo.blocks.blockList[blk].connections[1]); toLang = logo.parseArg(logo, turtle, logo.blocks.blockList[blk].connections[2]); //* arg:translate *// var apiURL = 'https://community-onehourtranslation.p.mashape.com/mt/'; var key = 'TranslatedText'; var text = logo.parseArg(logo, turtle, logo.blocks.blockList[blk].connections[1]); var targetLang = 'Spanish'; var args = 'translate/text?public_key=' + translatePublicKey + '&secret_key=' + translateSecretKey + '&source_content=' + text + '&source_language=' + fromLang + '&target_language=' + toLang; var request = new XMLHttpRequest(); request.open('GET', apiURL + args, false); request.setRequestHeader('X-Mashape-Authorization', translateMashapeKey); request.send(null); var value = JSON.parse(request.responseText)['results'][key]; if (!value) { logo.errorMsg('Problem with the language setting.', blk); value = ''; } logo.blocks.blockList[blk].value = value; //* arg:detectlang *// var apiURL = 'https://community-onehourtranslation.p.mashape.com/mt/'; var key = 'language'; var text = logo.parseArg(logo, turtle, logo.blocks.blockList[blk].connections[1]); var args = 'detect/text?public_key=' + translatePublicKey + '&secret_key=' + translateSecretKey + '&source_content=' + text; var request = new XMLHttpRequest(); request.open('GET', apiURL + args, false); request.setRequestHeader('X-Mashape-Authorization', translateMashapeKey); request.send(null); var value = JSON.parse(request.responseText)['results'][key]; if (!value) { logo.errorMsg('Problem with the language setting.', blk); value = ''; } logo.blocks.blockList[blk].value = value; //* block:translate *// var translateBlock = new ProtoBlock('translate'); translateBlock.palette = palettes.dict['external']; blocks.protoBlockDict['translate'] = translateBlock; translateBlock.staticLabels.push(_('translate')); translateBlock.adjustWidthToLabel(); translateBlock.oneArgMathBlock(); translateBlock.dockTypes[0] = 'textout'; translateBlock.dockTypes[1] = 'textin'; translateBlock.defaults.push(_('hello')); //* block:detectlang *// var detectLangBlock = new ProtoBlock('detectlang'); detectLangBlock.palette = palettes.dict['external']; blocks.protoBlockDict['detectlang'] = detectLangBlock; detectLangBlock.staticLabels.push(_('detect lang')); detectLangBlock.adjustWidthToLabel(); detectLangBlock.oneArgMathBlock(); detectLangBlock.dockTypes[0] = 'textout'; detectLangBlock.dockTypes[1] = 'anyin'; detectLangBlock.defaults.push(_('hello')); //* block:setlang *// var setLangBlock = new ProtoBlock('setlang'); setLangBlock.palette = palettes.dict['external']; blocks.protoBlockDict['setlang'] = setLangBlock; setLangBlock.staticLabels.push(_('set lang'), _('source'), _('target')); setLangBlock.adjustWidthToLabel(); setLangBlock.twoArgBlock(); setLangBlock.dockTypes[1] = 'anyin'; setLangBlock.dockTypes[2] = 'anyin'; setLangBlock.defaults.push('English', 'Spanish'); //* palette-icon:external *// //* palette-fill:external *// #59f //* palette-stroke:external *// #3771c8 //* palette-highlight:external *// #9DC4FF //* palette-stroke-highlight:external *// #000000