NOTE 1: It is assumed that you first copied a paragraph of text into your clipboard. Here I use the translation page from English to Russian (https://translate.google.gr/?hl=el#view=home&op=translate&sl=en&tl=ru&text=) You can use another.
NOTE 2: Automatic translation programs are powerless with translation, for example, technical literature and PDFs, so the process of professional translation looks like this: 1) Copy a paragraph, 2) Paste in Google Translator, 3) Copy the resulting translation, 4) Correct the translation in a text editor, 5) Paste into the original document. Total, we have 5 steps.
NOTE 3: You can automate all steps except the 4th, of course. There are many translation programs, but they are expensive and will never give you the flexibility your own Apple-script’s gives. And, despite their high cost, many of them violate the structure of the PDF and do not make a difference in what needs to be translated and what is not necessary. For example, this topic paid “professional” program will translate along with a piece of applescript, all fucking up
set myParagragh to the clipboard as string
set Translated_Text to ""
tell application "Safari"
activate
open location "https://translate.google.gr/?hl=el#view=home&op=translate&sl=en&tl=ru&text=" & myParagragh
delay 5.0
tell document 1
repeat until the length of Translated_Text is not 0
set TextTeg to do JavaScript "document.getElementsByTagName('span')[65].innerHTML"
delay 0.5
set Translated_Text to TextTeg as text
end repeat
end tell
end tell
set Translated_Text to findAndReplaceInText(Translated_Text, "<span title=\"\">", "")
set Translated_Text to findAndReplaceInText(Translated_Text, "</span>", "")
set Translated_Text to findAndReplaceInText(Translated_Text, "</span> <span title=\"\">", "")
on findAndReplaceInText(theText, theSearchString, theReplacementString)
set AppleScript's text item delimiters to theSearchString
set theTextItems to every text item of theText
set AppleScript's text item delimiters to theReplacementString
set theText to theTextItems as string
set AppleScript's text item delimiters to ""
return theText
end findAndReplaceInText
This script only gives you the 2nd and 3rd steps of the professional translation process, but these steps is also the most necessary to create a full-fledged utility. In the future, I will publish a utility that will speed up the process of professional translation. For example, pdf