Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Google translate in tooltip [Replaced by standalone app]


  • Please log in to reply
68 replies to this topic
jplaguna
  • Guests
  • Last active:
  • Joined: --
thank you very much. this will save me so much time.

cheers! ;0) j

Wicked
  • Members
  • 504 posts
  • Last active: Nov 18 2018 02:17 AM
  • Joined: 07 Jun 2008
I've updated this to use the new Json() by polyethene found here. It's a piece of a much larger script, so I'll just post the functions used as well:
::T_T::
T_T()
Return

T_T() {
   T := Input("Text", "V T30", ".")
   If(T == "")
   {
      SendInput, Cancelled.
      Return
   }
   L := Input("To language", "V T15", ".")
   If(L == "")
   {
      SendInput, Cancelled.
      Return
   }
   If(Language_List_Check(L) == False)
   {
      SendInput, Unsupported language.
      Return
   }
   S := UnHTM(UnSlashUnicode(UTF82Ansi(URL_DTF("http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=" uriEncode(Transform_Unicode(T)) "&langpair=%7C" L))))
   SetKeyDelay, 1
   Send, % String_Replace(String_Replace(String_Replace(String_Replace(json(S, "responseData.translatedText"), "!", "{!}", "All"), "^", "{^}", "All"), "&", "{&}", "All"), "$", "{$}", "All") "{Enter}"
   Return
}

;---

URL_DTF(U) {
   F := % A_Temp "\" Random_String(5) ".Tmp"
   URLDownloadToFile, % U, % F
    If(ErrorLevel == 1)
      TrayTip, Error, A problem occured during download., 3
   FileRead, R, % F
   FileDelete, % F
   Return R
}

Parse(V, S, N, D="") {
   If(N == "L")
   {
      Loop, Parse, V, % S
         I := A_Index
      Loop, Parse, V, % S
         If(A_Index == I)
            Return A_LoopField      
   }
   Else
   {
      Loop, Parse, V, % S
         If(A_Index == N)
            Return A_LoopField
   }
   Return D
}

Random_String(N) {
   Loop, % N
   {
      Random, T, 1, 2
      If(T == 1)
         Random, S, 0, 9
      Else
      {
         Random, S, 97, 122
         Transform, S, Chr, % S
      }
      R := R S
   }
   Return R
}

String_Replace(S, T, R, A="") {
	StringReplace, S, S, % T, % R, % A
	Return S
}

Input(S, O, E) {
   SendInput, % S ": "
   Input, I, %O%, %E%
   IfInString, ErrorLevel, Endkey
      SendInput, % "{Backspace " StrLen(S) + StrLen(I) + 3 "}"
   Else IfInString, ErrorLevel, Max
      SendInput, % "{Backspace " StrLen(S) + StrLen(I) + 2 "}"
   Else IfInString, ErrorLevel, Timeout
      SendInput, % "{Backspace " StrLen(S) + StrLen(I) + 2 "}"
      Return I
}

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
}

Language_List_Check(L) {
   A = af|sq|am|ar|hy|az|eu|be|bn|bh|xx-bork|bs|br|bg|km|ca|zh-CN|zh-TW|co|hr|cs|da|nl|xx-elmer|en|eo|et|fo|tl|fi|fr|fy|gl|ka|de|el|gn|gu|xx-hacker|ha|iw|hi|hu|is|id|ia|ga|it|ja|jw|kn|kk|rw|rn|xx-kilngon|ko|ku|ky|lo|la|lv|ln|lt|mk|mg|ms|ml|mt|mi|mr|mo|mn|sr-ME|ne|no|nn|oc|or|om|ps|fa|xx-pirate|pl|pt-BR|pt-PT|pa|qu|ro|rm|ru|gd|sr|sh|st|sn|sd|si|sk|sl|so|es|su|sw|sv|tg|ta|tt|te|th|ti|to|tr|tk|tw|ug|uk|ur|uz|vi|cy|xh|yi|yo|zu   
   Loop, Parse, A, |
      If(L == A_LoopField)
         Return True
   Return False
}

UTF82Ansi(zString) 
{ 
   Ansi2Unicode(zString, wString, 65001) 
   Unicode2Ansi(wString, sString, 0) 
   Return sString 
} 

Ansi2Unicode(ByRef sString, ByRef wString, CP = 0) 
{ 
     nSize := DllCall("MultiByteToWideChar" 
      , "Uint", CP 
      , "Uint", 0 
      , "Uint", &sString 
      , "int",  -1 
      , "Uint", 0 
      , "int",  0) 

   VarSetCapacity(wString, nSize * 2) 

   DllCall("MultiByteToWideChar" 
      , "Uint", CP 
      , "Uint", 0 
      , "Uint", &sString 
      , "int",  -1 
      , "Uint", &wString 
      , "int",  nSize) 
} 

Unicode2Ansi(ByRef wString, ByRef sString, CP = 0) 
{ 
     nSize := DllCall("WideCharToMultiByte" 
      , "Uint", CP 
      , "Uint", 0 
      , "Uint", &wString 
      , "int",  -1 
      , "Uint", 0 
      , "int",  0 
      , "Uint", 0 
      , "Uint", 0) 

   VarSetCapacity(sString, nSize) 

   DllCall("WideCharToMultiByte" 
      , "Uint", CP 
      , "Uint", 0 
      , "Uint", &wString 
      , "int",  -1 
      , "str",  sString 
      , "int",  nSize 
      , "Uint", 0 
      , "Uint", 0) 
}

UriEncode(str) 
{ ; v 0.3 / (w) 24.06.2008 by derRaphael / zLib-Style release 
   b_Format := A_FormatInteger 
   data := "" 
   SetFormat,Integer,H 
   Loop,Parse,str 
      if ((Asc(A_LoopField)>0x7f) || (Asc(A_LoopField)<0x30) || (asc(A_LoopField)=0x3d)) 
         data .= "%" . ((StrLen(c:=SubStr(ASC(A_LoopField),3))<2) ? "0" . c : c) 
      Else 
         data .= A_LoopField 
   SetFormat,Integer,%b_format% 
   return data 
} 

UnSlashUnicode(s)
{ 
  ; unslash unicode sequences like \u0026
  ; by Mikhail Kuropyatnikov 2009 ([email protected])
   rx = \\u([0-9a-fA-F]{4})
   pos = 0

   loop
   {
   pos := RegExMatch(s,rx,m,pos+1)
   if (pos = 0) 
      break
   StringReplace, s, s, %m%, % Chr("0x" . SubStr(m,3,4))
   }
   
   return s
}

Transform_Unicode(V) {
   C := Clipboard
   Clipboard := V
   Transform, U, Unicode
   Clipboard := C
   Return U
}

UnHTM(HTM) {
 Static HT
 IfEqual,HT,,   SetEnv,HT, % "ááââ´´ææàà&ååãã&au"
 . "mlä&bdquo„¦¦&bull•ç縸¢¢&circˆ©©¤¤&dagger†&dagger‡°"
 . "°÷÷ééêêèèððëë&euro€&fnofƒ½½¼¼¾¾>>&h"
 . "ellip…ííîî¡¡ìì¿¿ïï««&ldquo“&lsaquo‹&lsquo‘<<&m"
 . "acr¯&mdash—µµ··  &ndash–¬¬ññóóôô&oeligœòò&or"
 . "dfªººøøõõöö¶¶&permil‰±±££"""»»&rdquo”®"
 . "®&rsaquo›&rsquo’&sbquo‚&scaronš§§­­¹¹²²³³ßßþþ&tilde˜&tim"
 . "es×&trade™úúûûùù¨¨üüýý¥¥ÿÿ"
 TXT := RegExReplace( HTM,"<[^>]+>" )
 Loop, Parse, TXT, &`;
   L := "&" A_LoopField ";", R .= (!(A_Index&1)) ? ( (!InStr(R,L,1)) ? L:"" ) : ""
 StringTrimRight, R, R, 1
 Loop, Parse, R , `;
  If F := InStr( HT, A_LoopField )
    StringReplace, TXT,TXT, %A_LoopField%`;, % SubStr( HT,F+StrLen(A_LoopField), 1 ), All
  Else If ( SubStr( A_LoopField,2,1)="#" )
    StringReplace, TXT, TXT, %A_LoopField%`;, % Chr(SubStr(A_LoopField,3)), All
Return RegExReplace( TXT, "(^\s*|\s*$)")
}

For example:
T_T This sentence is written in French!.fr.
Note, you must type the . button to end the input!

Watch this video for the example!

