@arcblock/markdown-translator
> A smart translator that helps to translate your markdown to any language without messing up the format. This tool is built upon google translation service.
Last updated 6 months ago by wangshijun .
MIT · Original npm · Tarball · package.json
$ cnpm install @arcblock/markdown-translator 
SYNC missed versions from official npm registry.

Markdown Translator

A smart translator that helps to translate your markdown to any language without messing up the format. This tool is built upon google translation service.

Usage

Markdown translator comes with both programmatic and command-line support.

CLI Usage

First install the command line tool:

npm install -g @arcblock/markdown-translator

Then, print usage information:

❯ translator -h
Usage: translator [options]

Options:
  -V, --version             output the version number
  -i, --input-path <path>   Which file to translate
  -t, --target <lang>       Target language to translate (default: "en")
  -o, --output-path <path>  Where to put translated file
  -k, --api-key <key>       Google API Key, default to $GOOGLE_TRANSLATE_API_KEY
  -c, --cache-dir <dir>     Where to put translation cache, defaults to tmp
  -v, --verbose             Do we want to enable debug mode
  -h, --help                output usage information

Then, translate a file

translator -i /path/to/your/doc.md
translator -i /path/to/your/doc.md --target en

Programmatic

First, add dependency:

npm install @arcblock/markdown-translator -S

Then, create a translator and do translation:

const os = require('os');
const MarkdownTranslator = require('@arcblock/markdown-translator');

const apiKey = ''; // your google translation api key
const target = 'en';
const sourceFile = '/path/to/your/doc.md';
const cacheDir = os.tmpdir();
const translator = new MarkdownTranslator(apiKey);

translator
  .translate({ sourceFile, target, cacheDir })
  .then(files => {
    files.forEach(({ fileAbsolutePath, markdownResult }) => {
      console.log('translated', { fileAbsolutePath, markdownResult });
    });
  })
  .catch(err => {
    console.error(err);
  });

Current Tags

  • 0.1.0                                ...           latest (6 months ago)

1 Versions

  • 0.1.0                                ...           6 months ago
Maintainers (2)
Downloads
Today 0
This Week 0
This Month 1
Last Day 0
Last Week 1
Last Month 1
Dependencies (14)
Dev Dependencies (0)
None
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |