Skip to content

Commit

Permalink
docs
Browse files Browse the repository at this point in the history
  • Loading branch information
christian-fei committed Mar 26, 2020
1 parent e8de531 commit a8cc8a5
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 22 deletions.
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,41 @@

spins up a puppeteer instance (with [mega-scraper](https://www.npmjs.com/package/mega-scraper)) and translates any text for free using google translate, headlessly, with a free random proxy (using [get-free-https-proxy](https://www.npmjs.com/package/get-free-https-proxy))

## cli usage

```
npm i -g free-google-translate-with-puppeteer
free-google-translate-with-puppeteer --text 'hello how are you' --to 'de'
```

## cli options

#### --text [text] (required)

the text to translate


#### --to [language] (default: en)

translate given text to the following language

#### --from [language] (default: auto)

translate given text from given language


### alternatively with npx

```
npx free-google-translate-with-puppeteer --text 'hello how are you' --to 'de'
```

## example usage

```
npm i free-google-translate-with-puppeteer
```

```js
const translate = require('free-google-translate-with-puppeteer')

Expand All @@ -12,3 +45,4 @@ translate({ text: 'ein apfel am tag hält den arzt fern', from: 'it', to: 'en' }
console.log(`-> "${translation}"`) // one apple a day keeps the doctor away
})
```

17 changes: 15 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
#!/usr/bin/env node
const { browser: { createBrowser } } = require('mega-scraper')
const args = require('yargs').argv

module.exports = translate
if (require.main === module) {
translate(args)
.then(translation => {
console.log(translation)
process.exit(0)
})
.catch(err => {
console.error(err)
process.exit(1)
})
} else {
module.exports = translate
}

async function translate ({ text, from = 'auto', to, browser } = {}) {
async function translate ({ text, from = 'auto', to = 'en', browser } = {}) {
if (!text) throw new Error('missing text')
if (!from) throw new Error('missing from')
if (!to) throw new Error('missing to')
Expand Down
64 changes: 45 additions & 19 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
"version": "1.0.0",
"description": "",
"main": "index.js",
"bin": "index.js",
"dependencies": {
"mega-scraper": "^11.11.0"
"mega-scraper": "^11.11.0",
"yargs": "^15.3.1"
},
"devDependencies": {
"ava": "^2.4.0"
Expand Down

0 comments on commit a8cc8a5

Please sign in to comment.