feat: add health check and update README.md

This commit is contained in:
JuanZoran 2023-03-07 22:28:41 +08:00
parent c6ad825dac
commit b2851cffd8
4 changed files with 223 additions and 163 deletions

View File

@ -28,36 +28,44 @@
> 见 wiki
- 大部分功能可以自定义:
- 高亮
- 悬浮大小
- 排版顺序
- 弹窗大小
- `舒服窗口动画`
- etc (更多可以查看[配置](#配置))
- **完全离线** 的单词翻译体验 (可能后面会支持在线翻译)
- 支持显示:
- 柯林斯星级
- 牛津 3000 词汇
- 中文翻译
- 英文翻译 (不是英译中, 而是用英文解释)
- 词根
- etc
- 舒服的排版和`动画`
- 支持 `normal``visual`模式
> <font color='#FF9900'>不支持 visual-block mode</font>
- 本地词库单词量: `430w`
## 屏幕截图
### 演示
https://user-images.githubusercontent.com/107862700/213752097-2eee026a-ddee-4531-bf80-ba2cbc8b44ef.mp4
> 视频演示的在线查询, 查询速度取决于你的网络状况
> 可以打开音量查看自动读音
https://user-images.githubusercontent.com/107862700/215941500-3293c571-20a1-44e2-b202-77079f158ce9.mp4
https://user-images.githubusercontent.com/107862700/213752097-2eee026a-ddee-4531-bf80-ba2cbc8b44ef.mp4
### 主题
> 如果你有更美观或者更适合的配色, 欢迎提 PR
@ -145,10 +153,14 @@ use {
<font color="#FF9900">**注意事项**: </font>
- **如果插件无法正常工作, 请运行**`:check Trans`, 查看插件是否安装正确并且处于正常工作环境
- `install.sh`
- 使用了 `wget`下载词库, 安装请确保你的环境变量中存在 wget
- install.sh 下载后会自动将词库解压, 并移动到 `$HOME/.vim/dict`文件夹下
- 目前仅在 `Ubuntu22.04`的环境下测试通过
> 如果上述条件不符合, 请删掉 `run = 'install.sh'`部分, 考虑手动安装词库
> 如果上述条件满足, 仍出现问题, 欢迎在 issue 里向我反馈,我会及时尝试解决
@ -156,17 +168,16 @@ use {
- 下载词典的过程中, 需要能够 `流畅的访问github下载`
> 词库文件压缩包大小为: **281M**
> 解压缩后的大小大概为: 1.2G
> 解压缩后的大小大概为: **1.2G**
- 安装后如果不能正常运行, 请尝试检查一下问题:
- 本机是否已经安装了 `sqlite3`
> Linux 下安装:
> `sudo pacman -S sqlite # Arch`
> `sudo apt-get install sqlite3 libsqlite3-dev # Ubuntu`
> 后续会增加 `healthcheck` 进行检查
- **`auto_play`** 使用步骤:
> linux 只需要安装`festival`
@ -176,6 +187,7 @@ use {
> mac 系统使用`say` (感谢[@happysmile12321](https://github.com/happysmile12321) )
> 其他操作系统
- 需要确保安装了`nodejs`
- 进入插件的`tts`目录运行`npm install`

63
lua/Trans/health.lua Normal file
View File

@ -0,0 +1,63 @@
local M = {}
M.check = function()
local health = vim.health
local ok = health.report_ok
local warn = health.report_warn
local error = health.report_error
local has = vim.fn.has
local executable = vim.fn.executable
-- INFO :Check neovim version
if has('nvim-0.9') == 1 then
ok [[
[PASS]: you have Trans.nvim with full features in neovim-nightly
]]
else
warn [[
[WARN]: Trans Title requires Neovim 0.9 or newer
See neovim-nightly: https://github.com/neovim/neovim/releases/tag/nightly
]]
end
-- INFO :Check Sqlite
local has_sqlite = pcall(require, 'sqlite')
if has_sqlite then
ok [[
[PASS]: Dependency sqlite.lua is installed
]]
else
error [[
[ERROR]: Dependency sqlite.lua can't work correctly
Please Read the doc in github carefully
]]
end
if executable('sqlite3') then
ok [[
[PASS]: Dependency sqlite3 found
]]
else
error [[
[ERROR]: Dependency sqlite3 not found
]]
end
-- INFO :Check stardict
local db_path = vim.fn.expand(require('Trans').conf.db_path)
if vim.fn.filereadable(db_path) == 1 then
ok [[
[PASS]: Stardict database found
]]
else
error [[
[PASS]: Stardict database not found
Please check the doc in github
]]
end
end
return M

View File

@ -135,16 +135,8 @@ M.conf = {
-- appPasswd = '',
-- },
},
-- TODO :
-- register word
-- history = {
-- -- TOOD
-- }
-- TODO :add online translate engine
}
local times = 0
M.setup = function(opts)
if opts then
M.conf = vim.tbl_deep_extend('force', M.conf, opts)
@ -165,29 +157,13 @@ M.setup = function(opts)
engines[i] = k
i = i + 1
end
conf.engines = engines
times = times + 1
if times == 1 then
---@format disable
local new_command = api.nvim_create_user_command
new_command('Translate' , function() M.translate() end, { desc = ' 单词翻译',})
new_command('TranslateInput' , function() M.translate('i') end, { desc = ' 搜索翻译',})
new_command('TransPlay' , function()
local word = M.get_word(api.nvim_get_mode().mode)
if word ~= '' and word:isEn() then
word:play()
end
end, { desc = ' 自动发音' })
local set_hl = api.nvim_set_hl
local hls = require('Trans.ui.theme')[conf.theme]
for hl, opt in pairs(hls) do
set_hl(0, hl, opt)
end
---@format enable
end
end
local function get_select()
@ -209,7 +185,6 @@ local function get_select()
if s_row == e_row then
return line:sub(s_col, e_col)
else
local lines = fn.getline(s_row, e_row)
local i = #lines
@ -223,11 +198,9 @@ M.get_word = function(mode)
local word
if mode == 'n' then
word = fn.expand('<cword>')
elseif mode == 'v' then
api.nvim_input('<ESC>')
word = get_select()
elseif mode == 'i' then
-- TODO Use Telescope with fuzzy finder
---@diagnostic disable-next-line: param-type-mismatch

12
plugin/Trans.lua Normal file
View File

@ -0,0 +1,12 @@
local M = require("Trans")
local api = vim.api
local command = api.nvim_create_user_command
command('Translate', function() M.translate() end, { desc = ' 单词翻译', })
command('TranslateInput', function() M.translate('i') end, { desc = ' 搜索翻译', })
command('TransPlay', function()
local word = M.get_word(api.nvim_get_mode().mode)
if word ~= '' and word:isEn() then
word:play()
end
end, { desc = ' 自动发音' })