Utilisateur:Dr Brains/LinkTranslate.js

Note : après avoir enregistré la page, vous devrez forcer le rechargement complet du cache de votre navigateur pour voir les changements.

Mozilla / Firefox / Konqueror / Safari : maintenez la touche Majuscule (Shift) en cliquant sur le bouton Actualiser (Reload) ou pressez Maj-Ctrl-R (Cmd-R sur Apple Mac) ;

Firefox (sur GNU/Linux) / Chrome / Internet Explorer / Opera : maintenez la touche Ctrl en cliquant sur le bouton Actualiser ou pressez Ctrl-F5.
//<source lang=javascript>
//<pre><nowiki>
/*
Fonction : traduire un article à partir des correspondances interwiki.

* OK : Traduction des liens
* OK : Traduction des modèles (todo : traduire les noms des paramètres, au moins pour les modèles bibliographiques)
* todo : Traduction des catégories
* todo : Traduction des images (namespace);

*/

// ---------------------------- VARIABLES ----------------------------------- //

var LinkTranslate_SubPagePath = "/Traduction/Encours"

var LinkTranslate_AllLanguages = new Array();
LinkTranslate_AllLanguages.push("de");
LinkTranslate_AllLanguages.push("en");
LinkTranslate_AllLanguages.push("es");
LinkTranslate_AllLanguages.push("fr");
LinkTranslate_AllLanguages.push("it");
LinkTranslate_AllLanguages.push("pt");
LinkTranslate_AllLanguages.push("ru");

var LinkTranslate_DefaultLanguage = "fr";

// ---------------------------- FONCTIONS ----------------------------------- //

///////////////// AJAX ////////////////////////////////////

var LinkTranslate_ajax = {
  http:function(bundle){ var xmlhttp; try{ xmlhttp = new XMLHttpRequest(); }catch(e){ try{ xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }catch(e){ try{ xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }catch(e){ xmlhttp = false; }}}; if(xmlhttp){ xmlhttp.onreadystatechange = function(){ if (xmlhttp.readyState == 4){ LinkTranslate_ajax.httpComplete(xmlhttp,bundle);}}; xmlhttp.open(bundle.method ? bundle.method : "GET",bundle.url,bundle.async == false ? false : true); if (bundle.headers) { for (var field in bundle.headers){ try{ xmlhttp.setRequestHeader(field,bundle.headers[field]); }catch(err){}}}; xmlhttp.send(bundle.data ? bundle.data : null); }; return xmlhttp;}, 
  httpComplete: function(xmlhttp,bundle){ if(xmlhttp.status == 200 || xmlhttp.status == 302){ if(bundle.onSuccess) bundle.onSuccess(xmlhttp,bundle); }else if(bundle.onFailure){ bundle.onFailure(xmlhttp,bundle); }else{ }}
};

///////////////// LANCEMENT ////////////////////////////////////

if((mw.config.get('wgNamespaceNumber')>-1)&&((mw.config.get('wgAction')=="view")||(mw.config.get('wgAction')=="purge"))){
     addOnloadHook(LinkTranslate_AddLink);
}

///////////////// CREATION LIEN ////////////////////////////////////

function LinkTranslate_AddLink(){
     var Titre = document.getElementById("firstHeading");
     if(!Titre) Titre = document.getElementsByTagName('h1')[0];
     if(!Titre) return;

     if(typeof(LinkTranslate_UserCustom)=="function") LinkTranslate_UserCustom();

     var Small = document.createElement("small");
     var Link = document.createElement("a");
     Link.title="Afficher le menu de traduction";
     Link.href="javascript:LinkTranslate_MakeMenu();";
     Link.innerHTML = "Traduire";
     Small.setAttribute("style", "text-size:50% !important");
     Small.appendChild(Link);     
     Titre.appendChild(document.createTextNode(" "));
     Titre.appendChild(Small);
     //LinkTranslate_MakeMenu();
}

///////////////// CREATION MENU ////////////////////////////////////

