Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var bfplugin = {//never change this line
- //BabelFish compatibility:
- minBFVersion: '1.94',
- //Your plugin edit version:
- pluginVersion: '1.54',
- //Author:
- pluginAuthor: 'NettiCat, modified by Arkitk',
- //Description:
- //------------
- //Babelfish is a Firefox addon/extension working dict.leo.org and google
- //the original addon and website of NettiCat is not longer available. The latest version was 1.97.
- //It can be found using a search enginge. You still need a working definition/plugin-file like
- //this one.
- //Since the translation services were not working with the old pluginVersions, I tried
- //to modify the definitions. Google is available with the most probable translation. leo.org as
- //html-style and pure text of the first translation occurance. All other services were removed/are
- //not available anymore. The translation order cannot be changed easily in the
- //defintion/plugin-file. It is the responsibility of the addon.
- //It seems that service3 is executed 2 times by the addon. Dont know why. Therefore problems
- //of the order/priority of the translation service are likely.
- //It is possible to show more output of google-translation by changing this definition.
- //I give no support, because i am a noob programming with java script and addons. For new Verions
- //just search, maybe you are lucky ;) <
- //Display name of your service:
- service1Name: 'Google',
- service2Name: 'LeoDic_puretext',
- service3Name: 'LeoDic',
- detectionName: 'Google',
- //URL to get the text translation (enclose in outer single '' AND inner double ""):
- //placeholder for the text to translate is %s
- //placeholder for source language code is %from
- //placeholder for target language code is %to
- service1URL: '"http://translate.google.de/translate_a/t?client=t&text=%s&hl=en&sl=auto&tl=%to&ie=UTF-8&oe=UTF-8&multires=1&otf=2&ssel=0&tsel=0&uptl=%to&sc=1"',
- service2URL: '"http://dict.leo.org/%from%to/?search=%s&searchLoc=0"',
- service3URL: '"http://dict.leo.org/%from%to/?search=%s&searchLoc=0"',
- // alternativ
- //'"http://dict.leo.org/?lp=%from%to&lang=en&relink=off&search=%s"',
- //'"http://dict.leo.org/%from%to?lp=%from%to&lang=en&relink=off&search=%s"',
- //'"http://dict.leo.org/%from%to/?search=%s"';
- //http://translate.google.de/translate_a/t?client=t&text=%s&hl=en&sl=auto&tl=%to&ie=UTF-8&oe=UTF-8&multires=1&otf=2&ssel=0&tsel=0&uptl=%to&sc=1
- //service1URL: '"http://translate.google.de/translate_a/t?client=t&text=fenetre&hl=en&sl=auto&tl=de&ie=UTF-8&oe=UTF-8&multires=1&otf=2&ssel=0&tsel=0&uptl=de&sc=1"',
- //service1URL: '"http://translate.google.de/?hl=en&tab=wT#auto/%to/%s"',
- //URL to translate a whole page (enclose in outer single '' AND inner double ""):
- //placeholder for the site to translate is %url
- //placeholder for source language code is %from
- //placeholder for target language code is %to
- //placeholder for browser language code is %nl
- service1SiteURL: '"http://translate.google.com/translate?hl=%nl&langpair=%from|%to&u=%url"',
- service2SiteURL: '"http://translate.google.com/translate?hl=%nl&langpair=%from|%to&u=%url"',
- //URL to detect a language (enclose in outer single '' AND inner double ""):
- //placeholder for the text is %s
- detectionURL: '"http://translate.google.de/translate_a/t?client=t&text=%s&hl=en&sl=auto&tl=en&ie=UTF-8&oe=UTF-8&multires=1&otf=2&ssel=0&tsel=0&uptl=en&sc=1"',
- //Maximum text-length accepted by service, otherwise text is splitted:
- //service2MaxLength: 1000,
- //service5MaxLength: 300,
- //Whole page translation supports translation of secure sites (HTTPS):
- service1HTTPSSupport: 0,
- service2HTTPSSupport: 0,
- //Whole page translation cookie requirement (0=no, 1=yes, 2=if enabled only):
- service1CookieRequirement: 0,
- service2CookieRequirement: 0,
- //Post methods needed
- //service4PostParams: '"go=Search&lan1=%from&lan2=%to&word=%s"',
- //Language codes used in the service URL (with %from or %to):
- //Remove languages not supported by your service
- //Change the short language codes to those used by your service
- service1LanguageCodes : {
- 'auto' : '',
- 'AFRIKAANS' : 'af',
- 'ALBANIAN' : 'sq',
- 'AMHARIC' : 'am',
- 'ARABIC' : 'ar',
- 'ARMENIAN' : 'hy',
- 'AZERBAIJANI' : 'az',
- 'BASQUE' : 'eu',
- 'BELARUSIAN' : 'be',
- 'BENGALI' : 'bn',
- 'BIHARI' : 'bh',
- 'BULGARIAN' : 'bg',
- 'BURMESE' : 'my',
- 'CATALAN' : 'ca',
- 'CHEROKEE' : 'chr',
- 'CHINESE' : 'zh',
- 'CHINESE[S]' : 'zh-CN',
- 'CHINESE[T]' : 'zh-TW',
- 'CROATIAN' : 'hr',
- 'CZECH' : 'cs',
- 'DANISH' : 'da',
- 'DHIVEHI' : 'dv',
- 'DUTCH': 'nl',
- 'English' : 'en',
- 'ESPERANTO' : 'eo',
- 'ESTONIAN' : 'et',
- 'FILIPINO' : 'tl',
- 'FINNISH' : 'fi',
- 'French' : 'fr',
- 'GALICIAN' : 'gl',
- 'GEORGIAN' : 'ka',
- 'German' : 'de',
- 'GREEK' : 'el',
- 'GUARANI' : 'gn',
- 'GUJARATI' : 'gu',
- 'HEBREW' : 'iw',
- 'HINDI' : 'hi',
- 'HUNGARIAN' : 'hu',
- 'ICELANDIC' : 'is',
- 'INDONESIAN' : 'id',
- 'INUKTITUT' : 'iu',
- 'ITALIAN' : 'it',
- 'JAPANESE' : 'ja',
- 'KANNADA' : 'kn',
- 'KAZAKH' : 'kk',
- 'KHMER' : 'km',
- 'KOREAN' : 'ko',
- 'KURDISH': 'ku',
- 'KYRGYZ': 'ky',
- 'LAOTHIAN': 'lo',
- 'LATVIAN' : 'lv',
- 'LITHUANIAN' : 'lt',
- 'MACEDONIAN' : 'mk',
- 'MALAY' : 'ms',
- 'MALAYALAM' : 'ml',
- 'MALTESE' : 'mt',
- 'MARATHI' : 'mr',
- 'MONGOLIAN' : 'mn',
- 'NEPALI' : 'ne',
- 'NORWEGIAN' : 'no',
- 'ORIYA' : 'or',
- 'PASHTO' : 'ps',
- 'PERSIAN' : 'fa',
- 'POLISH' : 'pl',
- 'PORTUGUESE' : 'pt',
- 'PUNJABI' : 'pa',
- 'ROMANIAN' : 'ro',
- 'RUSSIAN' : 'ru',
- 'SANSKRIT' : 'sa',
- 'SERBIAN' : 'sr',
- 'SINDHI' : 'sd',
- 'SINHALESE' : 'si',
- 'SLOVAK' : 'sk',
- 'SLOVENIAN' : 'sl',
- 'SPANISH' : 'es',
- 'SWAHILI' : 'sw',
- 'SWEDISH' : 'sv',
- 'TAJIK' : 'tg',
- 'TAMIL' : 'ta',
- 'TAGALOG' : 'tl',
- 'TELUGU' : 'te',
- 'THAI' : 'th',
- 'TIBETAN' : 'bo',
- 'TURKISH' : 'tr',
- 'UKRAINIAN' : 'uk',
- 'URDU' : 'ur',
- 'UZBEK' : 'uz',
- 'UIGHUR' : 'ug',
- 'VIETNAMESE' : 'vi',
- 'UNKNOWN' : ''
- },
- service2LanguageCodes : {
- 'Chinese' : 'ch',
- 'English' : 'en',
- 'French' : 'fr',
- 'German' : 'de',
- 'Italian' : 'it',
- 'Spanish' : 'es',
- },
- service3LanguageCodes : {
- 'Chinese' : 'ch',
- 'English' : 'en',
- 'French' : 'fr',
- 'German' : 'de',
- 'Italian' : 'it',
- 'Spanish' : 'es',
- },
- //Language codes used by language detection:
- //Change the short language codes on the right to those sent by your language detection service
- detectionLanguageCodes : {
- 'AFRIKAANS' : 'af',
- 'ALBANIAN' : 'sq',
- 'AMHARIC' : 'am',
- 'ARABIC' : 'ar',
- 'ARMENIAN' : 'hy',
- 'AZERBAIJANI' : 'az',
- 'BASQUE' : 'eu',
- 'BELARUSIAN' : 'be',
- 'BENGALI' : 'bn',
- 'BIHARI' : 'bh',
- 'BULGARIAN' : 'bg',
- 'BURMESE' : 'my',
- 'CATALAN' : 'ca',
- 'CHEROKEE' : 'chr',
- 'CHINESE' : 'zh',
- 'CHINESE[S]' : 'zh-CN',
- 'CHINESE[T]' : 'zh-TW',
- 'CROATIAN' : 'hr',
- 'CZECH' : 'cs',
- 'DANISH' : 'da',
- 'DHIVEHI' : 'dv',
- 'DUTCH': 'nl',
- 'English' : 'en',
- 'ESPERANTO' : 'eo',
- 'ESTONIAN' : 'et',
- 'FILIPINO' : 'tl',
- 'FINNISH' : 'fi',
- 'French' : 'fr',
- 'GALICIAN' : 'gl',
- 'GEORGIAN' : 'ka',
- 'German' : 'de',
- 'GREEK' : 'el',
- 'GUARANI' : 'gn',
- 'GUJARATI' : 'gu',
- 'HEBREW' : 'iw',
- 'HINDI' : 'hi',
- 'HUNGARIAN' : 'hu',
- 'ICELANDIC' : 'is',
- 'INDONESIAN' : 'id',
- 'INUKTITUT' : 'iu',
- 'ITALIAN' : 'it',
- 'JAPANESE' : 'ja',
- 'KANNADA' : 'kn',
- 'KAZAKH' : 'kk',
- 'KHMER' : 'km',
- 'KOREAN' : 'ko',
- 'KURDISH': 'ku',
- 'KYRGYZ': 'ky',
- 'LAOTHIAN': 'lo',
- 'LATVIAN' : 'lv',
- 'LITHUANIAN' : 'lt',
- 'MACEDONIAN' : 'mk',
- 'MALAY' : 'ms',
- 'MALAYALAM' : 'ml',
- 'MALTESE' : 'mt',
- 'MARATHI' : 'mr',
- 'MONGOLIAN' : 'mn',
- 'NEPALI' : 'ne',
- 'NORWEGIAN' : 'no',
- 'ORIYA' : 'or',
- 'PASHTO' : 'ps',
- 'PERSIAN' : 'fa',
- 'POLISH' : 'pl',
- 'PORTUGUESE' : 'pt',
- 'PUNJABI' : 'pa',
- 'ROMANIAN' : 'ro',
- 'RUSSIAN' : 'ru',
- 'SANSKRIT' : 'sa',
- 'SERBIAN' : 'sr',
- 'SINDHI' : 'sd',
- 'SINHALESE' : 'si',
- 'SLOVAK' : 'sk',
- 'SLOVENIAN' : 'sl',
- 'SPANISH' : 'es',
- 'SWAHILI' : 'sw',
- 'SWEDISH' : 'sv',
- 'TAJIK' : 'tg',
- 'TAMIL' : 'ta',
- 'TAGALOG' : 'tl',
- 'TELUGU' : 'te',
- 'THAI' : 'th',
- 'TIBETAN' : 'bo',
- 'TURKISH' : 'tr',
- 'UKRAINIAN' : 'uk',
- 'URDU' : 'ur',
- 'UZBEK' : 'uz',
- 'UIGHUR' : 'ug',
- 'VIETNAMESE' : 'vi',
- 'UNKNOWN' : ''
- },
- service1ProcessResponse: function(response){
- // NEW
- // possible results of query
- /* // example 1
- [
- [["language","language","",""]],
- ,"en",,,,,,
- [["en"]],
- 2]
- // example 2
- [
- [["boy","garçon","",""]],
- [["noun",["boy","lad","chap","youngster"],
- [["boy",["garçon","boy","fils","gamin","jeune homme","élève"],[2],0.55225247],
- ["lad",["garçon","gars","jeune","gamin","homme","fils"],[3],0.01382537],
- ["chap",["type","garçon","bonhomme","gerçure","jeune homme","joue"],[3],0.0010172778],
- ["youngster",["enfant","jeune homme","garçon","jeune cheval"],[4],0.00053606776]]
- ]],
- "fr",
- ,
- [["boy",[5],1,0,1000,0,1,0]],
- [["garçon",4,,,""],["garçon",5,[["boy",1000,1,0],["guy",0,1,0],["fellow",0,1,0],["son",0,1,0],["boys",0,1,0]],[[0,6]],"garçon"]],
- ,
- ,
- [["fr"]],
- 3
- ]
- // example 3
- [
- [["boy , window","garçon, fenetre","",""]],,"fr",,[["boy",[4],1,0,597,0,1,0],[", window",[5],0,0,529,1,3,0]],[["garçon",4,[["boy",597,1,0],["son",0,1,0],["guy",0,1,0],["fellow",0,1,0],["boys",0,1,0]],[[0,6]],"garçon, fenetre"],[", fenetre",5,[[", window",529,0,0]],[[6,15]],""]],,,[["fr"]],13]
- */
- //your regex rules go here...
- var response=response.replace(/,,/g,",[[]],"); // ",," replace with ",[[]]," to make the response a full matrix
- response=response.replace(/,,/g,",[[]],"); // again because of odd occurance of "," example ",,,"
- var ds = response.split(']],'); // split into elements
- ds[0]=""+ds[0]; // make string again
- ds[0]=ds[0].replace(/\[/g, ''); // delete [
- ds[0]=ds[0].replace(/,\"\"/g, ''); // delete ,"",""
- ds[0]=ds[0].replace(/\]/g, ''); // delete ]
- var directtranlation=ds[0].split('","');
- if (directtranlation[0]) {
- directtranlation[0]=directtranlation[0].replace(/\"/g, '');} // delete "
- if (directtranlation[1]) {
- directtranlation[1]=directtranlation[1].replace(/\"/g, '');} // delete "
- /* ds[1]~alttr contains possible alternative source words and their translations, example output for alttr
- noun
- boy,lad,chap,youngster
- boy
- garçon,boy,fils,gamin,jeune homme,élève
- 2,0.55225247
- lad
- garçon,gars,jeune,gamin,homme,fils
- 3,0.01382537
- chap
- type,garçon,bonhomme,gerçure,jeune homme,joue
- 3,0.0010172778
- youngster
- enfant,jeune homme,garçon,jeune cheval
- 4,0.00053606776 */
- // alttr[0] type of word (noun, adjective ...
- // alttr[1] length= number of possible alternative source words, iterator i
- // alttr[3*(i-1)+2] first possible source word
- // alttr[3*(i-1)+3] first possible source word with possible translations in target language
- // alttr[3*(i-1)+4] second item = probability of first possible source word with
- // first item = unknown
- /* ds[1]=""+ds[1];
- alert(ds[0]);
- alert(ds[1]);
- var alttr = ds[1].split(',\[');
- alert(alttr);
- for( var i = 0, len = alttr.length; i < len; i++ ) {
- if( alttr[i] ) {
- alttr[i] = alttr[i].split(',');
- alttr[i] = ""+alttr[i];
- alttr[i]=alttr[i].replace(/\[/g, ''); // delete [
- alttr[i]=alttr[i].replace(/\]/g, ''); // delete ]
- alttr[i]=alttr[i].replace(/\"/g, ''); // delete "
- }
- } */
- // building simple html view
- /* if( directtranlation ) {
- response="<b>"+directtranlation[1]+"</b> - ";
- if( directtranlation ) {
- response=response+directtranlation[0];
- }
- } */
- if( directtranlation ) {
- response=directtranlation[0];
- }
- /* here addtional info (response contains addional information) should be parsed and evaluated, but results differ and i have no time to find
- a aprobiate solution, and it is not important
- response=response+"\n";response=response+"\n"+"<b>"+alttr[0]+"</b>"+"\n"; //word class
- for( var i = 0, len = alttr[1].length; i < len; i++ ) { // iterate through alternatives
- if( alttr[i] ) {
- response="<b>"+alttr[3*(i-1)+2]+"</b> - "+alttr[[3*(i-1)+4]]+" - "+alttr[[3*(i-1)+3]]+"\n";
- alert(response);
- }
- } */
- /* //other tests, not working, but for info
- javascript:alert("detection:"+detectedlang, "isReliable", 1);
- var startdelimeter='<div class="goog-inline-block goog-toolbar-button-inner-box">'; // start html-tag of translation
- var enddelimeter="</div>"; // end tag of translation
- var startindexoutput=response.lastIndexOf(startdelimeter); // corresponding start index/position
- response=response.substring(startindexoutput); // delete all text before start delimeter, for easier finding the end delimeter
- var endindexoutput=response.indexOf(enddelimeter); // end index/position
- response=response.substring(startdelimeter.length,endindexoutput); // extract translation as html (between start and end)
- javascript:alert("detection:"+response, "isLastReliable", 1); */
- return response;
- },
- service2ProcessResponse: function(response){
- // only first translation suggestion
- if(!response) {return '';}
- var startdelimeter='<div data-dz-role="result">'; // start html-tag of translation
- var enddelimeter="<h2>Weitere Treffer</h2>"; // end tag of translation
- var startindexoutput=response.lastIndexOf(startdelimeter); // corresponding start index/position
- if(startindexoutput<0) {
- startindexoutput=response.lastIndexOf('<div id="section-0" class="section results">');
- if(startindexoutput<0) {return '';} // catch error not finding delimeter
- }
- var endindexoutput=response.lastIndexOf(enddelimeter); // end index/position
- if(endindexoutput<0) {
- endindexoutput=response.lastIndexOf('<th colspan="2">Weitere Aktionen</th>');
- if(endindexoutput<0) {return '';} // catch error not finding delimeter
- }
- str = response.substring(startindexoutput,endindexoutput); // extract translation as html-format (between start and end)
- /* // not known how to get the content of %to, so extraction of htmlcode easiest way
- var targetlangdelim = str.indexOf('<td class="text" lang="');
- var targetlang='';
- if (targetlangdelim<0) {return '';}
- targetlang = str.substring(str.indexOf(targetlangdelim)+1);
- targetlang = targetlang.substring(0,targetlang.indexOf('</td>'));
- targetlang = bfplugin.leoClearHTML(targetlang);
- */
- var firsttranslation='<td class="text" lang="'; //+ "de" +'">'; // when target language is known replace "de"
- //alert("index:"+str.indexOf(firsttranslation)+" STR:"+str);
- if (str.indexOf(firsttranslation)<0){return '-';} // catch error not finding delimeter
- str = str.substring(str.indexOf(firsttranslation)+1); // first occurance of translation (source) (+1 to skip source=first finding)
- str = str.substring(str.indexOf(firsttranslation)); // first occurance of translation (target)
- str = str.substring(str.indexOf(firsttranslation),str.indexOf('</td>'));
- str = bfplugin.leoClearHTML(str); // del html tags
- str = str.replace(/, $/, ''); // delete last comma
- //str = str.replace(/(\r\n|\n|\r)/gm,""); // delete empty lines etc
- return str;
- },
- service3ProcessResponse: function(response){
- var startdelimeter='<div data-dz-role="result">'; // start html-tag of translation
- var enddelimeter="<h2>Weitere Treffer</h2>"; // end tag of translation
- var startindexoutput=response.lastIndexOf(startdelimeter); // corresponding start index/position
- var endindexoutput=response.lastIndexOf(enddelimeter); // end index/position
- str = response.substring(startindexoutput,endindexoutput); // extract translation as html (between start and end)
- //change here for other html-format
- str = str.replace(/h2/g,"h3");
- return str;
- },
- detectionProcessResponse: function(response){
- /* // OLD APPROACH
- try{
- var result = JSON.parse(String(response));
- if(!result || !result.responseData || !result.responseData.language)
- throw "error";
- }catch(e){return "";}
- return [result.responseData.language, result.responseData.isReliable, result.responseData.confidence]; */
- // NEW
- // http://translate.google.de/translate_a/t?client=t&text=fenetre&hl=en&sl=auto&tl=de&ie=UTF-8&oe=UTF-8&multires=1&otf=2&ssel=0&tsel=0&uptl=de&sc=1
- // will get
- // file "t" with:
- //[[["Fenster","fenetre","",""]],,"fr",,[["Fenster",[4],1,0,1000,0,1,0]],[["fenetre",4,[["Fenster",1000,1,0],["Fensters",0,1,0],["window",0,1,0]],[[0,7]],"fenetre"]],,,[["fr","en"]],4]
- if(!response) {return '';}
- var detectedlang=response.replace(/,,/g,",[[]],"); // ",," replace with ",[[]],"
- detectedlang=detectedlang.replace(/,,/g,",[[]],"); // again because of odd occurance of "," example ",,,"
- detectedlang=detectedlang.match(/\]\],\"(.*?)\",\[\[/g); // search for ]],"*",[[ where * is the detected language
- if (detectedlang) {
- var detectedlang=response.replace(/,,/g,",[[]],");
- var detectedlang=detectedlang.replace(/,,/g,",[[]],");
- detectedlang=detectedlang.match(/\]\],\"(.*?)\",\[\[/g);
- detectedlang=""+detectedlang; // String(detectedlang)
- //detectedlang=detectedlang.substring(4,6); // alternative zu .match
- detectedlang=detectedlang.replace(/"/g, ''); // delete "
- detectedlang=detectedlang.replace(/\[/g, ''); // delete [
- detectedlang=detectedlang.replace(/\]/g, ''); // delete ]
- detectedlang=detectedlang.replace(/,/g, ''); // delete ,
- }
- else {
- detectedlang="unknown";
- }
- alert("Detected language: "+detectedlang);
- return [detectedlang, true, 1]; // fake isReliable and fake confidence, since i have no time to extract
- },
- //User defined function
- //To use this function anywhere above you would address it with bfplugin.leoClearHTML(...)
- leoClearHTML: function(str) {
- str = str.replace(/<small>.*?<\/small>/gi, ''); // delete additional grammar hints
- str = str.replace(/<sup>.*?<\/sup>/gi, '');
- str = str.replace(/<[^>]*>/g, ''); // delete all html tags
- str = str.replace(/^\s+/,'').replace(/\s+$/,''); // delete heading and trailing spaces
- return str;
- }
- };//never change this line
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement