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();
}
}
}
}());