function LinkTranslate_MakeMenu(){
     if(document.getElementById("LinkTranslate_Menu")) return;

     var Titre = document.getElementById("firstHeading");
     if(!Titre) Titre = document.getElementsByTagName('h1')[0];
     if(!Titre) return;

     var MenuPages = document.createElement('div');
     MenuPages.id = "LinkTranslate_Menu";

     var CurrentLanguage = document.getElementsByTagName('html')[0].getAttribute('lang');

     var LangToTranslate = document.createElement("select");
     LangToTranslate.id = "LangToTranslate_Select";
     LangToTranslate.title = "Langue d'origine";
     var LangToTranslateOption = document.createElement('option');
     LangToTranslateOption.value = CurrentLanguage;
     LangToTranslateOption.innerHTML = CurrentLanguage;
     LangToTranslateOption.disabled = "disabled";
     LangToTranslateOption.selected = "selected";
     LangToTranslate.appendChild(LangToTranslateOption);


     var PageToTranslate = document.createElement("input");
     PageToTranslate.type = "text";
     PageToTranslate.size = 50;
     PageToTranslate.id = "PageToTranslate_Input";
     PageToTranslate.title = "Page d'origine";
     PageToTranslate.value = mw.config.get('wgPageName').replace(/_/g, " ");
     PageToTranslate.onkeyup = function(){
          LinkTranslate_GetSuggest();
     }

     var TranslatedLang = document.createElement("select");
     TranslatedLang.id = "TranslatedLang_Select";
     TranslatedLang.title = "Langue d'arrivée";
     for(var a=0;a<LinkTranslate_AllLanguages.length;a++){
          if(LinkTranslate_AllLanguages[a]!=CurrentLanguage){
               var NewOption = document.createElement('option');
               NewOption.value = LinkTranslate_AllLanguages[a];
               NewOption.innerHTML = LinkTranslate_AllLanguages[a];
               if(LinkTranslate_AllLanguages[a]==LinkTranslate_DefaultLanguage) NewOption.selected = "selected";
               TranslatedLang.appendChild(NewOption);
          }
     }


     var TranslatedPage = document.createElement("input");
     TranslatedPage.type = "text";
     TranslatedPage.size = 50;
     TranslatedPage.id = "TranslatedPage_Input";
     TranslatedPage.title = "Page d'arrivée";
     TranslatedPage.value = mw.config.get('wgFormattedNamespaces')[2]+":"+mw.config.get('wgUserName')+LinkTranslate_SubPagePath

     var OKInput = document.createElement("input");
     OKInput.type = "button";
     OKInput.value = "Valider";
     OKInput.onclick = function(){ LinkTranslate_CheckMenu(); };
     OKInput.onselect = function(){ LinkTranslate_CheckMenu(); };

     var CancelInput = document.createElement("input");
     CancelInput.type = "button";
     CancelInput.value = "Annuler";
     CancelInput.onclick = function(){ LinkTranslate_HideMenu(); };
     CancelInput.onselect = function(){ LinkTranslate_HideMenu(); };


     var ControlPanel = document.createElement("div");
     ControlPanel.id = "MenuControlPanel";

     MenuPages.appendChild(LangToTranslate);
     MenuPages.appendChild(PageToTranslate);
     MenuPages.appendChild(document.createElement("br"));
     MenuPages.appendChild(TranslatedLang);
     MenuPages.appendChild(TranslatedPage);
     MenuPages.appendChild(document.createElement("br"));
     MenuPages.appendChild(OKInput);
     MenuPages.appendChild(CancelInput);
     MenuPages.appendChild(ControlPanel);

     Titre.parentNode.insertBefore(MenuPages, Titre.nextSibling);
     PageToTranslate.focus();
     //LinkTranslate_CheckMenu();
}

function LinkTranslate_HideMenu(){
     var MenuPages = document.getElementById("LinkTranslate_Menu");
     if(MenuPages) MenuPages.parentNode.removeChild(MenuPages);
}

///////////////// VERIF MENU ////////////////////////////////////