A full list of supported languages (Ignore the hl=.. CBA to remove them all. Lol):
/*
Language List:

hl=af          Afrikaans
hl=sq          Albanian
hl=am          Amharic
hl=ar          Arabic
hl=hy          Armenian
hl=az          Azerbaijani
hl=eu          Basque
hl=be          Belarusian
hl=bn          Bengali
hl=bh          Bihari
hl=xx-bork     Bork, bork, bork!
hl=bs          Bosnian
hl=br          Breton
hl=bg          Bulgarian
hl=km          Cambodian
hl=ca          Catalan
hl=zh-CN       Chinese (Simplified)
hl=zh-TW       Chinese (Traditional)
hl=co          Corsican
hl=hr          Croatian
hl=cs          Czech
hl=da          Danish
hl=nl          Dutch
hl=xx-elmer    Elmer Fudd
hl=en          English
hl=eo          Esperanto
hl=et          Estonian
hl=fo          Faroese
hl=tl          Filipino
hl=fi          Finnish
hl=fr          French
hl=fy          Frisian
hl=gl          Galician
hl=ka          Georgian
hl=de          German
hl=el          Greek
hl=gn          Guarani
hl=gu          Gujarati
hl=xx-hacker   Hacker
hl=ha          Hausa
hl=iw          Hebrew
hl=hi          Hindi
hl=hu          Hungarian
hl=is          Icelandic
hl=id          Indonesian
hl=ia          Interlingua
hl=ga          Irish
hl=it          Italian
hl=ja          Japanese
hl=jw          Javanese
hl=kn          Kannada
hl=kk          Kazakh
hl=rw          Kinyarwanda
hl=rn          Kirundi
hl=xx-klingon  Klingon
hl=ko          Korean
hl=ku          Kurdish
hl=ky          Kyrgyz
hl=lo          Laothian
hl=la          Latin
hl=lv          Latvian
hl=ln          Lingala
hl=lt          Lithuanian
hl=mk          Macedonian
hl=mg          Malagasy
hl=ms          Malay
hl=ml          Malayalam
hl=mt          Maltese
hl=mi          Maori
hl=mr          Marathi
hl=mo          Moldavian
hl=mn          Mongolian
hl=sr-ME       Montenegrin
hl=ne          Nepali
hl=no          Norwegian
hl=nn          Norwegian (Nynorsk)
hl=oc          Occitan
hl=or          Oriya
hl=om          Oromo
hl=ps          Pashto
hl=fa          Persian
hl=xx-pirate   Pirate
hl=pl          Polish
hl=pt-BR       Portuguese (Brazil)
hl=pt-PT       Portuguese (Portugal)
hl=pa          Punjabi
hl=qu          Quechua
hl=ro          Romanian
hl=rm          Romansh
hl=ru          Russian
hl=gd          Scots Gaelic
hl=sr          Serbian
hl=sh          Serbo-Croatian
hl=st          Sesotho
hl=sn          Shona
hl=sd          Sindhi
hl=si          Sinhalese
hl=sk          Slovak
hl=sl          Slovenian
hl=so          Somali
hl=es          Spanish
hl=su          Sundanese
hl=sw          Swahili
hl=sv          Swedish
hl=tg          Tajik
hl=ta          Tamil
hl=tt          Tatar
hl=te          Telugu
hl=th          Thai
hl=ti          Tigrinya
hl=to          Tonga
hl=tr          Turkish
hl=tk          Turkmen
hl=tw          Twi
hl=ug          Uighur
hl=uk          Ukrainian
hl=ur          Urdu
hl=uz          Uzbek
hl=vi          Vietnamese
hl=cy          Welsh
hl=xh          Xhosa
hl=yi          Yiddish
hl=yo          Yoruba
hl=zu          Zulu
*/

I find it very useful for games without actual edit controls.. Where you just type a normal sentence in-game to have it translated.

psyantologist
  • Members
  • 6 posts
  • Last active: May 03 2011 10:30 PM
  • Joined: 22 Jul 2010
я тебя люблю, милостивый государь

fedtegreve
  • Members
  • 80 posts
  • Last active: Jan 28 2014 02:26 PM
  • Joined: 18 Mar 2010
Hi.
I'm using the google translator very much. A good support for translating, but I have some problems:

When I translate "Hej med dig" it is showing "sv>da"
It is danish, and should translate to english.
Where does the "sv" come from?

I'm using:
Translate("en","da") ; from English to Danish
Translate(to,anti)

/Benny

widow
  • Guests
  • Last active:
  • Joined: --

Hi.
I'm using the google translator very much. A good support for translating, but I have some problems:

When I translate "Hej med dig" it is showing "sv>da"
It is danish, and should translate to english.
Where does the "sv" come from?

I'm using:
Translate("en","da") ; from English to Danish
Translate(to,anti)

/Benny

sv = swedish

"hej med dig" = swedish (but not grammaticly correct)

