AutoHotkey Community

It is currently May 27th, 2012, 12:33 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 60 posts ]  Go to page Previous  1, 2, 3, 4
Author Message
 Post subject:
PostPosted: November 14th, 2011, 1:50 pm 
Offline
User avatar

Joined: May 18th, 2010, 3:10 pm
Posts: 1179
Location: Sweden
vadus wrote:
Hi. Many thanks to author of this script. Could you please modify it to Google Translate API v2 (http://code.google.com/intl/ru/apis/language/translate/v2/getting_started). Because v1 doesn't work :shock: . I cannot do it by myself.


The link does not seem to work to me, but I found this info about the payment required. ($20 per 1M characters)

I've also been working on a new GUI where you select language more easely by freetext (with helpful autocomplete), but it seems that an API v2 change is required.

It doesn't seem difficult to create a script that works with this, but I'd only put time into it if people would be willing to contribute to the cost so it'll atleast bear its' own costs. Seeing as each user would hardly require 1M translated characters it shouldn't be a major problem though. Do you think there's interest for this?

_________________
~sumon Appifyer AHK Nova halted Recommended: AHK_L (Why?)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 14th, 2011, 2:45 pm 
Offline

Joined: October 29th, 2011, 10:38 pm
Posts: 4
sumon wrote:
It doesn't seem difficult to create a script that works with this, but I'd only put time into it if people would be willing to contribute to the cost so it'll atleast bear its' own costs. Seeing as each user would hardly require 1M translated characters it shouldn't be a major problem though. Do you think there's interest for this?


I am ready to contribute to the part of cost :)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 14th, 2011, 3:31 pm 
Offline
User avatar

Joined: May 18th, 2010, 3:10 pm
Posts: 1179
Location: Sweden
vadus wrote:
sumon wrote:
It doesn't seem difficult to create a script that works with this, but I'd only put time into it if people would be willing to contribute to the cost so it'll atleast bear its' own costs. Seeing as each user would hardly require 1M translated characters it shouldn't be a major problem though. Do you think there's interest for this?


I am ready to contribute to the part of cost :)


That is encouraging!

What is discouraging, however, is this statement by Google:

Terms of Use wrote:
(When using the API, the following prohibitions apply:)

You will not sublicense an API for use by a third party. Consequently, you will not create an API Client that functions substantially the same as the API and offer it for use by third parties.


I'm not a lawyer, but this means there's no way to charge money for access to the API I sign up to Google with? I suppose donations could work legally - is there any other option? Hopefully it wouldn't be a problem, but by letting others use the API I would have to restrict the chars per day or risk paying someone else's bill. :) I think it could be really helpful so other than this I see no reason why not, but I dunno.. opinions?

_________________
~sumon Appifyer AHK Nova halted Recommended: AHK_L (Why?)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 14th, 2011, 7:14 pm 
Offline

Joined: October 29th, 2011, 10:38 pm
Posts: 4
sumon wrote:

I'm not a lawyer, but this means there's no way to charge money for access to the API I sign up to Google with? I suppose donations could work legally - is there any other option? Hopefully it wouldn't be a problem, but by letting others use the API I would have to restrict the chars per day or risk paying someone else's bill. :) I think it could be really helpful so other than this I see no reason why not, but I dunno.. opinions?


I think it's not a problem. I'll give you $10, then you present me your application :)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 16th, 2011, 1:46 am 
Offline
User avatar

Joined: May 18th, 2010, 3:10 pm
Posts: 1179
Location: Sweden
vadus wrote:
I think it's not a problem. I'll give you $10, then you present me your application :)


Hehe :)

Quick update: I've acquired the API key and set it up for usage, and modified an app I've been working on to work with this method. However, I've got a few fixes to do before I release it. I've also not yet decided on what to name the app, so ideas are welcome.

_________________
~sumon Appifyer AHK Nova halted Recommended: AHK_L (Why?)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 16th, 2011, 8:03 am 
Offline

Joined: October 29th, 2011, 10:38 pm
Posts: 4
sumon wrote:

Hehe :)

Quick update: I've acquired the API key and set it up for usage, and modified an app I've been working on to work with this method. However, I've got a few fixes to do before I release it. I've also not yet decided on what to name the app, so ideas are welcome.


It's great!
I'm waiting and thinking about the app name :roll:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 16th, 2011, 1:33 pm 
Offline

Joined: December 26th, 2010, 7:40 pm
Posts: 4172
Location: Awesometown, USA
name it something completely irrelevant, so Google never finds out :twisted:
take the MD5 hash of a meaningful name, and name it the first 6 chars of said hash :P

_________________
Autofire, AutoClick, Toggle, SpamWindow Control Tools
Recommended: AutoHotkey_L


Last edited by nimda on November 16th, 2011, 9:02 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 16th, 2011, 3:59 pm 
nimda wrote:
name it something completely irrelevant, so Google never finds out :twisted:
take the MD5 hash of a meaningful name, and name it the first 6 chars of said hash :P


Hide from Google? now that'd be something! nah i will keep it so it follows the terms of use, of course :)


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: November 17th, 2011, 11:43 pm 
Offline

Joined: April 1st, 2011, 9:32 am
Posts: 26
Hi All,

I have been writing scripts for about a month now and I'm not sure if this script that I have is relevant here, but it allows me to grab text from anything that is open (topmost active window) and put it in google translate.

Code:
#IfWinActive ahk_class MozillaUIWindowClass
#t::
   ClipTemp := Clipboard
      Send ^c
   Sleep, 1500
   Send ^{t}
   Send http://translate.google.gr
   Send {Enter}
   Sleep, 5000
   Send %Clipboard%
   Clipboard := ClipTemp
return
#IfWinActive ahk_class Chrome_WidgetWin_0
#t::
   ClipTemp := Clipboard
      Send ^c
   Sleep, 1500
   Send ^{t}
   Send http://translate.google.gr
   Send {Enter}
   Sleep, 5000
   Send %Clipboard%
   Clipboard := ClipTemp
return
#IfWinActive
#t::
   ClipTemp := Clipboard
      Send ^c
      Run, http://translate.google.gr/#en|el|%clipboard%
      Clipboard := ClipTemp


The last part is set to open up an english to greek translation when grabbing text from a window that is not the two browsers I have here but it easy to change by changing the #en|el part. Just look at the URL when you select the to and from language and it will give the two letter code.

This is part of a bigger script which I have posted:
http://www.autohotkey.com/forum/viewtopic.php?t=79017&highlight=


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 5th, 2011, 5:32 pm 
Offline
User avatar

Joined: May 18th, 2010, 3:10 pm
Posts: 1179
Location: Sweden
vadus wrote:
sumon wrote:

Hehe :)

Quick update: I've acquired the API key and set it up for usage, and modified an app I've been working on to work with this method. However, I've got a few fixes to do before I release it. I've also not yet decided on what to name the app, so ideas are welcome.


It's great!
I'm waiting and thinking about the app name :roll:


Sorry for the delay. It kinda stopped. Anyway, until I get my $t together I can share the backend URL (intended to be used with the AHK script):

See instructions at http://imgin.it/translate/ and feel free to play around in your browser or in scripting.

I have not figured how to make it autodetect source language, which would be need. You also need to make sure the input is "clean" (ask google as to what they accept - I do not know). What my backend does it that it basically takes the desired text, adds my secret API key (which is connected to my credit card, so that's why I don't just add it to my app), cleans up the result a bit, and returns a json string containing the translation info.

Things to do:
- Find out (and adapt backend PHP script) how to autodetect language and more, serverside
- Properly form (URI-encode?) the sent string, scriptside
- Parse the return string, scriptside
- Toss it all together with a nice easy-to-use GUI, scriptside (this, I have done, mostly)

Until further notice each API call is limited in characters, so you cannot parse a full page of text. I may change this if I notice the limit is too low, and if contributions come in. Note that the Google Terms of Use do not permit sublicensing, so I will rely solely on donations (no "subscription" in other words), and the fact that 5 million characters (for $20 if I recall correctly) should go quite a bit.

_________________
~sumon Appifyer AHK Nova halted Recommended: AHK_L (Why?)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 5th, 2011, 10:57 pm 
Offline

Joined: December 26th, 2010, 7:40 pm
Posts: 4172
Location: Awesometown, USA
sumon wrote:
I have not figured how to make it autodetect source language, which would be need.

Detect source language
The specific format to detect the language of a text is:
Code:
https://www.googleapis.com/language/translate/v2/detect?parameters

