I’ve created a snippet that translates the text in clipboard to another language using Google Translate API:
set endpoint to "https://translation.googleapis.com/language/translate/v2?key=YOUR-GOOGLE-API-KEY"
-- Get clipboard text
set textToTranslate to the clipboard
-- Remove single quotes from textToTranslate
set AppleScript's text item delimiters to "'"
set the textItems to text items of textToTranslate
set AppleScript's text item delimiters to ""
set textToTranslate to textItems as string
-- Make the API call using curl
set translatedText to do shell script "
curl -s -X POST '" & endpoint & "' \\
-H 'Content-Type: application/json' \\
-d '{
\"q\": \"" & textToTranslate & "\",
\"target\": \"pt-BR\"
}' | /opt/homebrew/bin/jq -r '.data.translations[0].translatedText'
"
return translatedText