Skip to content

acidsugarx/babel.nvim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

18 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🌍 babel.nvim

Translate text without leaving Neovim

Neovim Lua License


✨ Features

  • πŸ”€ Translate selected text or word under cursor
  • πŸͺŸ Multiple display modes (float, picker)
  • πŸ” Auto-detect installed picker
  • πŸ“‹ Copy translation to clipboard with y
  • ⚑ Async translation (non-blocking)

Supported Pickers

Picker Status
Native float βœ…
snacks.nvim βœ…
telescope.nvim βœ…
fzf-lua βœ…
mini.pick βœ…

⚑ Requirements

  • Neovim >= 0.9.0
  • curl

Optional (for picker display):

  • snacks.nvim, telescope.nvim, fzf-lua, or mini.pick

πŸ“¦ Installation

{
  "acidsugarx/babel.nvim",
  version = "*", -- recomended for the latest tag, not main
  opts = {
    target = "ru",  -- target language
  },
  keys = {
    { "<leader>tr", mode = "v", desc = "Translate selection" },
    { "<leader>tw", desc = "Translate word" },
  },
}

βš™οΈ Configuration

Minimal Setup

require("babel").setup({
  target = "ru",
})

Full Options

Default Configuration
require("babel").setup({
  source = "auto",        -- source language (auto-detect)
  target = "ru",          -- target language
  provider = "google",    -- translation provider: "google", "deepl"
  display = "float",      -- "float" or "picker"
  picker = "auto",        -- "auto", "telescope", "fzf", "snacks", "mini"
  float = {
    border = "rounded",
    max_width = 80,
    max_height = 20,
  },
  keymaps = {
    translate = "<leader>tr",
    translate_word = "<leader>tw",
  },
  -- DeepL provider settings (optional)
  deepl = {
    api_key = nil,        -- or use DEEPL_API_KEY env variable
    pro = nil,            -- nil = auto-detect, true = Pro, false = Free
    formality = "default", -- "default", "more", "less", "prefer_more", "prefer_less"
  },
})

Options

Option Type Default Description
source string "auto" Source language (auto-detect)
target string "ru" Target language code
provider string "google" Translation provider: "google", "deepl"
display string "float" Display mode: "float" or "picker"
picker string "auto" Picker: "auto", "telescope", "fzf", "snacks", "mini"
deepl.api_key string nil DeepL API key (or use DEEPL_API_KEY env)
deepl.pro boolean nil Force Pro/Free endpoint (nil = auto-detect by key)
deepl.formality string "default" Formality: "default", "more", "less", "prefer_more", "prefer_less"

Language Codes

Common language codes
Code Language
en English
ru Russian
de German
fr French
es Spanish
it Italian
pt Portuguese
zh Chinese
ja Japanese
ko Korean
ar Arabic
hi Hindi
tr Turkish
pl Polish
uk Ukrainian

πŸš€ Usage

Keymaps

Keymap Mode Description
<leader>tr Visual Translate selection
<leader>tw Normal Translate word under cursor

Commands

Command Description
:Babel [text] Translate provided text
:BabelWord Translate word under cursor

In Translation Window

Key Action
q / <Esc> / <CR> Close window
y Copy translation to clipboard
j / k Scroll

🌐 Providers

Provider Status API Key Notes
Google Translate βœ… No Default, unofficial API
DeepL πŸ§ͺ Yes (free tier) Best quality, 500k chars/month free
LibreTranslate πŸ”œ No Open source, self-hostable
Yandex πŸ”œ Yes Great for Russian
Lingva πŸ”œ No Google proxy, no rate limits

πŸ§ͺ Testing: DeepL provider is implemented but needs testing. If you have a DeepL API key and want to help test, please open an issue with your feedback!

DeepL Setup
  1. Get a free API key at deepl.com/pro#developer (500k chars/month free)

  2. Set up the API key (choose one):

    Option A: Environment variable

    export DEEPL_API_KEY="your-api-key-here"

    Option B: In config

    require("babel").setup({
      provider = "deepl",
      deepl = {
        api_key = "your-api-key-here",
      },
    })
  3. The endpoint (Free/Pro) is auto-detected from the key suffix (:fx = Free). You can override with deepl.pro = true/false.

  4. If no API key is found, babel.nvim will automatically fall back to Google Translate with a warning.

🀝 Contributing

Contributions are welcome! Feel free to:

  • πŸ› Report bugs
  • πŸ’‘ Suggest features
  • πŸ”§ Submit pull requests

πŸ™ Acknowledgments

Thanks to the amazing Neovim plugin ecosystem:

πŸ“ License

MIT Β© Ilya Gilev

About

🌍 Translate text without leaving Neovim

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Packages

No packages published