where parameters are any parameters to apply to the query. For details, see Working with results and Query parameter reference in the Using REST document.
Here is an example of how detect method works in the Translate API.
Code:
https://www.googleapis.com/language/translate/v2/detect?key=INSERT-YOUR-KEY&q=google+translate+is+fast
:?:

sumon wrote:
Properly form (URI-encode?) the sent string, scriptside

Code:
EncodeURL(Text) ;Uberi
{
   StringReplace, Text, Text, `%, `%25, All
   FormatInteger := A_FormatInteger, FoundPos := 0
   SetFormat, IntegerFast, Hex
   While (FoundPos := RegExMatch(Text, "[^\w-.~% ]", Char, FoundPos + 1))
      StringReplace, Text, Text, %Char%, % "%" SubStr(0 SubStr(Asc(Char), 3), -1), All
   StringReplace, Text, Text, %A_Space%, +, All
   SetFormat, IntegerFast, %FormatInteger%
   Return RegExReplace(Text, "%..", "$U0")
}
:?:


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Waiting for tool
PostPosted: December 30th, 2011, 4:45 am 
Hi, I have been following this thread for a while and I found Mikhail & Drini's .exe for translation very useful, though sadly it doesn't work anymore due to google's restrictions. I am no programmer, so I shall be really grateful if someone can produce a similar exe for use with google translate api v2. Ma be the API key can be derived form some config file, or an option to allow for the API key to be setup for the first time when the exe is run. Could that be possible ? I have been searching a lot over internet but haven't found anything close to this, and I believe it shall be very helpful to a lot of people.

You guys are doing a faboulous job, so thanks a lot for sharing these genius tools to the common public !! :D


Report this post
Top
  
Reply with quote  
PostPosted: January 23rd, 2012, 8:51 am 
Offline

Joined: December 11th, 2009, 2:41 pm
Posts: 6
Posted update


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 27th, 2012, 2:13 pm 
Offline

Joined: March 9th, 2009, 9:04 pm
Posts: 12
The improvment below seems to work on WinXP 32bit, but does not work on Win7 32bit and win7 64 bit.

"Translate("ru","en") - translates to russian, but if text already was in russian translates it to english"

I have AHK Version v1.1.05.06

Can someone please advice?

Thank you all for your hard work!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 27th, 2012, 10:10 pm 
Offline
User avatar

Joined: November 19th, 2010, 9:54 am
Posts: 184
Here is a little eye candy addon..

Image


Code:
#NoEnv
#Persistent
#SingleInstance force
SetWorkingDir %A_ScriptDir%

;--------------------------------------------------
; Translate text using translate.google.com
; after Google Translate API deprecation
;
; Ctrl+C, Ctrl+C
; Author: Mikhail Kuropyatnikov (micdelt@mail.ru),
;       Volgograd, Russia
;--------------------------------------------------

~^C:: DoublePress()

DoublePress()
{
   static pressed1 = 0
   if pressed1 and A_TimeSincePriorHotkey <= 200
   {
      pressed1 = 0
     ; Translate from any language to Russian and from Russian to English if source was in Russian
      ; Tooltip, % Translate("ru","en")
      GUIit(Translate("en","en"))
   }
   else
      pressed1 = 1
   
}

; translate to "to" language,
; if source language is "to"
; translate to "anti" language

