AutoHotkey Community

It is currently May 27th, 2012, 6:12 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 60 posts ]  Go to page Previous  1, 2, 3, 4  Next
Author Message
 Post subject: awesome tool!
PostPosted: May 29th, 2010, 11:53 am 
thank you very much. this will save me so much time.

cheers! ;0) j


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: June 26th, 2010, 2:56 am 
Online

Joined: June 7th, 2008, 6:00 am
Posts: 389
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:
Code:
::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 (micdelt@mail.ru)
   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, % "&aacuteá&acircâ&acute´&aeligæ&agraveà&amp&aringå&atildeã&au"
 . "mlä&bdquo„&brvbar¦&bull•&ccedilç&cedil¸&cent¢&circˆ&copy©&curren¤&dagger†&dagger‡&deg"
 . "°&divide÷&eacuteé&ecircê&egraveè&ethð&eumlë&euro€&fnofƒ&frac12½&frac14¼&frac34¾&gt>&h"
 . "ellip…&iacuteí&icircî&iexcl¡&igraveì&iquest¿&iumlï&laquo«&ldquo“&lsaquo‹&lsquo‘&lt<&m"
 . "acr¯&mdash—&microµ&middot·&nbsp &ndash–&not¬&ntildeñ&oacuteó&ocircô&oeligœ&ograveò&or"
 . "dfª&ordmº&oslashø&otildeõ&oumlö&para¶&permil‰&plusmn±&pound£&quot""&raquo»&rdquo”&reg"
 . "®&rsaquo›&rsquo’&sbquo‚&scaronš&sect§&shy­&sup1¹&sup2²&sup3³&szligß&thornþ&tilde˜&tim"
 . "es×&trade™&uacuteú&ucircû&ugraveù&uml¨&uumlü&yacuteý&yen¥&yumlÿ"
 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):
Code:
/*
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 22nd, 2010, 5:48 am 
Offline

Joined: July 22nd, 2010, 5:43 am
Posts: 6
я тебя люблю, милостивый государь


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 22nd, 2010, 10:49 am 
Offline

Joined: March 18th, 2010, 9:12 am
Posts: 72
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 22nd, 2010, 12:12 pm 
fedtegreve wrote:
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)


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: July 22nd, 2010, 6:29 pm 
Offline

Joined: July 22nd, 2010, 5:43 am
Posts: 6
fedtegreve wrote:
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 : )


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 6th, 2010, 9:03 pm 
Offline

Joined: May 8th, 2008, 2:58 pm
Posts: 39
Location: C:\ESTONIA\adavere\RIST.rar
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? :)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 10th, 2010, 12:44 am 
Offline

Joined: May 1st, 2010, 6:01 pm
Posts: 1020
Location: England
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 10th, 2010, 1:01 am 
Offline

Joined: May 1st, 2010, 6:01 pm
Posts: 1020
Location: England
Quote:
A full list of supported languages (Ignore the hl=.. CBA to remove them all. Lol):


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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 10th, 2011, 8:33 pm 
Offline

Joined: April 8th, 2009, 7:49 pm
Posts: 6073
Location: San Diego, California
I made a mod of Wicked's version of the translation script.
http://www.autohotkey.com/forum/viewtop ... 084#365084

'cause I use copy and paste a lot.
Code:
+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 (micdelt@mail.ru)
   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, % "&aacuteá&acircâ&acute´&aeligæ&agraveà&amp&aringå&atildeã&au"
 . "mlä&bdquo„&brvbar¦&bull•&ccedilç&cedil¸&cent¢&circˆ&copy©&curren¤&dagger†&dagger‡&deg"
 . "°&divide÷&eacuteé&ecircê&egraveè&ethð&eumlë&euro€&fnofƒ&frac12½&frac14¼&frac34¾&gt>&h"
 . "ellip…&iacuteí&icircî&iexcl¡&igraveì&iquest¿&iumlï&laquo«&ldquo“&lsaquo‹&lsquo‘&lt<&m"
 . "acr¯&mdash—&microµ&middot·&nbsp &ndash–&not¬&ntildeñ&oacuteó&ocircô&oeligœ&ograveò&or"
 . "dfª&ordmº&oslashø&otildeõ&oumlö&para¶&permil‰&plusmn±&pound£&quot""&raquo»&rdquo”&reg"
 . "®&rsaquo›&rsquo’&sbquo‚&scaronš&sect§&shy­&sup1¹&sup2²&sup3³&szligß&thornþ&tilde˜&tim"
 . "es×&trade™&uacuteú&ucircû&ugraveù&uml¨&uumlü&yacuteý&yen¥&yumlÿ"
 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*$)")
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject: wow
PostPosted: February 11th, 2011, 3:58 am 
Offline

Joined: February 11th, 2011, 2:56 am
Posts: 1
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. http://www.autohotkey.com/download/AutoCorrect.ahk


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: February 17th, 2011, 4:32 am 
Offline
User avatar

Joined: May 18th, 2010, 3:10 pm
Posts: 1179
Location: Sweden
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 Appifyer AHK Nova halted Recommended: AHK_L (Why?)


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

Joined: May 18th, 2010, 3:10 pm
Posts: 1179
Location: Sweden
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

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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 16th, 2011, 2:44 pm 
Offline

Joined: June 6th, 2006, 3:19 pm
Posts: 1654
Location: Denmark
Nice!
Some minor changes makes it work on the UniCode versions:
Code:
...
;;; 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)
...

_________________
RegEx Powered Dynamic Hotstrings
COM
AutoHotkey 2


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 16th, 2011, 3:24 pm 
Offline
User avatar

Joined: May 18th, 2010, 3:10 pm
Posts: 1179
Location: Sweden
tonne wrote:
Nice!
Some minor changes makes it work on the UniCode versions:
Code:
...
;;; 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.

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


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  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Apollo, Exabot [Bot], JamixZol, Yahoo [Bot] and 17 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