Skip to content
Open
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
9 changes: 5 additions & 4 deletions autoload/deepl.vim
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
" Send a translation request to deepl using curl
function! deepl#translate(input, target_lang, source_lang = "")
let cmd = "curl -sS " .. g:deepl#endpoint
let cmd = cmd .. ' -d "auth_key=' .. g:deepl#auth_key .. '"'
let cmd = cmd .. ' -d ' .. shellescape('text=' .. a:input)
let cmd = cmd .. ' -d "target_lang=' .. a:target_lang .. '"'
let json = { "text": [ a:input ], "target_lang": a:target_lang }

if a:source_lang != ""
let cmd = cmd .. ' -d "source_lang=' .. a:source_lang .. '"'
let json['source_lang'] = a:source_lang
endif

let cmd = cmd .. ' -H "Authorization: DeepL-Auth-Key ' .. g:deepl#auth_key .. '"'
let cmd = cmd .. ' --json ' .. shellescape(json_encode(json))

try
const res = json_decode(system(cmd))
return res["translations"][0]["text"]
Expand Down