potamides / pantran.nvim

Use your favorite machine translation engines without having to leave your favorite editor.
MIT License
289 stars 2 forks source link

`pantran.motion_translate` doesn't work #3

Closed TornaxO7 closed 1 year ago

TornaxO7 commented 1 year ago

Hi! I have the following keybindings at the moment:

local pantran = require("pantran")

local opts = {noremap = true, silent = true}
vim.keymap.set("n", "mt", pantran.motion_translate, ops)
vim.keymap.set("x", "mt", pantran.motion_translate, ops)

When I do nvim /tmp/test.txt and press mt nothing happens. But if I use

local pantran = require("pantran")

local opts = {noremap = true, silent = true}
-- vim.keymap.set("n", "mt", pantran.motion_translate, ops)
-- vim.keymap.set("x", "mt", pantran.motion_translate, ops)
vim.keymap.set("n", "mt", function() vim.api.nvim_command("Pantran") end, ops)
vim.keymap.set("x", "mt", function() vim.api.nvim_command("Pantran") end, ops)

instead, pressing mt works in normal mode but not in visual mode.

potamides commented 1 year ago

Hi! You need to use an <expr> mapping or it won't work. Also, ops in the argument list is probably a typo and should be opts. The following should work:

local pantran = require("pantran")

local opts = {noremap = true, silent = true, expr = true}
vim.keymap.set("n", "mt", pantran.motion_translate, opts)
vim.keymap.set("x", "mt", pantran.motion_translate, opts)
potamides commented 1 year ago

Oh, I just realized that the example mappings in the README do not contain the <expr> flag. Thanks for bringing this to my attention!

TornaxO7 commented 1 year ago

Also, ops in the argument list is probably a typo and should be opts.

Ah yes, you're right!

You need to use an mapping or it won't work.

Oh ok

Oh, I just realized that the example mappings in the README do not contain the flag. Thanks for bringing this to my attention!

Good that it's added now ^^

TornaxO7 commented 1 year ago

Hm.... Now I'm getting another issue. This is my setup call:

pantran.setup({
    default_engine = "google",
    engines = {
        google = {
            default_source = "en",
            default_target = "de",
        },
    }
})

now if I execute my keybinding, the ui opens as follows: image

I expected to have de as the target language. Am I doing something wrong?

potamides commented 1 year ago

Ah yes, that might be a bit tricky. Did you set up a Bearer token or API key for Google somewhere? If not Pantran uses a fallback API. Since the options and language identifiers can be different for that configuration is done in the fallback table. So your config should look like this:

pantran.setup({
    default_engine = "google",
    engines = {
        google = {
            fallback = {
                default_source = "en",
                default_target = "de",
            }
        }
    }
})
TornaxO7 commented 1 year ago

Yay, it's fully working now as expected! Thank you :)

sahinakkaya commented 1 year ago

Ah yes, that might be a bit tricky. Did you set up a Bearer token or API key for Google somewhere? If not Pantran uses a fallback API. Since the options and language identifiers can be different for that configuration is done in the fallback table. So your config should look like this:

pantran.setup({
    default_engine = "google",
    engines = {
        google = {
            fallback = {
                default_source = "en",
                default_target = "de",
            }
        }
    }
})

I think this should be written somewhere in the README.