var MenuChoices = new Array();
function LinkTranslate_CheckMenu(){
     var PageToTranslateElement = document.getElementById('PageToTranslate_Input');
     var LangToTranslateElement = document.getElementById('LangToTranslate_Select');
     var TranslatedPageElement = document.getElementById('TranslatedPage_Input');
     var TranslatedLangElement = document.getElementById('TranslatedLang_Select');
     if((!PageToTranslateElement)||(!LangToTranslateElement)||(!TranslatedPageElement)||(!TranslatedLangElement)) return;

     var PageToTranslate = PageToTranslateElement.value;
     var LangToTranslate = LangToTranslateElement.value;
     var TranslatedPage = TranslatedPageElement.value;
     var TranslatedLang = TranslatedLangElement.value;
/*
     var Confirmation = confirm('Page à traduire : '+PageToTranslate
                              + '\nLangue à traduire : '+LangToTranslate
                              + '\nPage traduite : '+TranslatedPage
                              + '\nLangue finale : '+TranslatedLang
                                );
     if(!Confirmation) return;
*/
     MenuChoices["PageToTranslate"] = PageToTranslate;
     MenuChoices["LangToTranslate"] = LangToTranslate;
     MenuChoices["TranslatedPage"] = TranslatedPage;
     MenuChoices["TranslatedLang"] = TranslatedLang;
     for(var Type in ElementsToTranslateListParams){
          if(ElementsToTranslateListParams.hasOwnProperty(Type)){
               ElementsToTranslate[Type] = false;
               LinkTranslate_CreateProgressBar(Type);
               LinkTranslate_GetAllLinks(Type);
          }
     }
}

function LinkTranslate_CreateProgressBar(TYPE){
     var ControlPanel = document.getElementById("MenuControlPanel");
     if(!ControlPanel) return;
     var Container = document.createElement('fieldset');
     var Legend = document.createElement('legend');
     Legend.id = "ProgressBarLegend_"+TYPE;
     Legend.innerHTML = ElementsToTranslateListParams[TYPE]["text"];
     Container.appendChild(Legend);     
     var ProgressBarTable = document.createElement('div');
     ProgressBarTable.id = "ProgressBarTable_"+TYPE;
     ProgressBarTable.className = "degrade_rev";
     ProgressBarTable.setAttribute('style', 'display:none;width:100%;height:10px;background-color:red;border:1px solid silver;');
     var ProgressBar = document.createElement('div');
     ProgressBar.setAttribute('style', 'width:0%;background-color:LimeGreen;height:10px;border-right:2px solid DarkGreen');
     ProgressBar.id = "ProgressBar_"+TYPE;
     ProgressBarTable.appendChild(ProgressBar);
     Container.appendChild(ProgressBarTable);
     ControlPanel.appendChild(Container);
     
}
function LinkTranslate_UpdateProgressBar(TYPE, L, TOTAL){
     var ProgressBar = document.getElementById("ProgressBar_"+TYPE);
     if(!ProgressBar) return;
     var Percent = parseInt( 100 * ((1 + L) / TOTAL) );
     if(Percent<1) return;
     if(Percent>100) Percent=100;
     ProgressBar.style.width = Percent + "%";
}
///////////////// LISTAGE ////////////////////////////////////

var ElementsToTranslate = new Array();
var ElementsTranslated = new Array();

var ElementsToTranslateListParams = new Array();

ElementsToTranslateListParams["Links"] = {"prop"     : "links",
                                          "item"     : "pl",
                                          "limit"    : "pllimit",
                                          "continue" : "plcontinue",
                                          "text"     : "Listage des liens"
                                         };
ElementsToTranslateListParams["Templates"] = {"prop"     : "templates",
                                              "item"     : "tl",
                                              "limit"    : "tllimit",
                                              "continue" : "tlcontinue",
                                              "text"     : "Listage des modèles"
                                             };

ElementsToTranslateListParams["Categories"] = {"prop"     : "categories",
                                               "item"     : "cl",
                                               "limit"    : "cllimit",
                                               "continue" : "clcontinue",
                                               "text"     : "Listage des catégories"
                                              };

// ----------------------------- LISTAGE -------------------------------

