Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/niuiic/translate.nvim
Highly configurable translation plugin for neovim.
https://github.com/niuiic/translate.nvim
Last synced: about 2 months ago
JSON representation
Highly configurable translation plugin for neovim.
- Host: GitHub
- URL: https://github.com/niuiic/translate.nvim
- Owner: niuiic
- License: mit
- Created: 2023-01-07T01:48:34.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-05-11T04:34:07.000Z (4 months ago)
- Last Synced: 2024-05-11T05:27:29.610Z (4 months ago)
- Language: Lua
- Homepage:
- Size: 32.2 KB
- Stars: 33
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-neovim - niuiic/translate.nvim - Invoke any translation engine via shell command. (Language / PHP)
README
# translate.nvim
Highly configurable translation plugin for neovim.
[More neovim plugins](https://github.com/niuiic/awesome-neovim-plugins)
## Feature
- multiple output
- float_win: output in float window
- clipboard: copy to clipboard
- insert: insert at current cursor position
- notify: notify with vim.notify
- multiple translate engine: invoke any translation engine via shell command
- async job: never block your work## Dependencies
- [niuiic/core.nvim](https://github.com/niuiic/core.nvim)
## Config
- default config
```lua
{
output = {
float = {
max_width = 40,
max_height = 5,
close_on_cursor_move = true,
enter_key = "T",
},
},
translate = {},
}
```- example
```lua
require("translate").setup({
output = {
float = {
-- max_width of float window
max_width = 40,
-- max_height of float window
max_height = 5,
-- whether close float window on cursor move
close_on_cursor_move = true,
-- key to enter float window
enter_key = "T",
},
},
translate = {
{
-- use :TransToZH to start this job
cmd = "TransToZH",
-- shell command
-- translate-shell is used here
command = "trans",
-- shell command args
args = function(trans_source)
-- trans_source is the text you want to translate
return {
"-b",
"-e",
"google",
-- use proxy
-- "-x",
-- "http://127.0.0.1:10025",
"-t",
"zh-CN",
-- you can filter translate source here
trans_source,
}
end,
-- how to get translate source
-- selection | input | clipboard
input = "selection",
-- how to output translate result
-- float_win | notify | clipboard | insert
output = { "float_win" },
-- format output
---@type fun(output: string): string
format = function(output)
return output
end,
},
{
cmd = "TransToEN",
command = "trans",
args = function(trans_source)
return {
"-b",
"-e",
"google",
"-t",
"en",
trans_source,
}
end,
input = "input",
output = { "notify", "clipboard" },
},
},
})
```- keymap
Notice: if input = "selection", source can be text selected in virtual mode(just `v`, not work in `V` and `C-v`) or expression under the cursor in normal mode.
```lua
vim.keymap.set("v", "", "TransToZH", { silent = true })
vim.keymap.set("n", "T", "TransToEN")
```