Translate text directly from Neovim using a free public translation endpoint, with no API key and no dependency other than curl.
- Translates a visual selection, the command arguments, or prompted text
- Optional yank of the result into the registers
- Optional in-place replacement of the selection
- Neovim >= 0.10.0
curl
{
"AlexPiquard/translator.nvim",
-- Example keybindings
keys = {
{ "<leader>tf", function()
require("translator").translate("fr", nil, { replace_selection = true, yank_output = false })
end, desc = "Translate selection to French, without yanking" },
{ "<leader>te", "<cmd>Translate en<cr>", desc = "Translate to English" },
},
opts = {},
}use {
"AlexPiquard/translator.nvim",
}:Translate <lang> [text]
<lang> is an ISO 639-1 code (fr, en, de, ...). The source language is auto-detected.
The text to translate comes from, in order:
- The command arguments
- An active visual selection
- A prompt (
vim.ui.input)
{
"AlexPiquard/translator.nvim",
opts = { replace_selection = true },
}Select some text and run :Translate <lang>: the selection is replaced by the translation. Characterwise and linewise selections are supported; block selections are ignored.
Defaults:
{
yank_output = true, -- yank the translation into the registers
replace_selection = false, -- replace the visual selection with the translation
visual_input = true, -- use the visual selection as the input text
notify_output = true, -- print the translation as a notification
}