Translate(To,Anti)
{
   UseAnti = 0
   TranslateTo := To
   if Clipboard =
       return

   UriCli := UriEncode(Clipboard)

anti_translate:
   Url := "http://translate.google.com/translate_a/t?client=x&text="
            . UriCli . "&tl=" . TranslateTo

   ; Simulate Google Chrome
   JsonTrans := UrlDownloadToVar(Url,"Mozilla/5.0 (Windows NT 6.1) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/18.6.872.0 Safari/535.2")

   ; thanks to Grey (http://forum.script-coding.com/profile.php?id=25792)
   StringReplace, JsonTrans, JsonTrans, \r\n,`r`n, All
   StringReplace, JsonTrans, JsonTrans, \", ", All
   FromLang:=JSON(JsonTrans, "src")
   ElapsedTime:=JSON(JsonTrans, "server_time")

   if (FromLang == To and TranslateTo <> Anti)
   {
      TranslateTo := Anti
      ;MsgBox % FromLang . " " . To . " " TranslateTo . " " . Anti
      goto anti_translate
   }

   Loop
   {
     Sentence:=JSON(JsonTrans, "sentences["(A_Index-1)"].trans")
     If Sentence
       TransText.=Sentence
     Else
       Break
   }
   
   ; Convert To UTF-8
   BaseFileEnc := A_FileEncoding
   FileEncoding
   FileDelete, %A_ScriptDir%\Convert.html
   FileAppend, %TransText%, %A_ScriptDir%\Convert.html
   FileEncoding, UTF-8
   FileRead TransText, %A_ScriptDir%\Convert.html
   FileDelete, %A_ScriptDir%\Convert.html
   FileEncoding, %BaseFileEnc%
   
   ; split long line to smaller lines about 40-50 symbols length
   t := RegExReplace(transText,".{40,50}(\s)","$0`n")
   
   ; ToolTip %FromLang%: %t%
   ; copy result to clipboard
   ; clipboard := t
   Return FromLang ": " t
   
}



~LButton::
ToolTip
return



UrlDownloadToVar(URL, UserAgent = "", Proxy = "", ProxyBypass = "") {
    ; Requires Windows Vista, Windows XP, Windows 2000 Professional, Windows NT Workstation 4.0,
    ; Windows Me, Windows 98, or Windows 95.
    ; Requires Internet Explorer 3.0 or later.
    pFix:=a_isunicode ? "W" : "A"
    hModule := DllCall("LoadLibrary", "Str", "wininet.dll")

    AccessType := Proxy != "" ? 3 : 1
    ;INTERNET_OPEN_TYPE_PRECONFIG                    0   // use registry configuration
    ;INTERNET_OPEN_TYPE_DIRECT                       1   // direct to net
    ;INTERNET_OPEN_TYPE_PROXY                        3   // via named proxy
    ;INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY  4   // prevent using java/script/INS

    io := DllCall("wininet\InternetOpen" . pFix
    , "Str", UserAgent ;lpszAgent
    , "UInt", AccessType
    , "Str", Proxy
    , "Str", ProxyBypass
    , "UInt", 0) ;dwFlags

    iou := DllCall("wininet\InternetOpenUrl" . pFix
    , "UInt", io
    , "Str", url
    , "Str", "" ;lpszHeaders
    , "UInt", 0 ;dwHeadersLength
    , "UInt", 0x80000000 ;dwFlags: INTERNET_FLAG_RELOAD = 0x80000000 // retrieve the original item
    , "UInt", 0) ;dwContext

    If (ErrorLevel != 0 or iou = 0) {
        DllCall("FreeLibrary", "UInt", hModule)
        return 0
    }

    VarSetCapacity(buffer, 10240, 0)
    VarSetCapacity(BytesRead, 4, 0)

    Loop
    {
        ;http://msdn.microsoft.com/library/en-us/wininet/wininet/internetreadfile.asp
        irf := DllCall("wininet\InternetReadFile", "UInt", iou, "UInt", &buffer, "UInt", 10240, "UInt", &BytesRead)
        VarSetCapacity(buffer, -1) ;to update the variable's internally-stored length

        BytesRead_ = 0 ; reset
        Loop, 4  ; Build the integer by adding up its bytes. (From ExtractInteger-function)
            BytesRead_ += *(&BytesRead + A_Index-1) << 8*(A_Index-1) ;Bytes read in this very DllCall

        ; To ensure all data is retrieved, an application must continue to call the
        ; InternetReadFile function until the function returns TRUE and the lpdwNumberOfBytesRead parameter equals zero.
        If (irf = 1 and BytesRead_ = 0)
            break
        Else ; append the buffer's contents
        {
            a_isunicode ? buffer:=StrGet(&buffer, "CP0")
            Result .= SubStr(buffer, 1, BytesRead_ * (a_isunicode ? 2 : 1))
        }

        /* optional: retrieve only a part of the file
        BytesReadTotal += BytesRead_
        If (BytesReadTotal >= 30000) ; only read the first x bytes
        break                      ; (will be a multiple of the buffer size, if the file is not smaller; trim if neccessary)
        */
    }

    DllCall("wininet\InternetCloseHandle",  "UInt", iou)
    DllCall("wininet\InternetCloseHandle",  "UInt", io)
    DllCall("FreeLibrary", "UInt", hModule)
   Return Result
}

JSON(ByRef js, s, v = "") {
   j = %js%
   Loop, Parse, s, .
   {
      p = 2
      RegExMatch(A_LoopField, "([+\-]?)([^[]+)((?:\[\d+\])*)", q)
      Loop {
         If (!p := RegExMatch(j, "(?<!\\)(""|')([^\1]+?)(?<!\\)(?-1)\s*:\s*((\{(?:[^{}]++|(?-1))*\})|(\[(?:[^[\]]++|(?-1))*\])|"
            . "(?<!\\)(""|')[^\7]*?(?<!\\)(?-1)|[+\-]?\d+(?:\.\d*)?|true|false|null?)\s*(?:,|$|\})", x, p))
            Return
         Else If (x2 == q2 or q2 == "*") {
            j = %x3%
            z += p + StrLen(x2) - 2
            If (q3 != "" and InStr(j, "[") == 1) {
               StringTrimRight, q3, q3, 1
               Loop, Parse, q3, ], [
               {
                  z += 1 + RegExMatch(SubStr(j, 2, -1), "^(?:\s*((\[(?:[^[\]]++|(?-1))*\])|(\{(?:[^{\}]++|(?-1))*\})|[^,]*?)\s*(?:,|$)){" . SubStr(A_LoopField, 1) + 1 . "}", x)
                  j = %x1%
               }
            }
            Break
         }
         Else p += StrLen(x)
      }
   }
   If v !=
   {
      vs = "
      If (RegExMatch(v, "^\s*(?:""|')*\s*([+\-]?\d+(?:\.\d*)?|true|false|null?)\s*(?:""|')*\s*$", vx)
         and (vx1 + 0 or vx1 == 0 or vx1 == "true" or vx1 == "false" or vx1 == "null" or vx1 == "nul"))
         vs := "", v := vx1
      StringReplace, v, v, ", \", All
      js := SubStr(js, 1, z := RegExMatch(js, ":\s*", zx, z) + StrLen(zx) - 1) . vs . v . vs . SubStr(js, z + StrLen(x3) + 1)
   }
   Return, j == "false" ? 0 : j == "true" ? 1 : j == "null" or j == "nul"
      ? "" : SubStr(j, 1, 1) == """" ? SubStr(j, 2, -1) : j
}

;-------------------------------------------------
; HTML encode/decode
;------------------------------------------------

StrPutVar(string, ByRef var, encoding)
{
    ; Ensure capacity.
    SizeInBytes := VarSetCapacity( var, StrPut(string, encoding)
        ; StrPut returns char count, but VarSetCapacity needs bytes.
        * ((encoding="utf-16"||encoding="cp1200") ? 2 : 1) )
    ; Copy or convert the string.
    StrPut(string, &var, encoding)
   Return SizeInBytes
}

UriEncode(str)
{
   b_Format := A_FormatInteger
   data := ""
   SetFormat,Integer,H
   SizeInBytes := StrPutVar(str,var,"utf-8")
   Loop, %SizeInBytes%
   {
   ch := NumGet(var,A_Index-1,"UChar")
   If (ch=0)
      Break
   if ((ch>0x7f) || (ch<0x30) || (ch=0x3d))
      s .= "%" . ((StrLen(c:=SubStr(ch,3))<2) ? "0" . c : c)
   Else
      s .= Chr(ch)
   }   
   SetFormat,Integer,%b_format%
   return s
}

GUIit(Text) {
   static Close
   Gui,99: Destroy
   Gui,99: +LastFound -border +AlwaysOnTop +ToolWindow -Caption
   Gui,99: Color,black
   Gui,99: Font, s20, Calibri
   Gui,99: Add, Edit, % "x" A_ScreenWidth/3 " y100 w" A_ScreenWidth/3 " H" A_ScreenHeight " cWhite ReadOnly -E0x200 -VScroll",%Text%
   Gui,99: Font, s30, Calibri
   Gui,99: Add, Text, % "x+5 y50 vClose g99GuiEscape cC23B22", ⓧ
   GuiControl, 99: Focus, Close
   WinSet, Transparent, 220
   Gui,99: Show, x0 y0 W%A_ScreenWidth% H%A_ScreenHeight%
   }

99GuiEscape:
   Gui,99: Destroy
   Return


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 60 posts ]  Go to page Previous  1, 2, 3, 4

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bing [Bot], Bon, maul.esel and 8 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group