From 803405d9e076ea233aa0fefa822f02d6222e393e Mon Sep 17 00:00:00 2001 From: previousdeveloper Date: Fri, 30 Oct 2015 02:19:54 +0300 Subject: [PATCH] init --- .gitignore | 1 + bin/translater.js | 2 ++ index.js | 28 ++++++++++++++++++++++++++++ package.json | 30 ++++++++++++++++++++++++++++++ 4 files changed, 61 insertions(+) create mode 100644 bin/translater.js create mode 100644 index.js create mode 100644 package.json diff --git a/.gitignore b/.gitignore index 123ae94..b5f8e29 100644 --- a/.gitignore +++ b/.gitignore @@ -25,3 +25,4 @@ build/Release # Dependency directory # https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git node_modules +.idea \ No newline at end of file diff --git a/bin/translater.js b/bin/translater.js new file mode 100644 index 0000000..036193d --- /dev/null +++ b/bin/translater.js @@ -0,0 +1,2 @@ +#!/usr/bin/env node +require('../'); diff --git a/index.js b/index.js new file mode 100644 index 0000000..fbfc9ae --- /dev/null +++ b/index.js @@ -0,0 +1,28 @@ +var request = require('request'); +var colors = require('colors'); +var argv = require('yargs').argv; + + +if (argv._.length > 2) { + request('http://mymemory.translated.net/api/get?q=' + argv._[0] + '&langpair=' + argv._[1] + '|' + argv._[2], function (error, response, body) { + + if (response.statusCode === 200) { + + var data = JSON.parse(body.trim()); + + data.matches.forEach(function (val, index, theArray) { + + console.log(colors.green(val.translation)); + + }); + }else{ + console.error(colors.red('translating error !')); + + } + + + }); +} else { + + console.error(colors.red('missing parameters')); +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..ba8734d --- /dev/null +++ b/package.json @@ -0,0 +1,30 @@ +{ + "name": "translater", + "version": "2.0.0", + "description": "Translate is a command-line interface to the MyMemory translated", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "bin": { + "translater": "./bin/translater.js" + }, + "repository": { + "type": "git", + "url": "https://https://github.com/previousdeveloper/translater.git" + }, + "keywords": [ + "translater" + ], + "author": "Gokhan Karadas (http://www.gokhankaradas.com)", + "license": "MIT", + "bugs": { + "url": "https://github.com/previousdeveloper/translater/issues" + }, + "homepage": "https://github.com/previousdeveloper/translater/issues#readme", + "dependencies": { + "colors": "^1.1.2", + "request": "^2.64.0", + "yargs":"^3.29.0" + } +} \ No newline at end of file