psyantologist
  • Members
  • 6 posts
  • Last active: May 03 2011 10:30 PM
  • Joined: 22 Jul 2010

Hi.
I'm using the google translator very much. A good support for translating, but I have some problems:

When I translate "Hej med dig" it is showing "sv>da"
It is danish, and should translate to english.
Where does the "sv" come from?

I'm using:
Translate("en","da") ; from English to Danish
Translate(to,anti)

/Benny


It seems to be (still) set to autodetect the source language.
... reminds me of the saying that danes might believe they can speak Swedish, while swedes tend to assume they understand Danish - while it often turns out that swedes do not understand Danish and danes cannot speak Swedish : )

RIST
  • Members
  • 39 posts
  • Last active: Aug 17 2012 08:36 PM
  • Joined: 08 May 2008
i get in ahk 64bit
error: parameter #2 invalid
specifically: unicode

Line#
}

~^C:: DoublePress()

Translate(from,to)
{
if clipboard =
return

----> Transform, unicodeClipboard, Unicode

the program will exit.

:/ mb somebody can fix.
Keegi Siin ka Eestlane? :)

x79animal
  • Members
  • 1021 posts
  • Last active: May 14 2013 04:21 PM
  • Joined: 01 May 2010
yep i get same as above in autohotkey_L unicode

ive tried lots of things but gets lots of errors, such as functions within functions etc

x79animal
  • Members
  • 1021 posts
  • Last active: May 14 2013 04:21 PM
  • Joined: 01 May 2010

A full list of supported languages (Ignore the hl=.. CBA to remove them all. Lol):


is no-one aware of CTRL+H in notepad? =[

Leef_me
  • Moderators
  • 8510 posts
  • Last active: Sep 10 2015 05:50 AM
  • Joined: 08 Apr 2009
I made a mod of Wicked's version of the translation script.
<!-- m -->http://www.autohotke... ... 084#365084<!-- m -->

'cause I use copy and paste a lot.
+esc::exitapp ; to exit the script

::T_T2::
T_T(1)	; enter T_T2 to use the text on the clipboard as the 'from' text
Return

::T_T::
T_T()
Return

T_T(flag=0) {
   if flag
      T :=clipboard
   else
      T := Input("Text", "V T30", ".")
   If(T == "")
   {
      SendInput, Cancelled.
      Return
   }
   L := Input("To language", "V T15", ".")
   If(L == "")
   {
      SendInput, Cancelled.
      Return
   }
   If(Language_List_Check(L) == False)
   {
      SendInput, Unsupported language.
      Return
   }
   S := UnHTM(UnSlashUnicode(UTF82Ansi(URL_DTF("http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=" uriEncode(Transform_Unicode(T)) "&langpair=%7C" L))))
   SetKeyDelay, 1
   Send, % String_Replace(String_Replace(String_Replace(String_Replace(json(S, "responseData.translatedText"), "!", "{!}", "All"), "^", "{^}", "All"), "&", "{&}", "All"), "$", "{$}", "All") "{Enter}"
   Return
}

;---

URL_DTF(U) {
   F := % A_Temp "\" Random_String(5) ".Tmp"
   URLDownloadToFile, % U, % F
    If(ErrorLevel == 1)
      TrayTip, Error, A problem occured during download., 3
   FileRead, R, % F
   FileDelete, % F
   Return R
}

Parse(V, S, N, D="") {
   If(N == "L")
   {
      Loop, Parse, V, % S
         I := A_Index
      Loop, Parse, V, % S
         If(A_Index == I)
            Return A_LoopField     
   }
   Else
   {
      Loop, Parse, V, % S
         If(A_Index == N)
            Return A_LoopField
   }
   Return D
}

Random_String(N) {
   Loop, % N
   {
      Random, T, 1, 2
      If(T == 1)
         Random, S, 0, 9
      Else
      {
         Random, S, 97, 122
         Transform, S, Chr, % S
      }
      R := R S
   }
   Return R
}

String_Replace(S, T, R, A="") {
   StringReplace, S, S, % T, % R, % A
   Return S
}

Input(S, O, E) {
   SendInput, % S ": "
   Input, I, %O%, %E%
   IfInString, ErrorLevel, Endkey
      SendInput, % "{Backspace " StrLen(S) + StrLen(I) + 3 "}"
   Else IfInString, ErrorLevel, Max
      SendInput, % "{Backspace " StrLen(S) + StrLen(I) + 2 "}"
   Else IfInString, ErrorLevel, Timeout
      SendInput, % "{Backspace " StrLen(S) + StrLen(I) + 2 "}"
      Return I
}

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
}

