• Stars
    star
    164
  • Rank 228,955 (Top 5 %)
  • Language
    Lua
  • License
    MIT License
  • Created almost 3 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Use any external translate command/API in nvim.

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>

More Repositories

1

ccc.nvim

Color picker and highlighter plugin for Neovim.
Lua
712
star
2

cmp-dictionary

A dictionary completion source for nvim-cmp
Lua
246
star
3

utf8.nvim

The missing utf8 module for neovim Lua.
Lua
77
star
4

scorpeon.vim

Syntax highlight using VSCode's textmate grammar as is.
TypeScript
72
star
5

cmp-dynamic

Source of nvim-cmp to dynamically generate candidates using Lua functions.
Lua
39
star
6

ugaterm.nvim

A terminal plugin for Neovim
Lua
33
star
7

jam.nvim

Japanese IME (not skk!) plugin for neovim.
Lua
32
star
8

denippet.vim

A snippet plugin for Vim/Neovim, powered by TypeScript
TypeScript
28
star
9

ddu-source-lsp

Ddu source for lsp.
TypeScript
19
star
10

dotfiles

My personal configs
Lua
18
star
11

ddc-previewer-floating

A previewer for ddc.vim in Neovim.
Lua
13
star
12

cmp-skkeleton

nvim-cmp source for skkeleton
Lua
10
star
13

ddc-source-lsp-setup

Lua
8
star
14

contextment.vim

A plugin for context-sensitive comment out.
Vim Script
8
star
15

ddc-source-vsnip

vim-vsnip source for ddc.vim
TypeScript
8
star
16

skk-learning.nvim

Learning skk implemention in Neovim, Lua.
Lua
8
star
17

coc-luasnip

TypeScript
7
star
18

filittle.nvim

A simple and fast file explorer written in Lua.
Lua
7
star
19

join.nvim

Simple join plugin for neovim.
Lua
6
star
20

ddu-filter-converter_devicon

Add devicon to files.
TypeScript
5
star
21

snip2json

Convert ultisnips syntax snippets to LSP format json.
TypeScript
4
star
22

nvim-lsp-setup

To batch configurations that are distributed in lsp.handlers and vim.diagnostic.config().
Lua
4
star
23

steelarray.nvim

Useful functions for array like table
Lua
4
star
24

lua-utils.nvim

Library for neovim Lua
Lua
4
star
25

shellopt.nim

Nim
4
star
26

ddc-source-nvim-lua

Neovim Lua source for ddc.vim.
TypeScript
3
star
27

linkformat.vim

A link formatter for any plugin manager
Vim Script
3
star
28

nim-example.nvim

Use Nim from neovim Lua
Lua
3
star
29

deepl.nvim

Hit deepl api from neovim and display in floating window
Lua
3
star
30

sticky-header.nvim

Lua
2
star
31

cmp-denippet

nvim-cmp source for denippet.vim
Lua
2
star
32

eiwa_dic.nvim

neovimのフローティングウィンドウを使った英和辞書
Lua
2
star
33

ddc-source-dictionary

Dictionary source for ddc.vim
TypeScript
2
star
34

deno-mock-jr

Mock server based on JSON-RPC
TypeScript
2
star
35

estrela.lua

Extend lua syntax powered by metatable.
Lua
2
star
36

todo.nvim

Lua
1
star
37

neovim-plugin-template

Template for a neovim plugin
Vim Script
1
star
38

ok-colorspace.lua

Lua implementation of Oklab/Okhsv/Okhsl.
Lua
1
star
39

njo

jo written in Nim
Nim
1
star
40

cmp-latex-symbol

Source of nvim-cmp for latex symbol.
Lua
1
star
41

cache.nvim

lru and lfu
1
star
42

deno-denops-lsputil

TypeScript
1
star
43

ugamacs

A set of codes used to analyze a gromacs simulation.
Lua
1
star