nvim: add go tr snippet and bind key for find translation key
This commit is contained in:
parent
10ba42cb1d
commit
341499f9a7
@ -36,6 +36,12 @@ for i = 1, 9, 1 do
|
||||
key('n', '<leader>t' .. i, '<cmd>' .. i .. 'tabnext<CR>', { desc = '[T]ab nr [' .. i .. ']' })
|
||||
end
|
||||
|
||||
-- translations
|
||||
|
||||
key('n', '<leader>tr', function()
|
||||
require('lupan.ui').find_translation_key()
|
||||
end, { desc = '[T][r]anlation key find' })
|
||||
|
||||
-- Diagnostic keymaps
|
||||
vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, { desc = 'Go to previous [D]iagnostic message' })
|
||||
vim.keymap.set('n', ']d', vim.diagnostic.goto_next, { desc = 'Go to next [D]iagnostic message' })
|
||||
|
@ -41,4 +41,29 @@ function M.tab_change_dir_newtab()
|
||||
M.tab_change_dir({ action = tabnew_tcd, prompt_title = "Tab change directory (new tab)" })
|
||||
end
|
||||
|
||||
local function append_text(text)
|
||||
text = string.gsub(text, "^ + %w+%.([%w%p]+) +.*", "%1")
|
||||
local row, col = unpack(vim.api.nvim_win_get_cursor(0))
|
||||
vim.api.nvim_buf_set_text(0, row - 1, col, row - 1, col, { text })
|
||||
end
|
||||
|
||||
function M.find_translation_key(opts)
|
||||
opts = opts or {}
|
||||
local action = opts.action or append_text
|
||||
local prompt_title = opts.prompt_title or "Get translation key"
|
||||
local cmd = { 'list-translation-keys' }
|
||||
local dropdown = themes.get_dropdown();
|
||||
local picker_opts = {
|
||||
prompt_title = prompt_title,
|
||||
finder = finders.new_oneshot_job(cmd, {}),
|
||||
sorter = sorters.get_fuzzy_file({}),
|
||||
attach_mappings = function(_, map)
|
||||
map({ "i", "n" }, "<CR>", function(prompt_bufnr) enter(prompt_bufnr, action) end)
|
||||
return true
|
||||
end
|
||||
}
|
||||
local find_translation_key = pickers.new(dropdown, picker_opts)
|
||||
find_translation_key:find()
|
||||
end
|
||||
|
||||
return M
|
||||
|
3
nvim/.config/nvim/snippets/go/snippets.lua
Normal file
3
nvim/.config/nvim/snippets/go/snippets.lua
Normal file
@ -0,0 +1,3 @@
|
||||
return {
|
||||
s("tr", { t "i18n.T(ctx, \"", i(1), t "\")" })
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user