Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add win wsl #34

Merged
merged 7 commits into from
May 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lua/Trans/backend/offline.lua
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ local formatter = {
['p'] = '过去式 ',
['r'] = '比较级 ',
['t'] = '最高级 ',
['b'] = '比较级 ',
['z'] = '最高级 ',
['s'] = '复数 ',
['d'] = '过去分词 ',
['i'] = '现在分词 ',
Expand Down
26 changes: 23 additions & 3 deletions lua/Trans/core/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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, ' ')
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, " ")
end
end

---Get Text which need to be translated
---@param mode string
---@return string
Expand All @@ -52,8 +72,8 @@ function M.get_str(mode)
return fn.input '需要翻译的字符串: '
end,
V = function()
print 'TODO'
return ''
api.nvim_input '<Esc>'
return M.get_lines()
end,
})[mode]():match '^%s*(.-)%s*$'
end
Expand Down
11 changes: 4 additions & 7 deletions plugin/Trans.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,12 @@ string.width = api.nvim_strwidth

local system = Trans.system
local f =
(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' 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))
local s = string.gsub(self, "\"", " ")
fn.jobstart(f:format(s))
end
7 changes: 0 additions & 7 deletions pytts/say.py

This file was deleted.

5 changes: 0 additions & 5 deletions tts/package.json

This file was deleted.

4 changes: 0 additions & 4 deletions tts/say.js

This file was deleted.