• Stars
    star
    501
  • Rank 88,002 (Top 2 %)
  • Language
    Vim Script
  • License
    MIT License
  • Created over 5 years ago
  • Updated over 1 year ago

Reviews

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

Repository Details

πŸ“• Translating plugin for Vim/Neovim

vim-translator

CI

Asynchronous translating plugin for Vim/Neovim

Installation

Plug 'voldikss/vim-translator'

Features

  • Asynchronous & mutithreading translating
  • Popupwin(vim8) & floatwin(neovim) support
  • Multiple engines: see g:translator_default_engines
  • Proxy support
  • No requirements for appid/appkey

Configuration

g:translator_target_lang

Type String.

Default: 'zh'

Please refer to language support list

g:translator_source_lang

Type String.

Default: 'auto'

Please refer to language support list

g:translator_default_engines

Type List of String.

Available: 'bing', 'google', 'haici', 'iciba'(expired), 'sdcv', 'trans', 'youdao'

Default: If g:translator_target_lang is 'zh', this will be ['bing', 'google', 'haici', 'youdao'], otherwise ['google']

g:translator_proxy_url

Type String. Default: ''

Example: let g:translator_proxy_url = 'socks5://127.0.0.1:1080'

g:translator_history_enable

Type Boolean.

Default: v:false

g:translator_window_type

Type String.

Default: 'popup'

Available: 'popup'(use floatwin in nvim or popup in vim), 'preview'

g:translator_window_max_width

Type Number (number of columns) or Float (between 0 and 1). If Float, the width is relative to &columns.

Default: 0.6

g:translator_window_max_height

Type Number (number of lines) or Float (between 0 and 1). If Float, the height is relative to &lines.

Default: 0.6

g:translator_window_borderchars

Type List of String. Characters of the floating window border.

Default: ['─', 'β”‚', '─', 'β”‚', 'β”Œ', '┐', 'β”˜', 'β””']

Key Mappings

This plugin doesn't supply any default mappings.

