MediaWiki:Gadget-google-translate.js

/* */ /*******************************************************************/ /* Prefills the edit field for new translations                   */ /* with the automatic Google translation of the message definition */ /* into the user's language as set in Special:Preferences         */ /*******************************************************************/ importScriptURI('http://www.google.com/jsapi'); addOnloadHook(function {  var editbox;  if (!document.editform || !(editbox = document.editform.wpTextbox1 )) return;  if (editbox.value) return;

//the seven lines below are courtesy of Sparkla. We have to use this instead of //getElemetById because the message definition element doesn't have an ID  var def = getElementsByClassName(document,'fieldset','mw-sp-translate-edit-definition'); if(def.length != 1) return; def = def[0]; var code = def.getElementsByTagName('code'); if(code.length == 0) return; code = code[0]; var text = getInnerText(code);

google.load("language", "1"); function initialize { google.language.translate(text, "", wgUserLanguage, function(result) {     if (!result.error) editbox.value = '!!FUZZY!!' + result.translation;      else alert(result.error);    }); } google.setOnLoadCallback(initialize);

//add "var gTransAutoSum = true;" to your .js page if you wish to auto-fill the summary field. if(window.gTransAutoSum) document.editform.wpSummary.value = 'translated with assistance of the Google-translate gadget'; }); /* */