From 24a838646df8107a4f51e606cd4555238ab8a339 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E5=B0=9B?= Date: Mon, 24 Apr 2023 18:48:36 +0800 Subject: [PATCH 1/7] feat: add win wsl --- plugin/Trans.lua | 4 +++- pytts/say.py | 7 ------- 2 files changed, 3 insertions(+), 8 deletions(-) delete mode 100644 pytts/say.py diff --git a/plugin/Trans.lua b/plugin/Trans.lua index 3e45f55..5788005 100644 --- a/plugin/Trans.lua +++ b/plugin/Trans.lua @@ -24,10 +24,12 @@ string.width = api.nvim_strwidth local system = Trans.system local f = + vim.fn.has 'wsl' == 1 and 'powershell.exe -Command "Add-Type -AssemblyName System.speech;(New-Object System.Speech.Synthesis.SpeechSynthesizer).Speak(\\\"%s\\\")"' or system == 'mac' and 'say %q' or system == 'termux' and 'termux-tts-speak %q' or + system == 'win' and 'powershell.exe -Command "Add-Type -AssemblyName System.speech;(New-Object System.Speech.Synthesis.SpeechSynthesizer).Speak(\\\"%s\\\")"' or system == 'linux' and 'echo %q | festival --tts' or - 'node' .. Trans.relative_path { 'tts', 'say.js' } .. ' %q' + 'node ' .. Trans.relative_path { 'tts', 'say.js' } .. ' %q' -- 'python ' .. Trans.relative_path { 'pytts', 'say.py' } .. ' %q' -- 'powershell -Command "Add-Type –AssemblyName System.Speech; (New-Object System.Speech.Synthesis.SpeechSynthesizer).Speak([Console]::In.ReadToEnd())" | Out-File -Encoding ASCII %q' -- or 'node' .. Trans.relative_path { 'tts', 'say.js' } .. ' %q' diff --git a/pytts/say.py b/pytts/say.py deleted file mode 100644 index a03da38..0000000 --- a/pytts/say.py +++ /dev/null @@ -1,7 +0,0 @@ -import pyttsx3 -import sys - -a = pyttsx3.init() - -a.say(sys.argv[1]) -a.runAndWait() From a48caf51e11d482685271b207dd277d15eeff5cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E5=B0=9B?= Date: Mon, 24 Apr 2023 19:57:33 +0800 Subject: [PATCH 2/7] remove: node --- plugin/Trans.lua | 9 ++------- tts/package.json | 5 ----- tts/say.js | 4 ---- 3 files changed, 2 insertions(+), 16 deletions(-) delete mode 100644 tts/package.json delete mode 100644 tts/say.js diff --git a/plugin/Trans.lua b/plugin/Trans.lua index 5788005..3b00025 100644 --- a/plugin/Trans.lua +++ b/plugin/Trans.lua @@ -25,15 +25,10 @@ string.width = api.nvim_strwidth local system = Trans.system local f = vim.fn.has 'wsl' == 1 and 'powershell.exe -Command "Add-Type -AssemblyName System.speech;(New-Object System.Speech.Synthesis.SpeechSynthesizer).Speak(\\\"%s\\\")"' or + system == 'win' and 'powershell -Command "Add-Type -AssemblyName System.speech;(New-Object System.Speech.Synthesis.SpeechSynthesizer).Speak(\\\"%s\\\")"' or system == 'mac' and 'say %q' or system == 'termux' and 'termux-tts-speak %q' or - system == 'win' and 'powershell.exe -Command "Add-Type -AssemblyName System.speech;(New-Object System.Speech.Synthesis.SpeechSynthesizer).Speak(\\\"%s\\\")"' or - system == 'linux' and 'echo %q | festival --tts' or - 'node ' .. Trans.relative_path { 'tts', 'say.js' } .. ' %q' --- 'python ' .. Trans.relative_path { 'pytts', 'say.py' } .. ' %q' --- 'powershell -Command "Add-Type –AssemblyName System.Speech; (New-Object System.Speech.Synthesis.SpeechSynthesizer).Speak([Console]::In.ReadToEnd())" | Out-File -Encoding ASCII %q' --- or 'node' .. Trans.relative_path { 'tts', 'say.js' } .. ' %q' --- system == 'win' and 'powershell -Command "Add-Type –AssemblyName System.Speech; (New-Object System.Speech.Synthesis.SpeechSynthesizer).Speak([Console]::In.ReadToEnd())" | Out-File -Encoding ASCII %q' + system == 'linux' and 'echo %q | festival --tts' string.play = function(self) fn.jobstart(f:format(self)) diff --git a/tts/package.json b/tts/package.json deleted file mode 100644 index e5abbcc..0000000 --- a/tts/package.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "dependencies": { - "say": "^0.16.0" - } -} diff --git a/tts/say.js b/tts/say.js deleted file mode 100644 index 1d4298b..0000000 --- a/tts/say.js +++ /dev/null @@ -1,4 +0,0 @@ -const say = require('say') - -// console.log(word) -say.speak(process.argv.slice(2)) From ba08913b1ee1db535d1fe9696fd3e94d410ad548 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E5=B0=9B?= Date: Tue, 25 Apr 2023 13:48:52 +0800 Subject: [PATCH 3/7] feat: get_lines --- lua/Trans/core/util.lua | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/lua/Trans/core/util.lua b/lua/Trans/core/util.lua index 2b84603..0450d33 100644 --- a/lua/Trans/core/util.lua +++ b/lua/Trans/core/util.lua @@ -32,10 +32,30 @@ function M.get_select() local e = #lines lines[1] = lines[1]:sub(s_col) lines[e] = line:sub(1, e_col) - return table.concat(lines) + return table.concat(lines, '\n') end end +---Get selected text +---@return string +function M.get_lines() + local _start = vim.fn.getpos 'v' + local _end = vim.fn.getpos '.' + + if _start[2] > _end[2] then + _start, _end = _end, _start + end + + local s_row, e_row = _start[2], _end[2] + + if s_row == e_row then + return vim.fn.getline(s_row) + else + local lines = vim.fn.getline(s_row, e_row) + return table.concat(lines, "\n") + end +end + ---Get Text which need to be translated ---@param mode string ---@return string @@ -52,8 +72,8 @@ function M.get_str(mode) return fn.input '需要翻译的字符串: ' end, V = function() - print 'TODO' - return '' + api.nvim_input '' + return M.get_lines() end, })[mode]():match '^%s*(.-)%s*$' end From 377c84c146bee3e9ad110adf23eae7950efdb501 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E5=B0=9B?= Date: Fri, 12 May 2023 20:27:39 +0800 Subject: [PATCH 4/7] fix: double quote error --- plugin/Trans.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugin/Trans.lua b/plugin/Trans.lua index 3b00025..e78a7e0 100644 --- a/plugin/Trans.lua +++ b/plugin/Trans.lua @@ -31,5 +31,6 @@ local f = system == 'linux' and 'echo %q | festival --tts' string.play = function(self) - fn.jobstart(f:format(self)) + local s = string.gsub(self, "\"", " ") + fn.jobstart(f:format(s)) end From 6e02f3b1baf1151f29ac371198f6cebe43dc9466 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E5=B0=9B?= Date: Fri, 12 May 2023 20:39:46 +0800 Subject: [PATCH 5/7] fix: update exchange_map --- lua/Trans/backend/offline.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lua/Trans/backend/offline.lua b/lua/Trans/backend/offline.lua index 7880ca6..2ef618e 100644 --- a/lua/Trans/backend/offline.lua +++ b/lua/Trans/backend/offline.lua @@ -99,6 +99,8 @@ local formatter = { ['p'] = '过去式 ', ['r'] = '比较级 ', ['t'] = '最高级 ', + ['b'] = '比较级 ', + ['z'] = '最高级 ', ['s'] = '复数 ', ['d'] = '过去分词 ', ['i'] = '现在分词 ', From 871cc1e48a2c1ddc8c5aa14946263ed283ad425f Mon Sep 17 00:00:00 2001 From: xiaomo Date: Sat, 13 May 2023 18:13:32 +0800 Subject: [PATCH 6/7] refactor: wsl --- plugin/Trans.lua | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plugin/Trans.lua b/plugin/Trans.lua index e78a7e0..a4573e4 100644 --- a/plugin/Trans.lua +++ b/plugin/Trans.lua @@ -24,8 +24,7 @@ string.width = api.nvim_strwidth local system = Trans.system local f = - vim.fn.has 'wsl' == 1 and 'powershell.exe -Command "Add-Type -AssemblyName System.speech;(New-Object System.Speech.Synthesis.SpeechSynthesizer).Speak(\\\"%s\\\")"' or - system == 'win' and 'powershell -Command "Add-Type -AssemblyName System.speech;(New-Object System.Speech.Synthesis.SpeechSynthesizer).Speak(\\\"%s\\\")"' or + (vim.fn.has 'wsl' or system == 'win') and 'powershell.exe -Command "Add-Type -AssemblyName System.speech;(New-Object System.Speech.Synthesis.SpeechSynthesizer).Speak(\\\"%s\\\")"' or system == 'mac' and 'say %q' or system == 'termux' and 'termux-tts-speak %q' or system == 'linux' and 'echo %q | festival --tts' From e993dc12be4970c0301f0cac07652dcd674fe50c Mon Sep 17 00:00:00 2001 From: xiaomo Date: Sat, 13 May 2023 18:16:28 +0800 Subject: [PATCH 7/7] fix: get_select get_lines --- lua/Trans/core/util.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lua/Trans/core/util.lua b/lua/Trans/core/util.lua index 0450d33..134ff37 100644 --- a/lua/Trans/core/util.lua +++ b/lua/Trans/core/util.lua @@ -32,7 +32,7 @@ function M.get_select() local e = #lines lines[1] = lines[1]:sub(s_col) lines[e] = line:sub(1, e_col) - return table.concat(lines, '\n') + return table.concat(lines, ' ') end end @@ -52,7 +52,7 @@ function M.get_lines() return vim.fn.getline(s_row) else local lines = vim.fn.getline(s_row, e_row) - return table.concat(lines, "\n") + return table.concat(lines, " ") end end