function LinkTranslate_GetAllLinks(TYPE, AllLinks, LinkContinue){
      if(!ElementsToTranslateListParams[TYPE]) return;
      if(!AllLinks) AllLinks = new Array();
      if(!LinkContinue) LinkContinue = "";
      var APILimit = 499;
      if((mw.config.get('wgUserGroups')=="bot")||(mw.config.get('wgUserGroups')=="sysop")) APILimit = 4999;
      var URL = mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/api.php?format=xml'
              + '&action=query&prop='+ElementsToTranslateListParams[TYPE]["prop"]
              + '&redirects'
              + '&'+ElementsToTranslateListParams[TYPE]["limit"]+'='+((mw.config.get('wgUserGroups')=="bot")||(mw.config.get('wgUserGroups')=="sysop") ? 4999 : 499 )
              + '&titles='+encodeURIComponent(MenuChoices["PageToTranslate"])
              + LinkContinue;
      LinkTranslate_ajax.http({ 
            url: URL,
            onSuccess:LinkTranslate_GetAllLinksDone,
            type:TYPE,
            array : AllLinks
     });
}
function LinkTranslate_GetAllLinksDone(Req, data){
      var AllLinks = data.array;
      var TYPE = data.type;
      var ObjetXML = Req.responseXML; 
      if(!ObjetXML) return;
      var Links = ObjetXML.getElementsByTagName(ElementsToTranslateListParams[TYPE]["item"]);
      for(var a=0;a<Links.length;a++){
            var ThisLink = Links[a].getAttribute('title');
            AllLinks.push(ThisLink);
      }
      var MustContinue = document.getElementsByTagName('query-continue')[0];
      if(MustContinue){
            var LinkContinue = "&"+ElementsToTranslateListParams[TYPE]["continue"] +"="
                               + encodeURIComponent(MustContinue.firstChild.getAttribute(ElementsToTranslateListParams[TYPE]["continue"]));
            LinkTranslate_GetAllLinks(TYPE, AllLinks, LinkContinue);
      }else{
            ElementsToTranslate[TYPE] = AllLinks;
            LinkTranslate_GetPageInterwiki(TYPE);
      }
}

///////////////// RECHERCHE INTERWIKI ////////////////////////////////////

function LinkTranslate_GetPageInterwiki(TYPE, position, AllInterwikis){
      if(!position) position = 0;
      if(!AllInterwikis) AllInterwikis = new Array();
      var PageToTranslate = MenuChoices["PageToTranslate"];
      var LangToTranslate = MenuChoices["LangToTranslate"];
      var TranslatedPage = MenuChoices["TranslatedPage"];
      var TranslatedLang = MenuChoices["TranslatedLang"];
      var AllLinks = ElementsToTranslate[TYPE];
      var Page = AllLinks[position];
      if(!Page){
            if(!ElementsTranslated[TYPE]) ElementsTranslated[TYPE] = AllInterwikis;
            LinkTranslate_IsAllInterwikiOK(TYPE);
            return;
      }
      var Table = document.getElementById("ProgressBarTable_"+TYPE);
      if(Table) Table.style.display = "";
      var ControlPanelLegend = document.getElementById("ProgressBarLegend_"+TYPE);
      if(ControlPanelLegend && position==0) ControlPanelLegend.innerHTML += " : Recherche des interwikis";
      LinkTranslate_UpdateProgressBar(TYPE, position, AllLinks.length);

      var APILimit = 499;
      if((mw.config.get('wgUserGroups')=="bot")||(mw.config.get('wgUserGroups')=="sysop")) APILimit = 4999;

      var URL = mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/api.php?format=xml'
              + '&action=query&prop=langlinks'
              + '&lllimit='+APILimit
              +'&redirects&titles='+encodeURIComponent(Page);
      LinkTranslate_ajax.http({ 
            url: URL,
            onSuccess:LinkTranslate_GetPageInterwikiDone,
            type : TYPE,
            page : Page,
            pos : position,
            array : AllInterwikis
      });
}

function LinkTranslate_GetPageInterwikiDone(Req, data){
      var TYPE = data.type;
      var Page = data.page;
      var position = data.pos;
      var AllInterwikis = data.array;
      var ObjetXML = Req.responseXML; 
      if(!ObjetXML) return;
      var TheLangLink = false;
      var LangLinks = ObjetXML.getElementsByTagName('ll');
      for(var a=0;a<LangLinks.length;a++){
            var ThisLang = LangLinks[a].getAttribute("lang");
            if(ThisLang == MenuChoices["TranslatedLang"]){
                  TheLangLink = LangLinks[a].firstChild.nodeValue;
            }
      }
      AllInterwikis.push(TheLangLink);
      LinkTranslate_GetPageInterwiki(TYPE, (position+1), AllInterwikis);
}




var LinkTranslate_RequestOK = new Array();

function LinkTranslate_IsAllInterwikiOK(RequestType){
      LinkTranslate_RequestOK[RequestType] = 2;
      var AllOK = true;
      for(var Type in ElementsToTranslate){
            if(LinkTranslate_RequestOK[Type]!=2) AllOK = false;
      }
      if(!AllOK) return;
      var URL = mw.config.get('wgServer') + mw.config.get('wgScript') + '?title='+encodeURIComponent(MenuChoices["PageToTranslate"])+'&action=raw';
      LinkTranslate_ajax.http({ 
            url: URL,
            onSuccess:LinkTranslate_DoTranslation["Global"]
      });
}

