docs: add simple explain readme

This commit is contained in:
JuanZoran 2023-03-17 10:17:37 +08:00
parent eacb06cd30
commit 7f1f8aa262

187
README.md
View File

@ -17,8 +17,7 @@
- [待办 (画大饼)](#待办-画大饼) - [待办 (画大饼)](#待办-画大饼)
<!--toc:end--> <!--toc:end-->
### 注意: 当前分支目前没有发布, README.md的描述并不准确, 遇到问题请切换到 `main`分支或者联系我 ### 注意: 当前分支目前没有发布, README.md 的描述并不准确, 遇到问题请切换到 `main`分支或者联系我
## 特点 ## 特点
@ -90,7 +89,7 @@ _安装之前, 首先需要明确本插件的依赖:_
use { use {
'JuanZoran/Trans.nvim' 'JuanZoran/Trans.nvim'
run = function() require('Trans').install() end, -- 自动下载使用的本地词库 run = function() require('Trans').install() end, -- 自动下载使用的本地词库
requires = { 'kkharji/sqlite.lua', }, requires = 'kkharji/sqlite.lua', ,
-- 如果你不需要任何配置的话, 可以直接按照下面的方式启动 -- 如果你不需要任何配置的话, 可以直接按照下面的方式启动
config = function () config = function ()
require'Trans'.setup{ require'Trans'.setup{
@ -116,7 +115,6 @@ use {
require("Trans").setup {} -- 启动Trans require("Trans").setup {} -- 启动Trans
vim.keymap.set({"n", 'x'}, "mm", '<Cmd>Translate<CR>', { desc = ' Translate' }) -- 自动判断virtual 还是 normal 模式 vim.keymap.set({"n", 'x'}, "mm", '<Cmd>Translate<CR>', { desc = ' Translate' }) -- 自动判断virtual 还是 normal 模式
vim.keymap.set({'n', 'x'}, 'mk', '<Cmd>TransPlay<CR>', {desc = ' 自动发音'}) -- 自动发音选中或者光标下的单词 vim.keymap.set({'n', 'x'}, 'mk', '<Cmd>TransPlay<CR>', {desc = ' 自动发音'}) -- 自动发音选中或者光标下的单词
vim.keymap.set("n", "mi", "<Cmd>TranslateInput<CR>", { desc = ' Translate' })
end end
} }
``` ```
@ -168,7 +166,7 @@ use {
> `sudo pacman -S sqlite # Arch` > `sudo pacman -S sqlite # Arch`
> `sudo apt-get install sqlite3 libsqlite3-dev # Ubuntu` > `sudo apt-get install sqlite3 libsqlite3-dev # Ubuntu`
> 后续会增加 `healthcheck` 进行检查 > **尝试运行 `checkhealth Trans`**
- **`auto_play`** 使用步骤: - **`auto_play`** 使用步骤:
@ -236,25 +234,20 @@ use {
## 配置 ## 配置
```lua ```lua
require'Trans'.setup{ require'Trans'.setup {
---@type string the directory for database file and password file ---@type string the directory for database file and password file
dir = os.getenv('HOME') .. '/.vim/dict', dir = os.getenv('HOME') .. '/.vim/dict',
---@type table modeStrategy default strategy for mode query = 'fallback',
-- backend_order = {},
---@type 'default' | 'dracula' | 'tokyonight' global Trans theme [see lua/Trans/style/theme.lua]
theme = 'default', -- default | tokyonight | dracula
strategy = { strategy = {
---@type { frontend:string, backend:string } fallback strategy for mode ---@type { frontend:string, backend:string | string[] } fallback strategy for mode
default = { default = {
frontend = 'hover', frontend = 'hover',
backend = '*', backend = '*',
}, },
}, },
---@type table<string, TransBackendOpts> fallback backend for mode
backend = {
---@class TransBackendOpts
default = {
---@type integer timeout for backend send request
timeout = 2000,
},
},
---@type table frontend options ---@type table frontend options
frontend = { frontend = {
---@class TransFrontendOpts ---@class TransFrontendOpts
@ -270,6 +263,7 @@ require'Trans'.setup{
close = 'slid', close = 'slid',
interval = 12, interval = 12,
}, },
timeout = 2000,
}, },
---@class TransHoverOpts : TransFrontendOpts ---@class TransHoverOpts : TransFrontendOpts
hover = { hover = {
@ -280,16 +274,17 @@ require'Trans'.setup{
---@type string -- see: /lua/Trans/style/spinner ---@type string -- see: /lua/Trans/style/spinner
spinner = 'dots', spinner = 'dots',
---@type string -- TODO :support replace with {{special word}} ---@type string -- TODO :support replace with {{special word}}
fallback_message = '翻译超时或没有找到相关的翻译', fallback_message = '{{notfound}} 翻译超时或没有找到相关的翻译',
auto_resize = true, auto_resize = true,
-- strict = false, -- TODO :No Width limit when str is a sentence
padding = 10, -- padding for hover window width padding = 10, -- padding for hover window width
keymaps = { keymaps = {
-- play = '_', -- Deprecated
pageup = '[[', pageup = '[[',
pagedown = ']]', pagedown = ']]',
pin = '<leader>[', pin = '<leader>[',
close = '<leader>]', close = '<leader>]',
toggle_entry = '<leader>;', toggle_entry = '<leader>;',
-- play = '_', -- Deprecated
}, },
---@type string[] auto close events ---@type string[] auto close events
auto_close_events = { auto_close_events = {
@ -297,31 +292,47 @@ require'Trans'.setup{
'CursorMoved', 'CursorMoved',
'BufLeave', 'BufLeave',
}, },
---@type string[] order to display translate result ---@type table<string, string[]> order to display translate result
order = { order = {
'title', default = {
'tag', 'str',
'pos', 'translation',
'exchange', 'definition',
'translation', },
'definition', offline = {
'title',
'tag',
'pos',
'exchange',
'translation',
'definition',
},
youdao = {
'title',
'translation',
'definition',
'web',
}
}, },
---@type table<string, string> ---@type table<string, string>
icon = { icon = {
-- or use emoji -- or use emoji
star = '', -- ⭐ list = '●', -- ● | ○ | ◉ | ◯ | ◇ | ◆ | ▪ | ▫ | ⬤ | 🟢 | 🟡 | 🟣 | 🟤 | 🟦 | 🟨 | 🟧 | 🟥 | 🟪 | 🟫 | 🟩 | 🟠 | 🟦 | 🟨 | 🟧 | 🟥 | 🟪 | 🟫 | 🟩 | 🟠
notfound = ' ', -- ❔ star = '', -- ⭐ | ✴ | ✳ | ✲ | ✱ | ✰ | ★ | ☆ | 🌟 | 🌠 | 🌙 | 🌛 | 🌜 | 🌟 | 🌠 | 🌌 | 🌙 |
yes = '✔', -- ✔️ notfound = ' ', --❔ | ❓ | ❗ | ❕|
no = '', -- ❌ yes = '✔', -- ✅ | ✔️ | ☑
cell = '■', -- ■ | □ | ▇ | ▏ ▎ ▍ ▌ ▋ ▊ ▉ █ no = '', -- ❌ | ❎ | ✖ | ✘ | ✗ |
cell = '■', -- ■ | □ | ▇ | ▏ ▎ ▍ ▌ ▋ ▊ ▉ █
web = '󰖟', --🌍 | 🌎 | 🌏 | 🌐 |
tag = ' ',
pos = '',
translation = '󰊿',
definition = '󰗊',
exchange = '✳',
}, },
}, },
}, },
style = { }p
---@type string global Trans theme [see lua/Trans/style/theme.lua]
theme = 'default', -- default | tokyonight | dracula
},
}
``` ```
@ -334,8 +345,6 @@ require'Trans'.setup{
```lua ```lua
vim.keymap.set({'n', 'x'}, 'mm', '<Cmd>Translate<CR>') vim.keymap.set({'n', 'x'}, 'mm', '<Cmd>Translate<CR>')
vim.keymap.set({'n', 'x'}, 'mk', '<Cmd>TransPlay<CR>') -- 自动发音选中或者光标下的单词 vim.keymap.set({'n', 'x'}, 'mk', '<Cmd>TransPlay<CR>') -- 自动发音选中或者光标下的单词
vim.keymap.set('n', 'mi', '<Cmd>TranslateInput<CR>')
``` ```
## 高亮组 ## 高亮组
@ -344,50 +353,58 @@ vim.keymap.set('n', 'mi', '<Cmd>TranslateInput<CR>')
```lua ```lua
{ {
TransWord = { TransWord = {
fg = '#7ee787', fg = '#7ee787',
bold = true, bold = true,
}, },
TransPhonetic = { TransPhonetic = {
link = 'Linenr' link = 'Linenr'
}, },
TransTitle = { TransTitle = {
fg = '#0f0f15', fg = '#0f0f15',
bg = '#75beff', bg = '#75beff',
bold = true, bold = true,
}, },
TransTitleRound = { TransTitleRound = {
fg = '#75beff', fg = '#75beff',
}, },
TransTag = { TransTag = {
fg = '#e5c07b', -- fg = '#e5c07b',
}, link = '@tag'
TransExchange = { },
link = 'TransTag', TransExchange = {
}, link = 'TransTag',
TransPos = { },
link = 'TransTag', TransPos = {
}, link = 'TransTag',
TransTranslation = { },
link = 'TransWord', TransTranslation = {
}, link = 'TransWord',
TransDefinition = { },
link = 'Moremsg', TransDefinition = {
}, link = 'Moremsg',
TransWin = { },
link = 'Normal', TransWin = {
}, link = 'Normal',
TransBorder = { },
link = 'FloatBorder', TransBorder = {
}, fg = '#89B4FA',
TransCollins = { },
fg = '#faf743', TransCollins = {
bold = true, fg = '#faf743',
}, bold = true,
TransFailed = { },
fg = '#7aa89f', TransFailed = {
}, fg = '#7aa89f',
} },
TransWaitting = {
link = 'MoreMsg'
},
TransWeb = {
-- TODO :
link = 'MoreMsg',
}
}
``` ```
## 声明 ## 声明
@ -407,11 +424,11 @@ vim.keymap.set('n', 'mi', '<Cmd>TranslateInput<CR>')
## 待办 (画大饼) ## 待办 (画大饼)
- [x] 多风格样式查询
- [x] 重新录制屏幕截图示例
- [x] 快捷键定义 - [x] 快捷键定义
- [x] 自动读音 - [x] 自动读音
- [x] 在线多引擎异步查询
- [x] `句子翻译` | `中翻英` 的支持
- [ ] 多风格样式查询
- [ ] 重新录制屏幕截图示例
- [ ] 变量命名的支持 - [ ] 变量命名的支持
- [ ] 历史查询结果保存 - [ ] 历史查询结果保存
- [ ] 在线多引擎异步查询
- [ ] `句子翻译` | `中翻英` 的支持