Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/uga-rosa/translate.nvim
Use any external translate command/API in nvim.
https://github.com/uga-rosa/translate.nvim
lua neovim-plugin
Last synced: 2 months ago
JSON representation
Use any external translate command/API in nvim.
- Host: GitHub
- URL: https://github.com/uga-rosa/translate.nvim
- Owner: uga-rosa
- License: mit
- Created: 2021-10-10T15:13:23.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2023-08-21T08:58:57.000Z (over 1 year ago)
- Last Synced: 2024-08-07T18:37:48.123Z (5 months ago)
- Topics: lua, neovim-plugin
- Language: Lua
- Homepage:
- Size: 140 KB
- Stars: 159
- Watchers: 3
- Forks: 11
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# translate.nvim
![demo](https://user-images.githubusercontent.com/82267684/158013979-52c8ca49-84e1-4ca0-bf30-b8165cca9135.gif)
# Features
- You can use any command you like for translation.
- Google translate API (default)
- [translate-shell](https://github.com/soimort/translate-shell)
- [DeepL API Pro/Free](https://www.deepl.com/en/docs-api/)
- 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](https://curl.se/).
If you use [translate-shell](https://github.com/soimort/translate-shell), you need to install `trans` command.
If you use [DeepL API Pro/Free](https://www.deepl.com/en/docs-api/), 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](https://github.com/junegunn/vim-plug), [packer.nvim](https://github.com/wbthomason/packer.nvim), [dein.vim](https://github.com/Shougo/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.
```vim
let g:deepl_api_auth_key = 'MY_AUTH_KEY'
lua <: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 for mapping.
If you cannot use it, you must change the format with nmap and xmap.nnoremap me Translate EN
xnoremap me Translate EN
Another way.nnoremap me :Translate EN
xnoremap me :Translate EN# Translate the word under the cursor
You can use this mapping.
```vim
nnoremap tw viw:Translate ZH
```