///////////////// TRADUCTION ////////////////////////////////////

LinkTranslate_DoTranslation = new Array();

LinkTranslate_DoTranslation["Global"] = function(Req, data){
      var ControlPanel = document.getElementById("MenuControlPanel");
      if(ControlPanel) ControlPanel.innerHTML = "Traduction";
      var PageToTranslateContent = Req.responseText;
      PageToTranslateContent = LinkTranslate_DoTranslation["Images"](PageToTranslateContent);
      for(var TYPE in  ElementsToTranslate){
            if(typeof(LinkTranslate_DoTranslation[TYPE])=="function")
            PageToTranslateContent = LinkTranslate_DoTranslation[TYPE](PageToTranslateContent);
      }
      var URL = mw.config.get('wgServer') + mw.config.get('wgScript') + '?title='+encodeURIComponent(MenuChoices["TranslatedPage"])+'&action=edit';
      LinkTranslate_ajax.http({ 
            url: URL,
            onSuccess:LinkTranslate_SavePage,
            text:PageToTranslateContent
      });
}
function LinkTranslate_SavePage(Req, data){
      while(document.body.firstChild){ document.body.removeChild(document.body.firstChild); }
      document.body.innerHTML = Req.responseText; 
      var TextArea = document.getElementById("wpTextbox1");
      if(!TextArea){ alert('Pas trouvé la zone d\'édition'); return; }
      TextArea.value = data.text;
      var Sum = "Traduction [["+MenuChoices["PageToTranslate"]+"]] : "
              + MenuChoices["LangToTranslate"] + " -> " + MenuChoices["TranslatedLang"];
      document.getElementById("wpSummary").value = Sum;

}

LinkTranslate_DoTranslation["Images"] = function(PageToTranslateContent){
      var ImageRegExp = new RegExp("\\[\\[[ ]*"+mw.config.get('wgFormattedNamespaces')[6]+"[ ]*:", "ig");
      var AllImages = PageToTranslateContent.match(ImageRegExp);
      if(AllImages==null) return PageToTranslateContent;
      for(var a=0,l=AllImages.length;a<l;a++){
            PageToTranslateContent = PageToTranslateContent.replace(AllImages[a], "[[File:");
      }
      return PageToTranslateContent;
}

LinkTranslate_DoTranslation["Links"] = function(PageToTranslateContent){
      var TYPE = "Links";
      var PageToTranslate = MenuChoices["PageToTranslate"];
      var LangToTranslate = MenuChoices["LangToTranslate"];
      var TranslatedPage = MenuChoices["TranslatedPage"];
      var TranslatedLang = MenuChoices["TranslatedLang"];
      var AllLinks = ElementsToTranslate[TYPE];
      var AllInterwikis = ElementsTranslated[TYPE];
      for(var a=0;a<AllLinks.length;a++){
            if(AllInterwikis[a]){
                  PageToTranslateContent = PageToTranslateContent.split("[["+AllLinks[a].ucFirst()+"|").join("[["+AllInterwikis[a].ucFirst()+"|");
                  PageToTranslateContent = PageToTranslateContent.split("[["+AllLinks[a].lcFirst()+"|").join("[["+AllInterwikis[a].lcFirst()+"|");
                  PageToTranslateContent = PageToTranslateContent.split("[["+AllLinks[a].ucFirst()+"]]").join("[["+AllInterwikis[a].ucFirst()+"]]");
                  PageToTranslateContent = PageToTranslateContent.split("[["+AllLinks[a].lcFirst()+"]]").join("[["+AllInterwikis[a].lcFirst()+"]]");
            }else{
                  PageToTranslateContent = PageToTranslateContent.split("[["+AllLinks[a].ucFirst()+"]]").join("{{Lien|"+AllLinks[a].ucFirst() + (LangToTranslate!="en" ? "|lang="+LangToTranslate : "") +  "}}");
                  PageToTranslateContent = PageToTranslateContent.split("[["+AllLinks[a].lcFirst()+"]]").join("{{Lien|"+AllLinks[a].lcFirst() + (LangToTranslate!="en" ? "|lang="+LangToTranslate : "") + "}}");
                  var LinkRegExp = new RegExp("\\[\\["+AllLinks[a]+"[^\\]]+\\]\\]", "ig");
                  var Links = PageToTranslateContent.match(LinkRegExp);
                  if(Links!=null){
                        for(var b=0;b<Links.length;b++){
                              var ThisLink = Links[b];
                              var ThisLinkContent = ThisLink.split('[[').join('').split(']]').join('');
                              //alert("Match :\n"+ ThisLink);
                              var TextLink = ThisLinkContent.replace(/.*\|/g, "");
                              var PageLink = ThisLinkContent.replace(/\|.*/g, "");
                              var ReplacedLink =  ThisLink.split("[["+ThisLinkContent+"]]").join("{{Lien|" +PageLink + (TextLink!="" ? "|texte="+TextLink : "") + "|trad="+ PageLink + (LangToTranslate!="en" ? "|lang="+LangToTranslate : "") +  "}}");
                              //alert("Replace :\n" + ThisLink + " -> " + ReplacedLink);
                              PageToTranslateContent = PageToTranslateContent.replace(ThisLink, ReplacedLink);
                        }
                  }
            }
      }
      return PageToTranslateContent;
}

