Highly configurable translation plugin for neovim.
- multiple input methods
- multiple output methods
- invoke any translation engine via shell command
- async job: never block your work
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