Language_List_Check(L) {
   A = af|sq|am|ar|hy|az|eu|be|bn|bh|xx-bork|bs|br|bg|km|ca|zh-CN|zh-TW|co|hr|cs|da|nl|xx-elmer|en|eo|et|fo|tl|fi|fr|fy|gl|ka|de|el|gn|gu|xx-hacker|ha|iw|hi|hu|is|id|ia|ga|it|ja|jw|kn|kk|rw|rn|xx-kilngon|ko|ku|ky|lo|la|lv|ln|lt|mk|mg|ms|ml|mt|mi|mr|mo|mn|sr-ME|ne|no|nn|oc|or|om|ps|fa|xx-pirate|pl|pt-BR|pt-PT|pa|qu|ro|rm|ru|gd|sr|sh|st|sn|sd|si|sk|sl|so|es|su|sw|sv|tg|ta|tt|te|th|ti|to|tr|tk|tw|ug|uk|ur|uz|vi|cy|xh|yi|yo|zu   
   Loop, Parse, A, |
      If(L == A_LoopField)
         Return True
   Return False
}

UTF82Ansi(zString)
{
   Ansi2Unicode(zString, wString, 65001)
   Unicode2Ansi(wString, sString, 0)
   Return sString
}

Ansi2Unicode(ByRef sString, ByRef wString, CP = 0)
{
     nSize := DllCall("MultiByteToWideChar"
      , "Uint", CP
      , "Uint", 0
      , "Uint", &sString
      , "int",  -1
      , "Uint", 0
      , "int",  0)

   VarSetCapacity(wString, nSize * 2)

   DllCall("MultiByteToWideChar"
      , "Uint", CP
      , "Uint", 0
      , "Uint", &sString
      , "int",  -1
      , "Uint", &wString
      , "int",  nSize)
}

Unicode2Ansi(ByRef wString, ByRef sString, CP = 0)
{
     nSize := DllCall("WideCharToMultiByte"
      , "Uint", CP
      , "Uint", 0
      , "Uint", &wString
      , "int",  -1
      , "Uint", 0
      , "int",  0
      , "Uint", 0
      , "Uint", 0)

   VarSetCapacity(sString, nSize)

   DllCall("WideCharToMultiByte"
      , "Uint", CP
      , "Uint", 0
      , "Uint", &wString
      , "int",  -1
      , "str",  sString
      , "int",  nSize
      , "Uint", 0
      , "Uint", 0)
}

UriEncode(str)
{ ; v 0.3 / (w) 24.06.2008 by derRaphael / zLib-Style release
   b_Format := A_FormatInteger
   data := ""
   SetFormat,Integer,H
   Loop,Parse,str
      if ((Asc(A_LoopField)>0x7f) || (Asc(A_LoopField)<0x30) || (asc(A_LoopField)=0x3d))
         data .= "%" . ((StrLen(c:=SubStr(ASC(A_LoopField),3))<2) ? "0" . c : c)
      Else
         data .= A_LoopField
   SetFormat,Integer,%b_format%
   return data
}

UnSlashUnicode(s)
{
  ; unslash unicode sequences like \u0026
  ; by Mikhail Kuropyatnikov 2009 ([email protected])
   rx = \\u([0-9a-fA-F]{4})
   pos = 0

   loop
   {
   pos := RegExMatch(s,rx,m,pos+1)
   if (pos = 0)
      break
   StringReplace, s, s, %m%, % Chr("0x" . SubStr(m,3,4))
   }
   
   return s
}

Transform_Unicode(V) {
   C := Clipboard
   Clipboard := V
   Transform, U, Unicode
   Clipboard := C
   Return U
}