LinkTranslate_DoTranslation["Templates"] = function(PageToTranslateContent){
      var TYPE = "Templates";
      var PageToTranslate = MenuChoices["PageToTranslate"];
      var LangToTranslate = MenuChoices["LangToTranslate"];
      var TranslatedPage = MenuChoices["TranslatedPage"];
      var TranslatedLang = MenuChoices["TranslatedLang"];
      var AllTemplates = ElementsToTranslate[TYPE];
      var AllInterwikis = ElementsTranslated[TYPE];
      for(var a=0;a<AllTemplates.length;a++){
            if(AllInterwikis[a]){
                  try{
                  var Template = AllTemplates[a].split(mw.config.get('wgFormattedNamespaces')[10]+":").join("");
                  var Interwiki = AllInterwikis[a].substring((AllInterwikis[a].indexOf(":")+1));
                  var TemplatesRegExp = new RegExp("\\{\\{( |_)*"+Template, "ig");
                  PageToTranslateContent = PageToTranslateContent.replace(TemplatesRegExp, "{{"+Interwiki);
                  }catch(e){ }
            }
      }
      PageToTranslateContent = LinkTranslate_DoTranslation["BiblioTemplates"](PageToTranslateContent);
      return PageToTranslateContent;
}

var LinkTranslate_BiblioTemplates = new Array();

LinkTranslate_BiblioTemplates["Ouvrage"] = new Array();
LinkTranslate_BiblioTemplates["Ouvrage"]["langue"]           = {"es":"idioma"};
LinkTranslate_BiblioTemplates["Ouvrage"]["prénom1"]          = {"es":"nombre"};
LinkTranslate_BiblioTemplates["Ouvrage"]["nom1"]             = {"es":"apellidos"};
LinkTranslate_BiblioTemplates["Ouvrage"]["lien auteur1"]     = {"es":"enlaceautor"};
LinkTranslate_BiblioTemplates["Ouvrage"]["titre"]            = {"es":"título"};
LinkTranslate_BiblioTemplates["Ouvrage"]["numéro d'édition"] = {"es":"edición"};
LinkTranslate_BiblioTemplates["Ouvrage"]["éditeur"]          = {"es":"editorial"};
LinkTranslate_BiblioTemplates["Ouvrage"]["lieu"]             = {"es":"ubicación"};
LinkTranslate_BiblioTemplates["Ouvrage"]["année"]            = {"es":"año"};
LinkTranslate_BiblioTemplates["Ouvrage"]["volume"]           = {"es":"volumen"};
LinkTranslate_BiblioTemplates["Ouvrage"]["passage"]          = {"es":"capítulo"};
LinkTranslate_BiblioTemplates["Ouvrage"]["consulté le"]      = {"es":"fechaacceso"};

LinkTranslate_BiblioTemplates["Article"] = new Array();
LinkTranslate_BiblioTemplates["Article"]["langue"]       = {"es":"idioma"};
LinkTranslate_BiblioTemplates["Article"]["prénom1"]      = {"es":"nombre"};
LinkTranslate_BiblioTemplates["Article"]["nom1"]         = {"es":"apellidos"};
LinkTranslate_BiblioTemplates["Article"]["lien auteur1"] = {"es":"enlaceautor"};
LinkTranslate_BiblioTemplates["Article"]["titre"]        = {"es":"título"};
LinkTranslate_BiblioTemplates["Article"]["périodique"]   = {"es":"revista"};
LinkTranslate_BiblioTemplates["Article"]["éditeur"]      = {"es":"editor"};
LinkTranslate_BiblioTemplates["Article"]["volume"]       = {"es":"volumen"};
LinkTranslate_BiblioTemplates["Article"]["numéro"]       = {"es":"número"};
LinkTranslate_BiblioTemplates["Article"]["année"]        = {"es":"año"};
LinkTranslate_BiblioTemplates["Article"]["pages"]        = {"es":"páginas"};
LinkTranslate_BiblioTemplates["Article"]["consulté le"]  = {"es":"fechaacceso"};

