Giter Site home page Giter Site logo

translate.nvim's Introduction

translate.nvim

demo

Features

  • You can use any command you like for translation.
  • The results of the translation can be output in a variety of ways.
    • Floating window
    • Split window
    • Insert to the current buffer
    • Replace the original text
    • Set the register
  • The translation command and output method can be specified as command arguments.
  • In addition to the above presets, you can add your own functions.

Requirements

  • neovim 0.8+

The default Google Translate requires nothing but curl.

If you use translate-shell, you need to install trans command.

If you use DeepL API Pro/Free, you need the authorization key for DeepL API Pro/Free. In addition, you need curl to send the request.

Quick start

Install

With any plugin manager you like (e.g. vim-plug, packer.nvim, dein.vim)

Setup

This plugin has default settings, so there is no need to call setup if you want to use it as is.

This is my setting.

let g:deepl_api_auth_key = 'MY_AUTH_KEY'
lua <<EOL
require("translate").setup({
    default = {
        command = "deepl_pro",
    },
    preset = {
        output = {
            split = {
                append = true,
            },
        },
    },
})
EOL

See help for available options.

Command

This plugin provides :Translate.

I put the quote from the help in the fold.

:Translate
:[range]Translate {target-lang} [{-options}...]

    {target-lang}: Required. The language into which the text should be
    translated. The format varies depending on the external command used.

    |:Translate| can take |:range|. |v|, |V| and |CTRL-V| are supported. If it was
    not given, |:Translate| treats current cursor line.

    available options:
        - '-source='
            The language of the text to be translated.
        - '-parse_before='
            The functions to format texts of selection. You can
            use a comma-separated string. If omitted,
            |translate-nvim-option-default-parse-before|.
        - '-command='
            The extermal command to use translation. If omitted,
            |translate-nvim-option-default-command| is used.
        - '-parse_after='
            The functions to format the result of extermal
            command. You can use a comma-separated string.
            If omitted, |translate-nvim-option-default-parse-after|.
        - '-output='
            The function to pass the translation result. If
            omitted, |translate-nvim-option-default-output|.
        - '-comment'
            Special option, used as a flag. If this flag is set
            and the cursor is over a comment, whole comment is
            treated as a selection.


    Use <Cmd> for mapping.
    If you cannot use it, you must change the format with nmap and xmap.


    nnoremap me <Cmd>Translate EN<CR>
    xnoremap me <Cmd>Translate EN<CR>
    
    Another way.

    nnoremap me :<C-u>Translate EN<CR>
    xnoremap me :Translate EN<CR>

Translate the word under the cursor

You can use this mapping.

nnoremap <space>tw viw:Translate ZH<CR>

translate.nvim's People

Contributors

uga-rosa avatar shutils avatar

Watchers

 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.