ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

DonationCoder.com Software > FARR Plugins and Aliases

FarSubScript : Google Translate.

(1/1)

verszipo:
Since CZB's Google Translate script doesn't work anymore (because of the Google Api changes) I thought I'd make a script that loads the GoogleTranslate page in FARR with a given word.

So, here's my first attempt at it, I've used the NinjaWords script as a starting point :
Spoiler
--- Code: Javascript ---plugins["GoogleTranslate"] ={        version: "1.0",        lastChange: new Date(fso.GetFile(currentDirectory+"\\fsubscript.js").DateLastModified).toDateString(),        displayName: "GoogleTranslate",        directory: currentDirectory,        icon: currentDirectory + "\\favicon.ico",        aliasstr: "gt",        description: "Translate the word using Google Translate"}; (function (){        var js = plugins["GoogleTranslate"];        var loaded = false;        var match = false;        var match2 = false;        var loadurl = "";        js.search = function search(querykey, explicit, queryraw, querynokeyword,modifierstring,triggermethod)        {                if(!explicit) return;                 idletime = 0;                // first : match when a space is at the end of the string                match = queryraw.match(new RegExp("^"+js.aliasstr+" ([a-z,A-Z,0-9]+) ([a-z,A-Z,0-9]+) (.+) $"));                // second : match when the user presses enter                match2= queryraw.match(new RegExp("^"+js.aliasstr+" ([a-z,A-Z,0-9]+) ([a-z,A-Z,0-9]+) (.+)$"));                 if((match && match[1] && match[2] && match[3])||                  (triggermethod && match2 && match2[1] && match2[2] && match2[3]))                {                        loaded = true;                        // formated HTML must be like this :                        // http://translate.google.com/#<srclng>/<destlng>/<word>                        // you can use "auto" as srclng for autodetection                        // Example : http://translate.google.com/#auto/en/word                        if (match)                                loadurl = "http://translate.google.com/#"+match[1]+"/"+match[2]+"/"+match[3];                        else if (match2)                                loadurl = "http://translate.google.com/#"+match2[1]+"/"+match2[2]+"/"+match2[3];                        else                                loadurl = "";                        htmlViewURL(loadurl);                        showPleaseWait("Loading..");                }                else                {                        showHTML("<b>GoogleTranslate</b>\                                <br>Translate a given text using the Google Translate service\                                <br><br>\                                <br>Syntax : <b>"+js.aliasstr+" srclng destlng word</b>\                                <br><b>srclng</b> is the source language\                                <br><b>destlng</b> is the destination language\                                <br><b>word</b> is the word we want to translate\                                <br><br>Example: <b><br>"+js.aliasstr+" en de computer</b>\                                <br> this will translate the 'computer' word from english to german\                                <br><br>Note : for source language you can type <b>'auto'</b> and Google will try to detect the language\                        ");                }        };        js.setStrValue = function onSetStrValue(varname,value)        {                if(varname == "EmbeddedWb.DocumentComplete")                {                        var pl = pluginInCharge();                        if(pl == "GoogleTranslate" && loaded)                        {                                loaded = false;                                // hide the "Chrome browser" advertisment                                // hide the "Search | Images |..." toolbar                                execSafeJS(                                        "document.getElementById('gt-bbar').style.display='none';\n\                                        document.getElementById('gb').style.display='none';\                                ");                                hidePleaseWait();                        }                }        }}());

Usage :
gt source_language destination_language word <space>
or
gt source_language destination_language word <enter>

source_language can be "auto" and then Google Translate will try to detect what language it is from.

There are still some bugs in it, the most notable ones are :
- you need to press space after the word (pressing Enter doesn't do the translation)
- doesn't support multiple word translation
- sometimes the page loads without the word(s), if you delete the space and add it again then it loads correctly
- after pressing Enter at the end of the search string FARR looses focus and the editbox from GoogleTranslate page gets the focus

Note : this script requires FarSubScript, make sure you have it installed and working in FARR.

Install :
extract the content of the archive into a subfolder under the Scripts folder of FARR (for example : plugins\GoogleTranslate) and either write "goreload" in FARR (this will reload all plugins) or restart FARR.

If anybody wants to improve the script feel free to do so.

Update : now supports multiple texts in one line and you can either press space or enter after the word(s) that you want to translate.

mouser:
Thanks for sharing this!  :Thmbsup:

IT_Fan:
Doesn't work any more, got "error: No translation found..."  :(

verszipo:
Strange, for me it still works correctly, i usually test it with "gt en fr wolf " and it displays correctly (in case you didn't figure it, I love wolfs ;) )

Could you write what version of FARR and SubScript you have ?

I for one have FARR 2.213.01 (portable) and FSubScript 1.10 and am running Win8 64 and Win8.1 64.

Navigation

[0] Message Index

Go to full version