LinkTranslate_BiblioTemplates["Lien web"] = new Array();
LinkTranslate_BiblioTemplates["Lien web"]["url"]         = {"es":"url"};
LinkTranslate_BiblioTemplates["Lien web"]["titre"]       = {"es":"título"};
LinkTranslate_BiblioTemplates["Lien web"]["auteur"]      = {"es":"autor"};
LinkTranslate_BiblioTemplates["Lien web"]["lien auteur"] = {"es":"enlaceautor"};
LinkTranslate_BiblioTemplates["Lien web"]["date"]        = {"es":"fecha"};
LinkTranslate_BiblioTemplates["Lien web"]["année"]       = {"es":"año"};
LinkTranslate_BiblioTemplates["Lien web"]["mois"]        = {"es":"mes"};
LinkTranslate_BiblioTemplates["Lien web"]["éditeur"]     = {"es":"editor"};
LinkTranslate_BiblioTemplates["Lien web"]["page"]        = {"es":"página"};
LinkTranslate_BiblioTemplates["Lien web"]["citation"]    = {"es":"cita"};
LinkTranslate_BiblioTemplates["Lien web"]["consulté le"] = {"es":"fechaacceso"};


LinkTranslate_DoTranslation["BiblioTemplates"] = function(PageToTranslateContent){
      for(var Template in LinkTranslate_BiblioTemplates){
            if(!LinkTranslate_BiblioTemplates.hasOwnProperty(Template)) continue;
            var TemplateRegExp = new RegExp("\\{\\{[ ]*"+Template+"[ ]*\\|[^\\}]*\\}\\}", "ig");
            var Matches = PageToTranslateContent.match(TemplateRegExp);
            if(Matches==null) continue;
            for(var a=0,l=Matches.length;a<l;a++){
                  var ThisTemplate = Matches[a];
                  for(var Param in LinkTranslate_BiblioTemplates[Template]){
                        if(LinkTranslate_BiblioTemplates[Template].hasOwnProperty(Param)){
                              var ThisParam = LinkTranslate_BiblioTemplates[Template][Param][MenuChoices["LangToTranslate"]];
                              if(ThisParam){
                                    var ParamRegExp = new RegExp("\\|[ ]*"+ThisParam+"[ ]*=", "g");
                                    var ParamMatches = ThisTemplate.match(ParamRegExp);
                                    if(ParamMatches!=null){
                                          ThisTemplate = ThisTemplate.replace(ParamRegExp, "|"+Param+"=");
                                    }
                              }
                        }
                  }
                  PageToTranslateContent = PageToTranslateContent.replace(Matches[a], ThisTemplate);
            }
      }
      return PageToTranslateContent;
}

LinkTranslate_DoTranslation["Categories"] = function(PageToTranslateContent){
      var TYPE = "Categories";
      var PageToTranslate = MenuChoices["PageToTranslate"];
      var LangToTranslate = MenuChoices["LangToTranslate"];
      var TranslatedPage = MenuChoices["TranslatedPage"];
      var TranslatedLang = MenuChoices["TranslatedLang"];
      var AllCategories = ElementsToTranslate[TYPE];
      var AllInterwikis = ElementsTranslated[TYPE];
      for(var a=0;a<AllCategories.length;a++){
            if(AllInterwikis[a]){
                  var CategoriesRegExp = new RegExp("\\[\\[[ ]*"+AllCategories[a], "ig");
                  PageToTranslateContent = PageToTranslateContent.replace(CategoriesRegExp, "[["+AllInterwikis[a]);
            }
      }
      return PageToTranslateContent;
}

///////////////// PREMIÈRE LETTRE EN MAJUSCULE ////////////////////////////////////
 
String.prototype.ucFirst = function () {
    return this.substr(0,1).toUpperCase() + this.substr(1,this.length);
}
 