UnHTM(HTM) {
 Static HT
 IfEqual,HT,,   SetEnv,HT, % "ááââ´´ææàà&ååãã&au"
 . "mlä&bdquo„¦¦&bull•ç縸¢¢&circˆ©©¤¤&dagger†&dagger‡°"
 . "°÷÷ééêêèèððëë&euro€&fnofƒ½½¼¼¾¾>>&h"
 . "ellip…ííîî¡¡ìì¿¿ïï««&ldquo“&lsaquo‹&lsquo‘<<&m"
 . "acr¯&mdash—µµ··  &ndash–¬¬ññóóôô&oeligœòò&or"
 . "dfªººøøõõöö¶¶&permil‰±±££"""»»&rdquo”®"
 . "®&rsaquo›&rsquo’&sbquo‚&scaronš§§­­¹¹²²³³ßßþþ&tilde˜&tim"
 . "es×&trade™úúûûùù¨¨üüýý¥¥ÿÿ"
 TXT := RegExReplace( HTM,"<[^>]+>" )
 Loop, Parse, TXT, &`;
   L := "&" A_LoopField ";", R .= (!(A_Index&1)) ? ( (!InStr(R,L,1)) ? L:"" ) : ""
 StringTrimRight, R, R, 1
 Loop, Parse, R , `;
  If F := InStr( HT, A_LoopField )
    StringReplace, TXT,TXT, %A_LoopField%`;, % SubStr( HT,F+StrLen(A_LoopField), 1 ), All
  Else If ( SubStr( A_LoopField,2,1)="#" )
    StringReplace, TXT, TXT, %A_LoopField%`;, % Chr(SubStr(A_LoopField,3)), All
Return RegExReplace( TXT, "(^\s*|\s*$)")
}


betojf
  • Members
  • 1 posts
  • Last active: Feb 20 2011 09:31 PM
  • Joined: 11 Feb 2011
wow thanks so much, registered to thank you for this!

offtopic: I have a spanish autocorrect .txt file that I would like to put on the site like the english one, it is 643 words. <!-- m -->http://www.autohotke...AutoCorrect.ahk<!-- m -->

sumon
  • Moderators
  • 1317 posts
  • Last active: Dec 05 2016 10:14 PM
  • Joined: 18 May 2010
Working on a branch of this, but I would like help with two things:

I want to list all the languages smoothly with the info (en) English, maybe sort it alphabetically and also store it's alphabetical number (for my DropDownlist). What's the best way to do this?

Work-in-progress.

EDIT: Saw the above posted full list of languages :)
EDIT2:

I have a list of all languages and codes now, you just need to parse it with | as a delimiter. All languages should be there now, although some are named non-perfectly (such as "NorwegianNynorsk" instead of "Norwegian (Nynorsk)"

You can find the list HERE

sumon
  • Moderators
  • 1317 posts
  • Last active: Dec 05 2016 10:14 PM
  • Joined: 18 May 2010
Branch is now finished, it has:

- SETTINGS (Language Picker)
- GUI
- Supports all (!) languages

To implement: Faster languageselection, maybe if you go Ctrl+C(x3) you get an InputBox asking for language to translate to?

Download the AHK file HERE

tonne
  • Members
  • 1654 posts
  • Last active: May 06 2014 06:22 PM
  • Joined: 06 Jun 2006
Nice!
Some minor changes makes it work on the UniCode versions:
...
;;; tonne, transform Unicode is not supported (nor needed) in unicode version
;  Transform, unicodeClipboard, Unicode
;;; tonne, save for later reference
   unicodeClipboard := clipboard

anti_translate:
   url := "http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q="
            . uriEncode(unicodeClipboard) . "&langpair=%7C" . translate_to
            
   ; simulate UrlDownloadToVAR
   UrlDownloadToFile, %url%, %A_ScriptDir%\translate.html
;;; tonne, added *p65001 to read UTF8
   FileRead, json_trans, *p65001 %A_ScriptDir%\translate.html
;;; tonne, skip conversion
;  json_trans := UTF82Ansi(json_trans)
...


sumon
  • Moderators
  • 1317 posts
  • Last active: Dec 05 2016 10:14 PM
  • Joined: 18 May 2010

Nice!
Some minor changes makes it work on the UniCode versions:

...
;;; tonne, transform Unicode is not supported (nor needed) in unicode version
;  Transform, unicodeClipboard, Unicode
;;; tonne, save for later reference
   unicodeClipboard := clipboard

anti_translate:
   url := "http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q="
            . uriEncode(unicodeClipboard) . "&langpair=%7C" . translate_to
            
   ; simulate UrlDownloadToVAR
   UrlDownloadToFile, %url%, %A_ScriptDir%\translate.html
;;; tonne, added *p65001 to read UTF8
   FileRead, json_trans, *p65001 %A_ScriptDir%\translate.html
;;; tonne, skip conversion
;  json_trans := UTF82Ansi(json_trans)
...


Thanks a tonne, tonne. However, it didn't seem to work. I lose my åäö's when I do this, causing malfunction in the translation (doesn't seem åäö's get sent to google, even). Was your modification in reply to my modification, or someone else's? The code is Here around line 92 and forth.

I realized this halted in development for me, I think I can do something really pretty off this.