diff --git a/lua/Trans/core/backend.lua b/lua/Trans/core/backend.lua index e95444a..677fd96 100644 --- a/lua/Trans/core/backend.lua +++ b/lua/Trans/core/backend.lua @@ -27,12 +27,11 @@ if file then file:close() end + local all_name = {} local backend_order = conf.backend_order or vim.tbl_keys(result) -for name, opts in pairs(backend_order) do - if opts.disable then - result[name] = nil - else +for _, name in ipairs(backend_order) do + if not result[name].disable then all_name[#all_name + 1] = name end end @@ -54,8 +53,8 @@ return setmetatable({ local private_opts = result[name] if private_opts then - for k, v in pairs(private_opts) do - backend[k] = v + for field, value in pairs(private_opts) do + backend[field] = value end end diff --git a/lua/Trans/core/setup.lua b/lua/Trans/core/setup.lua index 2333ebe..7f0de9d 100644 --- a/lua/Trans/core/setup.lua +++ b/lua/Trans/core/setup.lua @@ -4,6 +4,7 @@ local function set_strategy_opts(conf) local all_modes = Trans.modes local all_backends = Trans.backend.all_name + local function parse_backend(backend) if type(backend) == 'string' then return backend == '*' and all_backends or { backend } diff --git a/lua/Trans/core/translate.lua b/lua/Trans/core/translate.lua index fdaf42b..0959d69 100644 --- a/lua/Trans/core/translate.lua +++ b/lua/Trans/core/translate.lua @@ -49,24 +49,27 @@ local function do_query(data, backend) -- Hook ? end ----@type table +---@type table local strategy = { fallback = function(data) local result = data.result Trans.backend.offline.query(data) - if result.offline then return true end + if result.offline then return true end local update = data.frontend:wait() for _, backend in ipairs(data.backends) do do_query(data, backend) + local name = backend.name ---@cast backend TransBackend - while result[backend.name] == nil do + while result[name] == nil do if not update() then break end end - if result[backend.name] then return true end + if result[name] then return true end end + + return false end, --- TODO :More Strategys }