Sign in to follow this  
Followers 0
AzKay

TranslateX

11 posts in this topic

#1 ·  Posted (edited)

Well, I was bored, And decided, thanks to ga_frost for the idea, To make a translator script.

I was originally going to use google translator, it seems more accurate, but its got a bot detection thingo, so It doesnt work with google, so I just used bablefish. How does it work? Look at the languages, and change the $From and $To, to the language, for example, what its set on now is english to french, "en", "fr". How do I get the translation? Highlight the text you want translated, and press Ctrl X, Then, once the tooltip at 0,0 says done, Use Ctrl V (paste), And it will paste the translated text from the highlighted text. Feedback?

EDIT::

Ok, Make a more "user friendly" version.

Now for it to work, You have to define what language. Example:

When it starts up, Press Ctrl + s And it will show you all the language codes.

Then press Ctrl + d to define which language to use.

Ctrl + x Translates. ( Note, I used control + x because its right next to Ctrl + c, So its handy'er for me, You can change it it you want.

Exit through tray.

EDIT::

Added a small error check in there, Because this is running through altavista babelfish, And that service frequently gives you an "unable to translate" error. Which kinda stuffs the script when you paste, you get code. Which would get annoying. Instead of that code, you will get an error message.

EDIT::

I cant figure anything out anymore, Bugs everywhere, Heavy.

EDIT::

Got rid of the shift error checking, and added a 1 second timeout. Might have to increase it, Might not. But 1 second seems to work for me.

(( Not, usually without the timeout, it takes alot longer to translate, and you get the source for an error message. With the timeout, it will timeout at 1 second, so you dont have

to wait 10 seconds for an error. ))

If you do get an error source, Just try again.

EDIT::

I give up. Lol. Someone can take it from here if they are bored.

EDIT::

Ok, I tryed again, and searched another translator. I found a better one, And all the errors have disappeared. *Edits Below Code*.

Feedback?

EDIT::

I added a "Save Configuration" option, So you dont have to define the language each time. ( If you use it often on the same language ).

Opt("TrayMenuMode", 1)
HotKeySet("^x", "_Func")
HotKeySet("^d", "_Define")
HotKeySet("^s", "_Table")
$oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
$Config = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\TranslatorX", "Default Language")
If $Config = "" Then
    $Language = "en_fr"
Else
    $Language = $Config
EndIf

Global $Language
$Save = TrayCreateItem("Save Configuration")
$Exit = TrayCreateItem("Exit")

While 1
$Tray = TrayGetMsg()
    Select
        Case $Tray = $Exit
            Exit
        Case $Tray = $Save
            If StringInStr($Language, "_") Then
            $Language = StringReplace($Language, "_", "&2F")
            RegWrite("HKEY_LOCAL_MACHINE\SOFTWARE\TranslatorX", "", "REG_SZ", $Language)
            EndIf
    EndSelect
    Sleep(100)
WEnd

Func _Func()
    HotKeySet("^x")
    ToolTip("Translating", 0, 0)
    Send("^c")
    $Translation = _Translate(ClipGet(), $Language)
    ClipPut($Translation)
    HotKeySet("^x", "_Func")
EndFunc

Func _Table()
MsgBox(0, "TranslatorX", " zh_en >Chinese-simp to English" _
& @CRLF & " zt_en >Chinese-trad to English" _
& @CRLF & " en_zh >English to Chinese-simp" _
& @CRLF & " en_zt >English to Chinese-trad" _
& @CRLF & " en_nl >English to Dutch" _
& @CRLF & " en_fr >English to French" _
& @CRLF & " en_de >English to German" _
& @CRLF & " en_el >English to Greek" _
& @CRLF & " en_it >English to Italian" _
& @CRLF & " en_ja >English to Japanese" _
& @CRLF & " en_ko >English to Korean" _
& @CRLF & " en_pt >English to Portuguese" _
& @CRLF & " en_ru >English to Russian" _
& @CRLF & " en_es >English to Spanish" _
& @CRLF & " nl_en >Dutch to English" _
& @CRLF & " nl_fr >Dutch to French" _
& @CRLF & " fr_nl >French to Dutch" _
& @CRLF & " fr_en >French to English" _
& @CRLF & " fr_de >French to German" _
& @CRLF & " fr_el >French to Greek" _
& @CRLF & " fr_it >French to Italian" _
& @CRLF & " fr_pt >French to Portuguese" _
& @CRLF & " fr_es >French to Spanish" _
& @CRLF & " de_en >German to English" _
& @CRLF & " de_fr >German to French" _
& @CRLF & " el_en >Greek to English" _
& @CRLF & " el_fr >Greek to French" _
& @CRLF & " it_en >Italian to English" _
& @CRLF & " it_fr >Italian to French" _
& @CRLF & " ja_en >Japanese to English" _
& @CRLF & " ko_en >Korean to English" _
& @CRLF & " pt_en >Portuguese to English" _
& @CRLF & " pt_fr >Portuguese to French" _
& @CRLF & " ru_en >Russian to English" _
& @CRLF & " es_en >Spanish to English" _
& @CRLF & " es_fr >Spanish to French")
EndFunc

Func _Define()
    $Language = InputBox("TranslatorX", "Input Language From Table", "", "", 100, 10)
EndFunc

Func _Translate($Text, $Language)
$Language = StringReplace($Language, "_", "%2F")
$oHTTP.Open("GET", "http://freetranslation.paralink.com/target.asp?actions=translate&source=" & $Text & "&dir=" & $Language)
$oHTTP.Send()
$HTMLSource = $oHTTP.Responsetext
ToolTip("Done", 0, 0)
Sleep(10)
ToolTip("")
Return _StringBetween($HTMLSource, " onfocus=""onfocus(1)"">", "</textarea>")
EndFunc

Func _StringBetween($s, $from, $to)
    $x = StringInStr($s, $from) + StringLen($from)
    $y = StringInStr(StringTrimLeft($s, $x), $to)
    Return StringMid($s, $x, $y)
EndFunc
Edited by AzKay

# MY LOVE FOR YOU... IS LIKE A TRUCK- #

Share this post


Link to post
Share on other sites



i like it. However the ctrl c didn't work for me. Worked with another hotkey though.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Nice, it's very fast. I would like to see the translated text easily in the top of my screen in a quick GUI or something. I also suggest that you rewrite this in proper spelling, because babelfish really messed up your post translating it to dutch. Enters didn't show in the pasted text either, so a quick view would sort this.

:whistle: Don't use Ctrl + X (Cut) as a hotkey, rather use Ctrl + D or Ctrl + S or something.

Edited by Manadar

Share this post


Link to post
Share on other sites

Except, Ctrl X, Doesnt cut because the HotKeySet, Steals the hotkey :whistle:. Ok, I made a more user friendly one.


# MY LOVE FOR YOU... IS LIKE A TRUCK- #

Share this post


Link to post
Share on other sites

Ok. I give up, Not, It gets errors for the url being too long, seeing as this info is all going into the url. Someone else can take over. If they want. Lol.


# MY LOVE FOR YOU... IS LIKE A TRUCK- #

Share this post


Link to post
Share on other sites

It works pretty well for me and i think it will come in handy when i need to talk to my friends in Brazil.

Thanks for sharing. :whistle:

Jason

Share this post


Link to post
Share on other sites

Hi all,

It is a very good idea to capture text and translate it on a Hotkey press.

Anyway it was not very user friendly for me so I made some changes...

Open a window with original text and translated text.

Works with F2 hot key now

Manage correctly CRLF introduced by HTML formatting.

Works with foreign characters (Text -> HTML translation) and even if several paragraph are selected.

Enjoy... While browsing select a text, press F2 then few seconds later, translation comes!

Magic...

Thanks for this very good idea.

Jérôme

translate.au3

Share this post


Link to post
Share on other sites

Nice change. Though the point of it was to use it like copy and paste.

Ctrl X, Translates it, Ctrl V pastes the translation. Thats why I didnt bother with a GUI.


# MY LOVE FOR YOU... IS LIKE A TRUCK- #

Share this post


Link to post
Share on other sites

Hey, that's pretty slick! Thanks.

I need to rename about 300 Swish FX files with spanish titles so I came here trying to find the right syntax to use for a nameless form on a translator page. Now that I've found this little nugget I can bid adios to Senor _IEFormElementGetCollection.

By the way, that's the first time I've seen winhttp.winhttprequest.5.1. I googled it and wound up at MSDN but after reading a few articles I'm still not exactly sure how it works. It is sort of like consuming web services?

Well thanks again, I'm sure it will come in handy more than once.

Share this post


Link to post
Share on other sites

Hi, great idea :whistle: , but i have one question:

How can i use the same method, and translate using Google's service?

I tried like this:

Func _Translate($Text, $Language)
    $Language = StringReplace($Language, "_", "|")
    $oHTTP.Open("GET", "http://translate.google.com/translate_t?hl=ru&text=" & $Text & "&langpair=" & $Language)
    $oHTTP.Send()
    $HTMLSource = $oHTTP.Responsetext
    ToolTip("Done", 0, 0)
    Sleep(10)
    ToolTip("")
    Return _StringBetween($HTMLSource, " onfocus=""onfocus(1)"">", "</textarea>")
EndFunc

But returned empty string (the $HTMLSource include an error message 404, that i not have a pernision).

Any one can help me please do it using Google's serivice?


Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

AutoIt is simple, subtle, elegant. © AutoIt Team

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0