Untitled

ah
mail@pastecode.io avatar
unknown
plain_text
2 years ago
896 B
2
Indexable
Never
^+T::
    Send, ^c
    Clipboard = 
    ClipWait
    If ErrorLevel
        {
            MsgBox, No text was selected.
            return
        }
    translatedText := ""
    URL := "https://translate.google.com/translate_a/single?client=gtx&sl=auto&tl=en&dt=t&q=" . Clipboard
    HTML := ""
    URLDownloadToVar, HTML, %URL%
    StringReplace, HTML, HTML, , `n, All
    StringReplace, HTML, HTML, , , All
    Loop, Parse, HTML, `n
    {
        If InStr(A_LoopField, """translatedText"":")
            {
                StringReplace, translatedText, A_LoopField, """translatedText"":""", """
                StringReplace, translatedText, translatedText, """", """
                Break
            }
    }
    If translatedText = ""
        {
            MsgBox, Translation failed.
            return
        }
    MsgBox, %translatedText%
    return