From 453fecf5afe98f893864848750d628fb20312ad6 Mon Sep 17 00:00:00 2001 From: NI57721 Date: Wed, 21 Jan 2026 16:00:29 +0900 Subject: [PATCH] Update DeepL API request to match latest API changes --- autoload/deepl.vim | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/autoload/deepl.vim b/autoload/deepl.vim index 44db456..dc69645 100644 --- a/autoload/deepl.vim +++ b/autoload/deepl.vim @@ -1,14 +1,18 @@ " 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 data = #{ + \ text: [a:input], + \ target_lang: a:target_lang, + \ } if a:source_lang != "" - let cmd = cmd .. ' -d "source_lang=' .. a:source_lang .. '"' + let data.source_lang = a:source_lang endif + let cmd = "curl -sS " .. g:deepl#endpoint + let cmd = cmd .. ' -H "Authorization: DeepL-Auth-Key ' .. g:deepl#auth_key .. '"' + let cmd = cmd .. ' -H "Content-Type: application/json"' + let cmd = cmd .. ' -d ' .. shellescape(json_encode(data)) + try const res = json_decode(system(cmd)) return res["translations"][0]["text"]