From 529a1639c627c64720a46fb489c312ccfae4d57a Mon Sep 17 00:00:00 2001 From: JuanZoran <1430359574@qq.com> Date: Sat, 25 Mar 2023 09:41:06 +0800 Subject: [PATCH] chore: sync progress --- lua/Trans/backend/baidu.lua | 9 +++++---- lua/Trans/backend/offline.lua | 1 + lua/Trans/backend/youdao.lua | 9 +++++---- lua/Trans/core/backend.lua | 1 + lua/Trans/core/setup.lua | 10 +++++----- lua/Trans/frontend/hover/init.lua | 4 ++-- 6 files changed, 19 insertions(+), 15 deletions(-) diff --git a/lua/Trans/backend/baidu.lua b/lua/Trans/backend/baidu.lua index 38984c6..e01600e 100644 --- a/lua/Trans/backend/baidu.lua +++ b/lua/Trans/backend/baidu.lua @@ -5,10 +5,11 @@ ---@field app_passwd string ---@field disable boolean local M = { - uri = 'https://fanyi-api.baidu.com/api/trans/vip/translate', - salt = tostring(math.random(bit.lshift(1, 15))), - name = 'baidu', - method = 'get', + uri = 'https://fanyi-api.baidu.com/api/trans/vip/translate', + salt = tostring(math.random(bit.lshift(1, 15))), + name = 'baidu', + name_zh = '百度', + method = 'get', } diff --git a/lua/Trans/backend/offline.lua b/lua/Trans/backend/offline.lua index b3b2a46..7880ca6 100644 --- a/lua/Trans/backend/offline.lua +++ b/lua/Trans/backend/offline.lua @@ -13,6 +13,7 @@ vim.api.nvim_create_autocmd('VimLeavePre', { ---@class TransOfflineBackend local M = { name = 'offline', + name_zh = '本地', no_wait = true, } diff --git a/lua/Trans/backend/youdao.lua b/lua/Trans/backend/youdao.lua index d62961f..81f0d12 100644 --- a/lua/Trans/backend/youdao.lua +++ b/lua/Trans/backend/youdao.lua @@ -5,10 +5,11 @@ ---@field app_passwd string ---@field disable boolean local M = { - uri = 'https://openapi.youdao.com/api', - salt = tostring(math.random(bit.lshift(1, 15))), - name = 'youdao', - method = 'get', + uri = 'https://openapi.youdao.com/api', + salt = tostring(math.random(bit.lshift(1, 15))), + name = 'youdao', + name_zh = '有道', + method = 'get', } ---@class YoudaoQuery diff --git a/lua/Trans/core/backend.lua b/lua/Trans/core/backend.lua index bbb6390..e11f8fe 100644 --- a/lua/Trans/core/backend.lua +++ b/lua/Trans/core/backend.lua @@ -5,6 +5,7 @@ local Trans = require 'Trans' ---@field no_wait? boolean whether need to wait for the result ---@field all_name string[] @all backend name ---@field name string @backend name +---@field name_zh string @backend name in Chinese ---@class TransOnlineBackend: TransBackend ---@field uri string @request uri diff --git a/lua/Trans/core/setup.lua b/lua/Trans/core/setup.lua index b6673d9..f1cb675 100644 --- a/lua/Trans/core/setup.lua +++ b/lua/Trans/core/setup.lua @@ -2,7 +2,7 @@ local Trans = require 'Trans' local function set_strategy_opts(conf) local all_backends = Trans.backend.all_name - + local g_strategy = conf.strategy local function parse_backend(backend) if type(backend) == 'string' then @@ -12,19 +12,19 @@ local function set_strategy_opts(conf) return backend end - local default_strategy = conf.strategy.default + local default_strategy = g_strategy.default default_strategy.backend = parse_backend(default_strategy.backend) default_strategy.__index = default_strategy - conf.strategy.default = nil + g_strategy.default = nil - setmetatable(conf.strategy, { + setmetatable(g_strategy, { __index = function() return default_strategy end, }) - for _, strategy in pairs(conf.strategy) do + for _, strategy in pairs(g_strategy) do strategy.backend = parse_backend(strategy.backend) setmetatable(strategy, default_strategy) end diff --git a/lua/Trans/frontend/hover/init.lua b/lua/Trans/frontend/hover/init.lua index b72f8f3..1ec4071 100644 --- a/lua/Trans/frontend/hover/init.lua +++ b/lua/Trans/frontend/hover/init.lua @@ -93,7 +93,6 @@ function M:init_window(opts) animation = m_opts.animation, } - -- stylua: ignore start local win_opts = { col = opts.col or 1, row = opts.row or 1, @@ -102,7 +101,6 @@ function M:init_window(opts) height = opts.height or m_opts.height, relative = opts.relative or 'cursor', } - -- stylua: ignore end if win_opts.title then win_opts.title_pos = 'center' @@ -139,6 +137,8 @@ function M:wait() width = times, } + + -- FIXME : add proper args return function() cur = cur + 1 buffer[1] = spinner[cur % size + 1] .. (cell):rep(cur)