Perform translation in Neovim using translate-shell
Find a file
2026-02-06 21:30:39 +01:00
lua/translate feat: create translate.nvim 2026-02-06 21:30:39 +01:00
plugin feat: create translate.nvim 2026-02-06 21:30:39 +01:00
test feat: create translate.nvim 2026-02-06 21:30:39 +01:00
.busted feat: create translate.nvim 2026-02-06 21:30:39 +01:00
.gitignore feat: create translate.nvim 2026-02-06 21:30:39 +01:00
.mise.toml feat: create translate.nvim 2026-02-06 21:30:39 +01:00
README.md feat: create translate.nvim 2026-02-06 21:30:39 +01:00

translate.nvim

Neovim plugin for translating text using translate-shell.

Features

  • :Translate command 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

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