2022-12-21 12:36:00 +08:00
|
|
|
|
# Trans.nvim
|
2023-01-16 00:43:17 +08:00
|
|
|
|
|
|
|
|
|
<!--toc:start-->
|
2022-12-21 12:40:09 +08:00
|
|
|
|
- [Trans.nvim](#transnvim)
|
|
|
|
|
- [特点](#特点)
|
|
|
|
|
- [屏幕截图](#屏幕截图)
|
2023-01-30 22:00:27 +08:00
|
|
|
|
- [演示](#演示)
|
|
|
|
|
- [主题](#主题)
|
2022-12-21 12:40:09 +08:00
|
|
|
|
- [安装](#安装)
|
|
|
|
|
- [配置](#配置)
|
|
|
|
|
- [快捷键绑定](#快捷键绑定)
|
2022-12-21 17:05:28 +08:00
|
|
|
|
- [高亮组](#高亮组)
|
2022-12-21 12:40:09 +08:00
|
|
|
|
- [声明](#声明)
|
|
|
|
|
- [感谢](#感谢)
|
2023-01-20 17:06:49 +08:00
|
|
|
|
- [待办 (画大饼)](#待办-画大饼)
|
2023-01-16 00:43:17 +08:00
|
|
|
|
<!--toc:end-->
|
2022-12-21 12:40:09 +08:00
|
|
|
|
|
2022-12-21 22:17:58 +08:00
|
|
|
|
|
2022-12-21 12:36:00 +08:00
|
|
|
|
## 特点
|
2023-01-30 22:00:27 +08:00
|
|
|
|
- 使用纯lua编写, 速度极快
|
|
|
|
|
> `Lazy.nvim`的记录: <font color="#0099FF">`➜ Trans.nvim 0.82ms`</font>
|
|
|
|
|
|
2022-12-21 12:36:00 +08:00
|
|
|
|
- 大部分功能可以自定义:
|
|
|
|
|
- 高亮
|
|
|
|
|
- 悬浮大小
|
|
|
|
|
- 排版顺序
|
|
|
|
|
- 弹窗大小
|
2023-01-21 00:24:58 +08:00
|
|
|
|
- `舒服窗口动画`
|
2022-12-21 12:40:09 +08:00
|
|
|
|
- etc (更多可以查看[配置](#配置))
|
2022-12-21 12:36:00 +08:00
|
|
|
|
- **完全离线** 的单词翻译体验 (可能后面会支持在线翻译)
|
|
|
|
|
- 支持显示:
|
|
|
|
|
- 柯林斯星级
|
|
|
|
|
- 牛津3000词汇
|
|
|
|
|
- 中文翻译
|
|
|
|
|
- 英文翻译 (不是英译中, 而是用英文解释)
|
|
|
|
|
- 词根
|
|
|
|
|
- etc
|
2023-01-16 00:43:17 +08:00
|
|
|
|
- 舒服的排版和`动画`
|
2022-12-21 16:51:36 +08:00
|
|
|
|
- 支持 `normal`和 `visual`模式
|
2023-01-30 22:00:27 +08:00
|
|
|
|
> <font color='#FF9900'>不支持 visual-block mode</font>
|
2022-12-21 12:36:00 +08:00
|
|
|
|
|
2023-01-09 21:30:16 +08:00
|
|
|
|
- 本地词库单词量: `430w`
|
2022-12-21 12:36:00 +08:00
|
|
|
|
|
|
|
|
|
## 屏幕截图
|
2023-01-25 17:19:07 +08:00
|
|
|
|
### 演示
|
2023-01-21 00:24:58 +08:00
|
|
|
|
https://user-images.githubusercontent.com/107862700/213752097-2eee026a-ddee-4531-bf80-ba2cbc8b44ef.mp4
|
2022-12-21 12:36:00 +08:00
|
|
|
|
|
2023-01-25 17:19:07 +08:00
|
|
|
|
### 主题
|
|
|
|
|
> 如果你有更美观或者更适合的配色, 欢迎提PR
|
|
|
|
|
> 主题配色在: `lua/Trans/theme.lua`文件中,你只需要添加你主题的表就可以了
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- `default`
|
|
|
|
|

|
|
|
|
|
|
|
|
|
|
- `dracula`
|
|
|
|
|

|
|
|
|
|
|
|
|
|
|
- `tokyonight`
|
|
|
|
|

|
|
|
|
|
|
2022-12-21 12:36:00 +08:00
|
|
|
|
|
|
|
|
|
## 安装
|
|
|
|
|
*安装之前, 首先需要明确本插件的依赖:*
|
|
|
|
|
- [ECDICT](https://github.com/skywind3000/ECDICT): 插件所用的离线单词数据库
|
|
|
|
|
- sqlite.lua: 操作数据库所用的库
|
|
|
|
|
- sqlite3: 数据库
|
|
|
|
|
|
2023-01-30 22:00:27 +08:00
|
|
|
|
<details>
|
|
|
|
|
<summary>Packer.nvim</summary>
|
2023-01-21 00:24:58 +08:00
|
|
|
|
|
2022-12-21 12:36:00 +08:00
|
|
|
|
```lua
|
|
|
|
|
use {
|
|
|
|
|
'JuanZoran/Trans.nvim'
|
2022-12-21 17:17:00 +08:00
|
|
|
|
run = 'bash ./install.sh',
|
2023-01-30 12:01:58 +08:00
|
|
|
|
requires = 'kkharji/sqlite.lua',
|
2022-12-21 12:36:00 +08:00
|
|
|
|
-- 如果你不需要任何配置的话, 可以直接按照下面的方式启动
|
2023-01-21 00:24:58 +08:00
|
|
|
|
config = function ()
|
|
|
|
|
require'Trans'.setup{
|
|
|
|
|
-- your configuration here
|
|
|
|
|
}
|
|
|
|
|
end
|
2022-12-25 09:02:37 +08:00
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
**如果你想要使用Packer的惰性加载,这里有一个例子**
|
|
|
|
|
```lua
|
|
|
|
|
use {
|
|
|
|
|
"JuanZoran/Trans.nvim",
|
|
|
|
|
keys = {
|
|
|
|
|
{ 'v', 'mm' }, -- 换成其他你想用的key即可
|
|
|
|
|
{ 'n', 'mm' },
|
2023-01-16 12:10:09 +08:00
|
|
|
|
{ 'n', 'mi' },
|
2022-12-25 09:02:37 +08:00
|
|
|
|
},
|
2023-01-16 00:43:17 +08:00
|
|
|
|
run = 'bash ./install.sh', -- 自动下载使用的本地词库
|
2023-01-30 12:01:58 +08:00
|
|
|
|
requires = 'kkharji/sqlite.lua',
|
2022-12-25 09:02:37 +08:00
|
|
|
|
config = function()
|
2023-01-16 00:43:17 +08:00
|
|
|
|
require("Trans").setup {} -- 启动Trans
|
|
|
|
|
vim.keymap.set({"v", 'n'}, "mm", '<Cmd>Translate<CR>', { desc = ' Translate' }) -- 自动判断virtual 还是 normal 模式
|
|
|
|
|
vim.keymap.set("n", "mi", "<Cmd>TranslateInput<CR>", { desc = ' Translate' })
|
2022-12-25 09:02:37 +08:00
|
|
|
|
end
|
2022-12-21 12:36:00 +08:00
|
|
|
|
}
|
|
|
|
|
```
|
2023-01-30 22:00:27 +08:00
|
|
|
|
</details>
|
|
|
|
|
|
|
|
|
|
<details>
|
|
|
|
|
<summary>Lazy.nvim</summary>
|
2022-12-25 09:02:37 +08:00
|
|
|
|
|
2023-01-26 13:18:40 +08:00
|
|
|
|
```lua
|
|
|
|
|
{
|
|
|
|
|
"JuanZoran/Trans.nvim",
|
|
|
|
|
keys = {
|
|
|
|
|
-- 可以换成其他你想映射的键
|
|
|
|
|
{ 'mm', mode = { 'n', 'x' }, '<Cmd>Translate<CR>', desc = ' Translate' },
|
|
|
|
|
|
|
|
|
|
-- 目前这个功能的视窗还没有做好,可以在配置里将view.i改成hover
|
|
|
|
|
{ 'mi', '<Cmd>TranslateInput<CR>', desc = ' Translate From Input' },
|
|
|
|
|
},
|
|
|
|
|
dependencies = { 'kkharji/sqlite.lua', lazy = true },
|
|
|
|
|
opts = {
|
|
|
|
|
-- your configuration there
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
```
|
2023-01-30 22:00:27 +08:00
|
|
|
|
</details>
|
2023-01-26 13:18:40 +08:00
|
|
|
|
|
2023-01-30 22:00:27 +08:00
|
|
|
|
<font color="#FF9900">**注意事项**: </font>
|
2022-12-21 12:36:00 +08:00
|
|
|
|
- `install.sh`
|
|
|
|
|
- 使用了 `wget`下载词库, 安装请确保你的环境变量中存在wget
|
|
|
|
|
- install.sh 下载后会自动将词库解压, 并移动到 `$HOME/.vim/dict`文件夹下
|
|
|
|
|
- 目前仅在 `Ubuntu22.04`的环境下测试通过
|
|
|
|
|
> 如果上述条件不符合, 请删掉 `run = 'install.sh'`部分, 考虑手动安装词库
|
2022-12-22 11:06:49 +08:00
|
|
|
|
> 如果上述条件满足, 仍出现问题, 欢迎在issue里向我反馈,我会及时尝试解决
|
2022-12-21 12:36:00 +08:00
|
|
|
|
|
|
|
|
|
- 下载词典的过程中, 需要能够 `流畅的访问github下载`
|
|
|
|
|
> 词库文件压缩包大小为: **281M**
|
|
|
|
|
> 解压缩后的大小大概为: 1.2G
|
|
|
|
|
|
|
|
|
|
- 安装后如果不能正常运行, 请尝试检查一下问题:
|
|
|
|
|
- 本机是否已经安装了 `sqlite3`
|
|
|
|
|
> Linux下安装:
|
2023-01-21 08:08:01 +08:00
|
|
|
|
> `sudo pacman -S sqlite # Arch`
|
2022-12-21 12:36:00 +08:00
|
|
|
|
> `sudo apt-get install sqlite3 libsqlite3-dev # Ubuntu`
|
|
|
|
|
|
2022-12-21 22:17:58 +08:00
|
|
|
|
> 后续会增加 `healthcheck` 进行检查
|
2022-12-21 12:36:00 +08:00
|
|
|
|
|
2023-01-21 21:13:51 +08:00
|
|
|
|
- **`auto_play`** 使用步骤:
|
2023-01-21 22:09:20 +08:00
|
|
|
|
> linux 只需要安装`festival`
|
2023-01-22 10:15:23 +08:00
|
|
|
|
> sudo apt-get install festival festvox-kallpc16k
|
|
|
|
|
> ***如果你想要设置音色,发音可以访问:*** [Festival官方](https://www.cstr.ed.ac.uk/projects/festival/morevoices.html)
|
|
|
|
|
> 可以选择英音、美音、男声、女声
|
2023-01-21 22:09:20 +08:00
|
|
|
|
|
|
|
|
|
> 其他操作系统
|
2023-01-21 21:13:51 +08:00
|
|
|
|
- 需要确保安装了`nodejs`
|
|
|
|
|
- 进入插件的`tts`目录运行`npm install`
|
|
|
|
|
> 如果`install.sh`运行正常则自动安装,如果安装失败,请尝试手动安装
|
2023-01-30 12:01:58 +08:00
|
|
|
|
- `title`的配置,只对`neovim 0.9`版本有效
|
2022-12-21 12:36:00 +08:00
|
|
|
|
|
2023-01-30 22:00:27 +08:00
|
|
|
|
<details>
|
|
|
|
|
<summary>Festival配置(仅针对linux用户)</summary>
|
2023-01-22 10:15:23 +08:00
|
|
|
|
- 配置文件
|
|
|
|
|
- 全局配置: `/usr/share/festival/siteinit.scm`
|
|
|
|
|
- 用户配置: `~/.festivalrc`
|
|
|
|
|
|
|
|
|
|
- 更改声音
|
|
|
|
|
- 在festival的voices文件内建立自己的文件夹
|
|
|
|
|
> 一般其默认配置目录在`/usr/share/festival/voices`
|
|
|
|
|
|
|
|
|
|
示例:
|
|
|
|
|
> `sudo mkdir /usr/share/festival/voices/my_voices`
|
|
|
|
|
|
|
|
|
|
- 下载想要的voices文件并解压
|
2023-01-30 22:00:27 +08:00
|
|
|
|
> 可能需要
|
2023-01-22 10:15:23 +08:00
|
|
|
|
|
|
|
|
|
- 试听[在这里](https://www.cstr.ed.ac.uk/projects/festival/morevoices.html))
|
|
|
|
|
- 下载[在这里](http://festvox.org/packed/festival/2.5/voices/))
|
|
|
|
|
> 假设下载的文件在`Downloads`文件夹, 下载的文件为:`festvox_cmu_us_aew_cg.tar.gz`
|
|
|
|
|
|
|
|
|
|
示例:
|
|
|
|
|
> `cd ~/Downloads && tar -xf festvox_cmu_us_aew_cg.tar.gz`
|
|
|
|
|
|
|
|
|
|
- 将音频文件拷贝到festival文件夹
|
|
|
|
|
示例:
|
|
|
|
|
> `sudo cp -r festival/lib/voices/us/cmu_us_aew_cg/ /usr/share/festival/voices/my_voices/`
|
|
|
|
|
|
|
|
|
|
- 在配置文件中设置默认的声音
|
|
|
|
|
示例:
|
|
|
|
|
> 加入`(set! voice_default voice_cmu_indic_hin_ab_cg)`到配置文件
|
|
|
|
|
|
|
|
|
|
- 安装完成
|
|
|
|
|
|
|
|
|
|
- 相关说明网站
|
2023-01-30 22:00:27 +08:00
|
|
|
|
> 可能需要
|
2023-01-22 10:15:23 +08:00
|
|
|
|
- [wiki](https://archlinux.org/packages/community/any/festival-us/) 查看更多详细配置
|
|
|
|
|
- [官方网站](http://festvox.org/dbs/index.html)
|
|
|
|
|
- [用户手册](http://www.festvox.org/docs/manual-2.4.0/festival_toc.html)
|
|
|
|
|
|
2023-01-30 22:00:27 +08:00
|
|
|
|
</details>
|
|
|
|
|
|
2022-12-21 12:36:00 +08:00
|
|
|
|
## 配置
|
|
|
|
|
```lua
|
2023-01-14 10:37:21 +08:00
|
|
|
|
require'Trans'.setup {
|
|
|
|
|
view = {
|
2023-01-21 00:24:58 +08:00
|
|
|
|
i = 'float',
|
2023-01-14 10:37:21 +08:00
|
|
|
|
n = 'hover',
|
|
|
|
|
v = 'hover',
|
|
|
|
|
},
|
2023-01-21 00:24:58 +08:00
|
|
|
|
hover = {
|
2023-01-25 11:18:30 +08:00
|
|
|
|
width = 37,
|
|
|
|
|
height = 27,
|
2023-01-14 10:37:21 +08:00
|
|
|
|
border = 'rounded',
|
2023-01-30 20:09:57 +08:00
|
|
|
|
title = title,
|
2023-01-21 00:24:58 +08:00
|
|
|
|
keymap = {
|
|
|
|
|
pageup = '[[',
|
|
|
|
|
pagedown = ']]',
|
2023-01-21 21:13:51 +08:00
|
|
|
|
pin = '<leader>[',
|
|
|
|
|
close = '<leader>]',
|
|
|
|
|
toggle_entry = '<leader>;',
|
|
|
|
|
play = '_',
|
2023-01-10 23:37:26 +08:00
|
|
|
|
},
|
2023-01-21 00:24:58 +08:00
|
|
|
|
animation = {
|
2023-01-21 21:13:51 +08:00
|
|
|
|
-- open = 'fold',
|
|
|
|
|
-- close = 'fold',
|
|
|
|
|
open = 'slid',
|
2023-01-21 00:24:58 +08:00
|
|
|
|
close = 'slid',
|
2023-01-21 21:13:51 +08:00
|
|
|
|
interval = 12,
|
|
|
|
|
},
|
|
|
|
|
auto_close_events = {
|
|
|
|
|
'InsertEnter',
|
|
|
|
|
'CursorMoved',
|
|
|
|
|
'BufLeave',
|
|
|
|
|
},
|
2023-01-25 11:18:30 +08:00
|
|
|
|
auto_play = true,
|
2023-01-30 20:09:57 +08:00
|
|
|
|
timeout = 3000,
|
2023-01-21 00:24:58 +08:00
|
|
|
|
},
|
|
|
|
|
float = {
|
|
|
|
|
width = 0.8,
|
|
|
|
|
height = 0.8,
|
|
|
|
|
border = 'rounded',
|
2023-01-30 20:09:57 +08:00
|
|
|
|
title = title,
|
2023-01-21 00:24:58 +08:00
|
|
|
|
keymap = {
|
|
|
|
|
quit = 'q',
|
|
|
|
|
},
|
|
|
|
|
animation = {
|
|
|
|
|
open = 'fold',
|
|
|
|
|
close = 'fold',
|
|
|
|
|
interval = 10,
|
2023-01-25 11:18:30 +08:00
|
|
|
|
},
|
|
|
|
|
tag = {
|
|
|
|
|
wait = '#519aba',
|
|
|
|
|
fail = '#e46876',
|
|
|
|
|
success = '#10b981',
|
|
|
|
|
},
|
|
|
|
|
engine = {
|
|
|
|
|
'本地',
|
2023-01-21 00:24:58 +08:00
|
|
|
|
}
|
2022-12-21 12:36:00 +08:00
|
|
|
|
},
|
2023-01-25 11:18:30 +08:00
|
|
|
|
order = { -- only work on hover mode
|
2023-01-14 10:37:21 +08:00
|
|
|
|
'title',
|
|
|
|
|
'tag',
|
|
|
|
|
'pos',
|
|
|
|
|
'exchange',
|
|
|
|
|
'translation',
|
|
|
|
|
'definition',
|
2022-12-21 12:36:00 +08:00
|
|
|
|
},
|
2023-01-14 10:37:21 +08:00
|
|
|
|
icon = {
|
|
|
|
|
star = '',
|
2023-01-21 21:13:51 +08:00
|
|
|
|
notfound = ' ',
|
|
|
|
|
yes = ' ',
|
|
|
|
|
no = ''
|
2023-01-25 11:18:30 +08:00
|
|
|
|
-- star = '⭐',
|
|
|
|
|
-- notfound = '❔',
|
2023-01-21 21:13:51 +08:00
|
|
|
|
-- yes = '✔️',
|
|
|
|
|
-- no = '❌'
|
2022-12-21 12:36:00 +08:00
|
|
|
|
},
|
2023-01-30 20:09:57 +08:00
|
|
|
|
theme = 'default',
|
|
|
|
|
-- theme = 'dracula',
|
|
|
|
|
-- theme = 'tokyonight',
|
|
|
|
|
|
2023-01-14 10:37:21 +08:00
|
|
|
|
db_path = '$HOME/.vim/dict/ultimate.db',
|
2023-01-21 00:24:58 +08:00
|
|
|
|
|
2023-01-30 20:09:57 +08:00
|
|
|
|
engine = {
|
|
|
|
|
-- 目前支持hover窗口支持百度, 默认不开启
|
|
|
|
|
-- baidu = {
|
|
|
|
|
-- appid = '',
|
|
|
|
|
-- appPasswd = '',
|
|
|
|
|
-- },
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
-- TODO :
|
|
|
|
|
-- register word
|
|
|
|
|
-- history = {
|
|
|
|
|
-- -- TOOD
|
2023-01-10 23:37:26 +08:00
|
|
|
|
-- }
|
|
|
|
|
|
2023-01-30 20:09:57 +08:00
|
|
|
|
-- TODO :add online translate engine
|
|
|
|
|
}
|
2022-12-21 12:36:00 +08:00
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## 快捷键绑定
|
2022-12-21 16:59:26 +08:00
|
|
|
|
**示例:**
|
|
|
|
|
> 示例中展示, 将`mm`映射成快捷键
|
|
|
|
|
```lua
|
2023-01-10 23:37:26 +08:00
|
|
|
|
vim.keymap.set({'n', 'v'}, 'mm', '<Cmd>Translate<CR>')
|
|
|
|
|
vim.keymap.set('n', 'mi', '<Cmd>TranslateInput<CR>')
|
2022-12-21 16:59:26 +08:00
|
|
|
|
|
|
|
|
|
```
|
2022-12-21 12:36:00 +08:00
|
|
|
|
|
2022-12-21 17:05:28 +08:00
|
|
|
|
## 高亮组
|
2023-01-21 08:08:01 +08:00
|
|
|
|
> 默认定义
|
2022-12-21 17:05:28 +08:00
|
|
|
|
```lua
|
2023-01-21 08:08:01 +08:00
|
|
|
|
{
|
|
|
|
|
TransWord = {
|
|
|
|
|
fg = '#7ee787',
|
|
|
|
|
bold = true,
|
|
|
|
|
},
|
|
|
|
|
TransPhonetic = {
|
|
|
|
|
link = 'Linenr'
|
|
|
|
|
},
|
|
|
|
|
TransTitle = {
|
|
|
|
|
fg = '#0f0f15',
|
|
|
|
|
bg = '#75beff',
|
|
|
|
|
bold = true,
|
|
|
|
|
},
|
|
|
|
|
TransTitleRound = {
|
|
|
|
|
fg = '#75beff',
|
|
|
|
|
},
|
|
|
|
|
TransTag = {
|
|
|
|
|
fg = '#e5c07b',
|
|
|
|
|
},
|
|
|
|
|
TransExchange = {
|
|
|
|
|
link = 'TransTag',
|
|
|
|
|
},
|
|
|
|
|
TransPos = {
|
|
|
|
|
link = 'TransTag',
|
|
|
|
|
},
|
|
|
|
|
TransTranslation = {
|
|
|
|
|
link = 'TransWord',
|
|
|
|
|
},
|
|
|
|
|
TransDefinition = {
|
|
|
|
|
link = 'Moremsg',
|
|
|
|
|
},
|
|
|
|
|
TransWin = {
|
|
|
|
|
link = 'Normal',
|
|
|
|
|
},
|
|
|
|
|
TransBorder = {
|
|
|
|
|
link = 'FloatBorder',
|
|
|
|
|
},
|
|
|
|
|
TransCollins = {
|
|
|
|
|
fg = '#faf743',
|
|
|
|
|
bold = true,
|
|
|
|
|
},
|
|
|
|
|
TransFailed = {
|
|
|
|
|
fg = '#7aa89f',
|
|
|
|
|
},
|
|
|
|
|
}
|
2022-12-21 17:05:28 +08:00
|
|
|
|
```
|
2023-01-30 20:09:57 +08:00
|
|
|
|
|
2022-12-21 12:36:00 +08:00
|
|
|
|
## 声明
|
|
|
|
|
- 本插件词典基于[ECDICT](https://github.com/skywind3000/ECDICT)
|
|
|
|
|
|
|
|
|
|
## 感谢
|
2023-01-16 00:43:17 +08:00
|
|
|
|
- [ECDICT](https://github.com/skywind3000/ECDICT) 本地词典的提供
|
|
|
|
|
- [sqlite.lua](https://github.com/kharji/sqlite.lua) 数据库访问
|
|
|
|
|
- [T.vim](https://github.com/sicong-li/T.vim) 灵感来源
|
2022-12-21 12:36:00 +08:00
|
|
|
|
|
2023-01-20 17:06:49 +08:00
|
|
|
|
## 待办 (画大饼)
|
2023-01-21 08:26:07 +08:00
|
|
|
|
- [x] 多风格样式查询
|
|
|
|
|
- [x] 重新录制屏幕截图示例
|
|
|
|
|
- [ ] 历史查询结果保存
|
|
|
|
|
- [ ] 在线多引擎异步查询
|
|
|
|
|
- [ ] 快捷键定义
|
2023-01-22 10:15:23 +08:00
|
|
|
|
- [x] 自动读音
|
2023-01-21 08:26:07 +08:00
|
|
|
|
- [ ] `句子翻译` | `中翻英` 的支持
|