Git Product home page Git Product logo

translate-markdown's Introduction

Translate Markdown document on Google Translate

translate-markdown is a command line tool to translate your Markdown document on Google Translate. It receives Markdown document from stdin and strips it to plain text, then open Google Translate with the plain text on a browser.

Install

$ npm install -g translate-markdown

Usage

Please see translate-markdown --help.

screen shot

$ translate-markdown [--help|--strip-only|--apikey {key}] {target lang}

    Translate Makrdown document from stdin.

Example:

    Below receive Markdown text (README.md) from stdin and open a browser to
    translate it in Google Translate.

        $ cat README.md | translate-markdown ja

    Note that there is restriction of the number of characters.

Options:

    {target lang}
        Specify target language you want to translate. For example, 'en' is for
        English and 'ja' is for Japanese. The language of markdown text is
        automatically detected.

    --strip-only
        Strip markdown to plain text only. Stripped plain text is output to
        stdout.

    --apikey {key}
        Use Google Translate API isntead of opening a browser. The result text will
        be output to stdout. You can also use $TRANSLATE_MARKDOWN_APIKEY environment
        variable to set a API key.

    --help
        Show this help.

Features are also available from Node.js program. Please see APIs in code.

Tips

Use from Vim

function! s:translate_markdown(lang) abort
    if &filetype !=# 'markdown'
        echoerr 'Not a Markdown buffer!'
        return
    endif

    if !executable('translate-markdown')
        echoerr '`translate-markdown` command is not found!'
        return
    endif

    let start = getpos("'<")
    let end = getpos("'>")
    let saved = getpos('.')

    call setpos('.', start)
    normal! v
    call setpos('.', end)

    let save_reg_g = getreg('g')
    let save_regtype_g = getregtype('g')
    try
        normal! "gy
        let input = getreg('g')
    finally
        call setreg('g', save_reg_g, save_regtype_g)
        call setpos('.', saved)
    endtry

    echo system('translate-markdown ' . a:lang, input)
endfunction
command! -nargs=0 -range=% TranslateMarkdown call <SID>translate_markdown('en')<CR>

Copy and paste above code to your .vimrc. Now :TranslateMarkdown command is available in visual mode and normal mode. Select the range you want to translate and execute :TranslateMarkdown, then Google Translate is opened with the selected text in browser.

If you want to map the command to some key sequence, please use :autocmd and :noremap. Below maps <Leader>T to the command.

autocmd FileType markdown noremap <buffer><Leader>T :TranslateMarkdown<CR>

translate-markdown's People

Contributors

rhysd avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.