""" Configuration example
" Echo translation in the cmdline
nmap <silent> <Leader>t <Plug>Translate
vmap <silent> <Leader>t <Plug>TranslateV
" Display translation in a window
nmap <silent> <Leader>w <Plug>TranslateW
vmap <silent> <Leader>w <Plug>TranslateWV
" Replace the text with translation
nmap <silent> <Leader>r <Plug>TranslateR
vmap <silent> <Leader>r <Plug>TranslateRV
" Translate the text in clipboard
nmap <silent> <Leader>x <Plug>TranslateX

Once the translation window is opened, type <C-w>p to jump into it and again to jump back

Beside, there is a function which can be used to scroll window, only works in neovim.

nnoremap <silent><expr> <M-f> translator#window#float#has_scroll() ?
                            \ translator#window#float#scroll(1) : "\<M-f>"
nnoremap <silent><expr> <M-b> translator#window#float#has_scroll() ?
                            \ translator#window#float#scroll(0) : "\<M-b>"

Commands

Translate

:Translate[!] [--engines=ENGINES] [--target_lang=TARGET_LANG] [--source_lang=SOURCE_LANG] [your text]

Translate the text from the source language source_lang to the target language target_lang with engine, echo the result in the cmdline

If engines is not given, use g:translator_default_engines

If text is not given, use the text under the cursor

If target_lang is not given, use g:translator_target_lang

The command can also be passed to a range, i.e., :'<,'>Translate ..., which translates text in visual selection

If ! is provided, the plugin will perform a reverse translating by switching target_lang and source_lang

Examples(you can use <Tab> to get completion):

:Translate                                  " translate the word under the cursor
:Translate --engines=google,youdao are you ok " translate text `are you ok` using google and youdao engines
:2Translate ...                             " translate line 2
:1,3Translate ...                           " translate line 1 to line 3
:'<,'>Translate ...                         " translate selected lines

TranslateW

:TranslateW[!] [--engines=ENGINES] [--target_lang=TARGET_LANG] [--source_lang=SOURCE_LANG] [your text]

Like :Translate..., but display the translation in a window

TranslateR

:TranslateR[!] [--engines=ENGINES] [--target_lang=TARGET_LANG] [--source_lang=SOURCE_LANG] [your text]

Like :Translate..., but replace the current text with the translation

TranslateX

:TranslateX[!] [--engines=ENGINES] [--target_lang=TARGET_LANG] [--source_lang=SOURCE_LANG] [your text]

Translate the text in the clipboard

TranslateH

:TranslateH

Export the translation history

TranslateL

:TranslateL

Display log message

Highlight

Here are the default highlight links. To customize, use hi or hi link

" Text highlight of translator window
hi def link TranslatorQuery             Identifier
hi def link TranslatorDelimiter         Special
hi def link TranslatorExplain           Statement

" Background of translator window border
hi def link Translator                  Normal
hi def link TranslatorBorder            NormalFloat

Statusline

  • g:translator_status

FAQ

https://github.com/voldikss/vim-translator/issues?q=label%3AFAQ

Breaking Changes

https://github.com/voldikss/vim-translator/issues?q=label%3A%22breaking+change%22

References

License

MIT

More Repositories

1

vim-floaterm

πŸ’» Terminal manager for (neo)vim
Vim Script
2,461
star
2

coc-todolist

[Deprecated due to an unfixable bug and crappy design]πŸ• Todolist/task manager extension for (Neo)Vim
TypeScript
135
star
3

coc-browser

See https://github.com/voldikss/coc-extensions
TypeScript
127
star
4

coc-extensions

🌸 Collections of coc.nvim extensions maintained by @voldikss
TypeScript
123
star
5

coc-cmake

See https://github.com/voldikss/coc-extensions
TypeScript
97
star
6

vim-browser-search

πŸŒ€ Perform a quick web search for the text selected in (Neo)Vim
Vim Script
94
star
7

vim-skylight

πŸ’‘Search asynchronously and preview file/symbol under cursor in the floating window.
Vim Script
89
star
8

vim-codelf

(Neo)Vim plugin for searching variable names
Python
53
star
9

coc-floaterm

See https://github.com/voldikss/coc-extensions
TypeScript
49
star
10

coc-tasks

See https://github.com/voldikss/coc-extensions
TypeScript
31
star
11

dotfiles

My configuration files
Vim Script
30
star
12

coc-github

πŸ™ Github issue source for coc.nvim
TypeScript
30
star
13

fzf-floaterm

Fzf support for vim-floaterm
Vim Script
23
star
14

vim-hello-word

δΈ€δΈͺ用ζ₯θƒŒε•θ―ηš„ (Neo)Vim 插仢
Vim Script
20
star
15

vim-wenyan

Vim plugin for wenyan-lang(syntax, snippets, etc.)
Vim Script
17
star
16

coc-gist

See https://github.com/voldikss/coc-extensions
TypeScript
15
star
17

coc-just-complete

See https://github.com/voldikss/coc-extensions
TypeScript
10
star
18

LeaderF-everything

Use everything.exe in (neo)vim.
Vim Script
7
star
19

coc-lsp-wl

See https://github.com/voldikss/coc-extensions
TypeScript
7
star
20

coc-dot-complete

See https://github.com/voldikss/coc-extensions
TypeScript
5
star
21

coc-dash-complete

See https://github.com/voldikss/coc-extensions
TypeScript
5
star
22

translator-rs

translator cli
Rust
4
star
23

vim-find-everything

Use everything.exe in (neo)vim.
Vim Script
4
star
24

HelloElectsys

🐸 Huck the electsys
JavaScript
4
star
25

LeaderF-floaterm

LeaderF support for vim-floaterm
Vim Script
3
star
26

LeaderF-emoji

Vim Script
1
star
27

clap-floaterm

vim-clap support for vim-floaterm
Vim Script
1
star
28

EE369-2048-AI

Use supervised learning (imitation learning) and tree searching approaches to solve the game of 2048.
Jupyter Notebook
1
star
29

vim-fnote

Vim Script
1
star