niuiic/translate.nvim

github github
language
stars 41
issues 0
subscribers 2
forks 2
CREATED

2023-01-07

UPDATED

2 months ago


translate.nvim

Highly configurable translation plugin for neovim.

More neovim plugins

Feature

  • multiple input methods
  • multiple output methods
  • invoke any translation engine via shell command
  • async job: never block your work

Dependencies

Usage

local function trans_to_zh()
    require("translate").translate({
        get_command = function(input)
            return {
                "trans",
                "-e",
                "bing",
                "-b",
                ":zh",
                input,
            }
        end,
        -- input | clipboard | selection
        input = "selection",
        -- open_float | notify | copy | insert | replace
        output = { "open_float" },
        resolve_result = function(result)
            if result.code ~= 0 then
                return nil
            end

            return string.match(result.stdout, "(.*)\n")
        end,
    })
end

local function trans_to_en()
    require("translate").translate({
        get_command = function(input)
            return {
                "trans",
                "-e",
                "bing",
                "-b",
                ":en",
                input,
            }
        end,
        input = "selection",
        output = { "replace" },
        resolve_result = function(result)
            if result.code ~= 0 then
                return nil
            end

            return string.match(result.stdout, "(.*)\n")
        end,
    })
end