///////////////// PREMIÈRE LETTRE EN MINUSCULE ////////////////////////////////////
 
String.prototype.lcFirst = function () {
    return this.substr(0,1).toLowerCase() + this.substr(1,this.length);
}

///////////////// SUGGESTIONS API ////////////////////////////////////

var LinkTranslate_Suggest_Size = 5


function LinkTranslate_GetSuggest(){
    var Input = document.getElementById("PageToTranslate_Input");
    if(!Input) return;
    var ApNamespace = 0;
    var APNamespaceName = "";
    var Value = Input.value;
    for(var NS in mw.config.get('wgFormattedNamespaces')){
        var NamespaceName = mw.config.get('wgFormattedNamespaces')[NS];
        if((NS>0)&&(Value.indexOf(NamespaceName+":")!=-1)){
            APNamespaceName = NamespaceName+":";
            ApNamespace = NS;
            Value = Value.split(APNamespaceName).join('');
        }
    }
    var Adresse = mw.config.get('wgServer') + mw.config.get('wgScriptPath')+ '/api.php?format=xml&action=query&list=allpages&apfilterredir=nonredirects&aplimit='+LinkTranslate_Suggest_Size+'&apnamespace='+ApNamespace+'&apprefix='+Value;
    //alert(Adresse);
    var NouvelleRequete = new XMLHttpRequest()
    NouvelleRequete.open("GET", Adresse, true);
    NouvelleRequete.onreadystatechange = function() {
        if(NouvelleRequete.readyState != 4) return;
        var ObjetXML = NouvelleRequete.responseXML;
        var PageNames = new Array();
        var Pages = ObjetXML.getElementsByTagName('p');
        for(var a=0;a<Pages.length;a++){
            var PageName = Pages[a].getAttribute('title')
            PageNames.push(PageName);
        }
        LinkTranslate_ShowSuggest(Input, PageNames);
    }
    NouvelleRequete.send(null);
}

function LinkTranslate_ShowSuggest(Input, PageNames){
    var LastSelect = document.getElementById("Translate_Suggest");
    if(LastSelect) LastSelect.parentNode.removeChild(LastSelect);
    if(PageNames.length==0) return;

    var Size = LinkTranslate_Suggest_Size
    if (PageNames.length < LinkTranslate_Suggest_Size) {
        Size = PageNames.length;
    }
    var listh = Size * 20 ;

    var nl = parseInt ( Input.offsetLeft ) - 1 ;
    var nt = parseInt(Input.offsetTop) - listh ;


    var NewSelect = document.createElement('select');
    NewSelect.id = "Translate_Suggest";
    NewSelect.size = Size ;
    NewSelect.style.align = "left" ;
    NewSelect.style.zIndex = 5 ;
    NewSelect.style.position = "absolute" ;
    NewSelect.style.top = nt + "px" ;
    NewSelect.style.width = Input.offsetWidth + "px" ;
    NewSelect.style.height = listh + "px" ;
    NewSelect.style.left = nl + "px" ;
    NewSelect.onkeyup = LinkTranslate_KeypressedOnSuggest;
    NewSelect.onchange = LinkTranslate_ReplaceSuggest;
    NewSelect.style.display = "block" ;
    for ( var i = 0 ; i < PageNames.length ; i++ ) {
        var opt = document.createElement ( "option" ) ;
        var ot = document.createTextNode ( PageNames[i] ) ;
        opt.appendChild ( ot ) ;
        opt.value = PageNames[i];
        NewSelect.appendChild ( opt ) ;
    }  
    Input.parentNode.insertBefore(NewSelect,Input);
}

function LinkTranslate_KeypressedOnSuggest(e){
    if (!e) var e = window.event;
    if (e.keyCode != 13) return;
    LinkTranslate_ReplaceSuggest();
}
 
// REMPLACEMENT DU CHAMP DE TEXTE PAR UNE SUGGESTION
 
function LinkTranslate_ReplaceSuggest(){
    var Text = document.getElementById("PageToTranslate_Input");
    var TextValue = Text.value;
    var List = document.getElementById("Translate_Suggest");
    var Options = List.getElementsByTagName('option');
    for(var a=0;a<Options.length;a++){
        if(Options[a].selected){
            var ListValue = Options[a].value;
            Text.value = ListValue;
            LinkTranslate_GetSuggest() ;
            Text.focus();
            return;
        }
    }
}




//</nowiki></pre></source>