Perform translation in Neovim using translate-shell
- Lua 100%
| lua/translate | ||
| plugin | ||
| test | ||
| .busted | ||
| .gitignore | ||
| .mise.toml | ||
| README.md | ||
translate.nvim
Neovim plugin for translating text using translate-shell.
Features
:Translatecommand with popup preview- Replace visual selection with translation
- Replace word under cursor with translation
- Formatted markdown output with pronunciations, definitions, examples, and synonyms
- Main translation automatically copied to
+register
Requirements
- translate-shell (
transCLI)
Installation
Using lazy.nvim:
{
"l-lin/translate.nvim",
cmd = "Translate",
opts = { default_lang = "en" },
keys = {
{ "<leader>tr", function() require("translate").replace_selection() end, mode = "v", desc = "Translate & replace" },
{ "<leader>tr", function() require("translate").replace_cword() end, mode = "n", desc = "Translate & replace word under cursor" },
},
}
Usage
Command Mode
:Translate hello fr " Translate 'hello' to French
:Translate hello world fr " Translate 'hello world' to French
:Translate bonjour " Translate to default language (en)
Opens a floating window with formatted translation. Cursor positioned at line 3, main translation copied to + register.
Lua API
-- Setup with custom default language
require("translate").setup({ default_lang = "fr" })
-- Translate and show popup
require("translate").translate("hello", "fr")
-- Replace visual selection with translation (no popup)
require("translate").replace_selection()
-- Replace word under cursor with translation (no popup)
require("translate").replace_cword()
Configuration
{
default_lang = "en", -- Target language when not specified
}
Testing
# Using mise
mise run test
# Or directly with busted
busted --lpath='./lua/?.lua;./lua/?/init.lua' test/
License
MIT