Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pantran.motion_translate doesn't work #3

Closed
TornaxO7 opened this issue Sep 3, 2022 · 7 comments
Closed

pantran.motion_translate doesn't work #3

TornaxO7 opened this issue Sep 3, 2022 · 7 comments

Comments

@TornaxO7
Copy link

TornaxO7 commented Sep 3, 2022

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
Copy link
Owner

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
Copy link
Owner

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

potamides added a commit that referenced this issue Sep 5, 2022
For the example mappings to work the argument must be treated as an
expression. The necessary flag was missing for that in the `opts` table
(#3).
@TornaxO7
Copy link
Author

TornaxO7 commented Sep 6, 2022

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
Copy link
Author

TornaxO7 commented Sep 6, 2022

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
Copy link
Owner

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
Copy link
Author

TornaxO7 commented Sep 7, 2022

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

@sahinakkaya
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants