User:Czar/citetrans.js

jQuery(document).ready(function($) { if(mw.config.get('wgNamespaceNumber') != -1) {	mw.loader.using(['mediawiki.util']).done( function { var portletlink = mw.util.addPortletLink('p-tb','#','Citation translation','t-citetrans'); $(portletlink).click(function(e) {			e.preventDefault;			citationtranslationfunction;		}); }); } // // function citationtranslationfunction {  var myContent = document.getElementById('wpTextbox1').value;

// Date myContent = myContent.replace(/\{\{[_ ]*[Ff]echa[_ ]*\|[ ]*([0-9]+)[ ]*\|[ ]*([0-9]+)[ ]*\|[ ]*([0-9]+)[ ]*\}\}/gi, '\{\{date|$3-$2-$1\}\}');

// translate citation templates myContent = myContent.replace(/(\{\{)[_ ]*[Cc]ita[_ ]+libro/g, '$1cite book'); myContent = myContent.replace(/(\{\{)[_ ]*[Cc]ytuj[_ ]+książkę/g, '$1cite book'); myContent = myContent.replace(/(\{\{)[_ ]*[Cc]ita[_ ]+publicación/g, '$1cite journal'); myContent = myContent.replace(/(\{\{)[_ ]*[Cc]ytuj[_ ]+pismo/g, '$1cite journal'); myContent = myContent.replace(/(\{\{)[_ ]*[Cc]ita[_ ]+(?:noticia|news)/g, '$1cite news'); myContent = myContent.replace(/(\{\{)[_ ]*[Cc]ita[_ ]*web/g, '$1cite web'); myContent = myContent.replace(/(\{\{)[_ ]*[Cc]itar[_ ]+web/g, '$1cite web'); myContent = myContent.replace(/(\{\{)[_ ]*[Ll]ien[_ ]+web/g, '$1cite web'); myContent = myContent.replace(/(\{\{)[_ ]*[Cc]ytuj[_ ]+stronę/g, '$1cite web'); myContent = myContent.replace(/(\{\{)[_ ]*[Kk]irjaviite/g, '$1cite book'); myContent = myContent.replace(/(\{\{)[_ ]*[Oo]uvrage/gi, '$1cite book'); myContent = myContent.replace(/(\{\{)[_ ]*[Vv]erkkoviite/gi, '$1cite web'); myContent = myContent.replace(/(\{\{)[_ ]*[Ww]eb[_ ]+kaynağı/gi, '$1cite web'); myContent = myContent.replace(/(\{\{)[_ ]*[Hh]aber[_ ]+kaynağı/gi, '$1cite news'); myContent = myContent.replace(/(\{\{)[_ ]*[Kk]itap[_ ]+kaynağı/gi, '$1cite book'); myContent = myContent.replace(/(\{\{)[_ ]*[Dd]ergi[_ ]+kaynağı/gi, '$1cite journal'); myContent = myContent.replace(/(\{\{)[_ ]*[Aa]rticle/gi, '$1cite journal'); //pt myContent = myContent.replace(/(\{\{)[_ ]*[Cc]itar[_ ]+livro/g, '$1cite book'); myContent = myContent.replace(/(\{\{)[_ ]*[Cc]itar[_ ]+periódico/g, '$1cite newspaper'); myContent = myContent.replace(/(\{\{)[_ ]*[Cc]itar[_ ]+tese/g, '$1cite thesis');

// spacing myContent = myContent.replace(/(\{\{)[_ ]+((?:[Cc]ite|[Cc]itation))/g, '$1$2');

// roll up citations to simplify processing while (myContent.search(/\{\{(?:[Cc]ite|[Cc]itation)[_ ]+(?:book|web|article)[^\{\}\n]*[\n]/g) >= 0 ) { myContent = myContent.replace(/(\{\{(?:[Cc]ite|[Cc]itation)[_ ]+(?:book|web|article)[^\{\}\n]*)[\n]/gi, '$1'); } for(var i=0; i<3; i++) { // cut these if they are blank myContent = myContent.replace(/(\{\{(?:[Cc]ite|[Cc]itation)(?:[^{}]|\{\{[^{}]*\}\})*)\|[ ]*resumenprofano[ ]*=(?:| )*(\||\}\})/g,'$1$2'); myContent = myContent.replace(/(\{\{(?:[Cc]ite|[Cc]itation)(?:[^{}]|\{\{[^{}]*\}\})*)\|[ ]*fuenteprofano[ ]*=(?:| )*(\||\}\})/g,'$1$2'); myContent = myContent.replace(/(\{\{(?:[Cc]ite|[Cc]itation)(?:[^{}]|\{\{[^{}]*\}\})*)\|[ ]*fechaprofano[ ]*=(?:| )*(\||\}\})/g,'$1$2'); myContent = myContent.replace(/(\{\{(?:[Cc]ite|[Cc]itation)(?:[^{}]|\{\{[^{}]*\}\})*)\|[ ]*cita[ ]*=(?:| )*(\||\}\})/g,'$1$2'); myContent = myContent.replace(/(\{\{(?:[Cc]ite|[Cc]itation)(?:[^{}]|\{\{[^{}]*\}\})*)\|[ ]*mes[ ]*=(?:| )*(\||\}\})/g,'$1$2'); myContent = myContent.replace(/(\{\{(?:[Cc]ite|[Cc]itation)(?:[^{}]|\{\{[^{}]*\}\})*)\|[ ]*giorno[ ]*=(?:| )*(\||\}\})/g,'$1$2'); myContent = myContent.replace(/(\{\{(?:[Cc]ite|[Cc]itation)(?:[^{}]|\{\{[^{}]*\}\})*)\|[ ]*mesacceso[ ]*=(?:| )*(\||\}\})/g,'$1$2'); myContent = myContent.replace(/(\{\{(?:[Cc]ite|[Cc]itation)(?:[^{}]|\{\{[^{}]*\}\})*)\|[ ]*[Tt]unniste[ ]*=(?:| )*(\||\}\})/g,'$1$2');

// start translation myContent = myContent.replace(/(\{\{(?:[Cc]ite|[Cc]itation)(?:[^{}]|\{\{[^{}]*\}\})*\|[ ]*)(?:fechaacceso|consulta|acessodata|accesso|consulté le|data dostępu)([ ]*=)/g,'$1accessdate$2'); myContent = myContent.replace(/(\{\{(?:[Cc]ite|[Cc]itation)(?:[^{}]|\{\{[^{}]*\}\})*\|[ ]*)(?:añoacceso|[Ll]uettu|erişim\-?tarihi)([ ]*=)/g,'$1accessdate$2'); myContent = myContent.replace(/(\{\{(?:[Cc]ite|[Cc]itation)(?:[^{}]|\{\{[^{}]*\}\})*\|[ ]*)(?:agencia|ajans)([ ]*=)/g,'$1agency$2'); myContent = myContent.replace(/(\{\{(?:[Cc]ite|[Cc]itation)(?:[^{}]|\{\{[^{}]*\}\})*\|[ ]*)(?:urlarchivo|urlarchivio|arşiv[Uu][Rr][Ll])([ ]*=)/g,'$1archiveurl$2'); myContent = myContent.replace(/(\{\{(?:[Cc]ite|[Cc]itation)(?:[^{}]|\{\{[^{}]*\}\})*\|[ ]*)(?:fechaarchivo|dataarchivio|arşivtarihi)([ ]*=)/g,'$1archivedate$2'); while(myContent.search(/(\{\{(?:[Cc]ite|[Cc]itation)(?:[^{}]|\{\{[^{}]*\}\})*\|[ ]*)(?:autore|auteur|autor|[Tt]ekijä)([0-9]*[ ]*=)/g) >= 0) { myContent = myContent.replace(/(\{\{(?:[Cc]ite|[Cc]itation)(?:[^{}]|\{\{[^{}]*\}\})*\|[ ]*)(?:autore|auteur|autor|[Tt]ekijä)([0-9]*[ ]*=)/g,'$1author$2'); } while(myContent.search(/(\{\{(?:[Cc]ite|[Cc]itation)(?:[^{}]|\{\{[^{}]*\}\})*\|[ ]*)(?:enlaceautor|wkautore|lien auteur)([0-9]*[ ]*=)/g) >= 0) { myContent = myContent.replace(/(\{\{(?:[Cc]ite|[Cc]itation)(?:[^{}]|\{\{[^{}]*\}\})*\|[ ]*)(?:enlaceautor|wkautore|lien auteur)([0-9]*[ ]*=)/g,'$1authorlink$2'); } myContent = myContent.replace(/(\{\{(?:[Cc]ite|[Cc]itation)(?:[^{}]|\{\{[^{}]*\}\})*\|[ ]*)(?:capitolo|capítulo)([ ]*=)/g,'$1chapter$2'); myContent = myContent.replace(/(\{\{(?:[Cc]ite|[Cc]itation)(?:[^{}]|\{\{[^{}]*\}\})*\|[ ]*)(?:url_capitolo|urlcapítulo)([ ]*=)/g,'$1chapterurl$2'); myContent = myContent.replace(/(\{\{(?:[Cc]ite|[Cc]itation)(?:[^{}]|\{\{[^{}]*\}\})*\|[ ]*)(?:coautores|coautori|coauteurs)([ ]*=)/g,'$1coauthors$2'); myContent = myContent.replace(/(\{\{(?:[Cc]ite|[Cc]itation)(?:[^{}]|\{\{[^{}]*\}\})*\|[ ]*)(?:fecha|data|online on|tarih)([ ]*=)/g,'$1date$2'); myContent = myContent.replace(/(\{\{(?:[Cc]ite|[Cc]itation)(?:[^{}]|\{\{[^{}]*\}\})*\|[ ]*)(?:giorno|jour)([ ]*=)/g,'$1day$2'); myContent = myContent.replace(/(\{\{(?:[Cc]ite|[Cc]itation)(?:[^{}]|\{\{[^{}]*\}\})*\|[ ]*)(?:edizione|edición|basım)([ ]*=)/g,'$1edition$2'); myContent = myContent.replace(/(\{\{(?:[Cc]ite|[Cc]itation)(?:[^{}]|\{\{[^{}]*\}\})*\|[ ]*)(?:curatore)([ ]*=)/g,'$1editor$2'); while(myContent.search(/(\{\{(?:[Cc]ite|[Cc]itation)(?:[^{}]|\{\{[^{}]*\}\})*\|[ ]*)(?:apellido-editor)([0-9]*[ ]*=)/g) >= 0) { myContent = myContent.replace(/(\{\{(?:[Cc]ite|[Cc]itation)(?:[^{}]|\{\{[^{}]*\}\})*\|[ ]*)(?:apellido-editor)([0-9]*[ ]*=)/g,'$1editor-last$2'); } while(myContent.search(/(\{\{(?:[Cc]ite|[Cc]itation)(?:[^{}]|\{\{[^{}]*\}\})*\|[ ]*)(?:nombre-editor)([0-9]*[ ]*=)/g) >= 0) { myContent = myContent.replace(/(\{\{(?:[Cc]ite|[Cc]itation)(?:[^{}]|\{\{[^{}]*\}\})*\|[ ]*)(?:nombre-editor)([0-9]*[ ]*=)/g,'$1editor-first$2'); } myContent = myContent.replace(/(\{\{(?:[Cc]ite|[Cc]itation)(?:[^{}]|\{\{[^{}]*\}\})*\|[ ]*)(?:formato|biçim)([ ]*=)/g,'$1format$2'); myContent = myContent.replace(/(\{\{(?:[Cc]ite|[Cc]itation)(?:[^{}]|\{\{[^{}]*\}\})*\|[ ]*)(?:nome|nombre|ilk|prénom|primeiro|imię|ad)([0-9]*[ ]*=)/g,'$1first$2'); myContent = myContent.replace(/(\{\{(?:[Cc]ite|[Cc]itation)(?:[^{}]|\{\{[^{}]*\}\})*\|[ ]*)(?:publicación|dergi)([ ]*=)/g,'$1journal$2'); myContent = myContent.replace(/(\{\{(?:[Cc]ite|[Cc]itation)(?:[^{}]|\{\{[^{}]*\}\})*\|[ ]*)(?:idioma|llengua|língua[0-9]*|lingua|język|dil|langue)([ ]*=)/g,'$1language$2'); myContent = myContent.replace(/(\{\{(?:[Cc]ite|[Cc]itation)(?:[^{}]|\{\{[^{}]*\}\})*\|[ ]*)(?:apellidos?|cognome|son|nom|nazwisko|soyadı|sobrenome|ultimo)([0-9]*[ ]*=)/g,'$1last$2'); myContent = myContent.replace(/(\{\{(?:[Cc]ite|[Cc]itation)(?:[^{}]|\{\{[^{}]*\}\})*\|[ ]*)(?:ubicación|città|[Jj]ulkaisupaikka|lugar-publicación|yer|miejsce|lieu|local)([ ]*=)/g,'$1location$2'); myContent = myContent.replace(/(\{\{(?:[Cc]ite|[Cc]itation)(?:[^{}]|\{\{[^{}]*\}\})*\|[ ]*)(?:mes|mese|mois|ay)([ ]*=)/g,'$1month$2'); myContent = myContent.replace(/(\{\{(?:[Cc]ite|[Cc]itation)(?:[^{}]|\{\{[^{}]*\}\})*\|[ ]*)(?:número|wydanie|wydani)([ ]*=)/g,'$1number$2'); myContent = myContent.replace(/(\{\{(?:[Cc]ite|[Cc]itation)(?:[^{}]|\{\{[^{}]*\}\})*\|[ ]*)(?:página|pagine|passage|[Ss]ivu)([ ]*=)/g,'$1page$2'); myContent = myContent.replace(/(\{\{(?:[Cc]ite|[Cc]itation)(?:[^{}]|\{\{[^{}]*\}\})*\|[ ]*)(?:páginas|pagina|sayfalar|strony)([ ]*=)/g,'$1pages$2'); myContent = myContent.replace(/(\{\{(?:[Cc]ite|[Cc]itation)(?:[^{}]|\{\{[^{}]*\}\})*\|[ ]*)(?:editorial|editore|publicado|site|éditeur|editora|opublikowany|[Jj]ulkaisija|yayıncı|yayımcı|wydawca|instituição)([ ]*=)/g,'$1publisher$2'); myContent = myContent.replace(/(\{\{(?:[Cc]ite|[Cc]itation)(?:[^{}]|\{\{[^{}]*\}\})*\|[ ]*)citazione([ ]*=)/g,'$1quote$2'); myContent = myContent.replace(/(\{\{(?:[Cc]ite|[Cc]itation)(?:[^{}]|\{\{[^{}]*\}\})*\|[ ]*)grau([ ]*=)/g,'$1degree$2'); myContent = myContent.replace(/(\{\{(?:[Cc]ite|[Cc]itation)(?:[^{}]|\{\{[^{}]*\}\})*\|[ ]*)(?:cita|[Tt]unniste|cid)([ ]*=)/g,'$1ref$2'); myContent = myContent.replace(/(\{\{(?:[Cc]ite|[Cc]itation)(?:[^{}]|\{\{[^{}]*\}\})*\|[ ]*)(?:título|titolo|titulo|titre|tytuł|[Nn]imike|[Nn]imeke|başlık)([ ]*=)/g,'$1title$2'); myContent = myContent.replace(/(\{\{(?:[Cc]ite|[Cc]itation)(?:[^{}]|\{\{[^{}]*\}\})*\|[ ]*)(?:[Oo]soite|lire en ligne)([ ]*=)/g,'$1url$2'); myContent = myContent.replace(/(\{\{(?:[Cc]ite|[Cc]itation)(?:[^{}]|\{\{[^{}]*\}\})*\|[ ]*)(?:volumen|wolumin)([ ]*=)/g,'$1volume$2'); myContent = myContent.replace(/(\{\{(?:[Cc]ite|[Cc]itation)(?:[^{}]|\{\{[^{}]*\}\})*\|[ ]*)(?:sitioweb|[Yy]azar|sito)([ ]*=)/g,'$1website$2'); myContent = myContent.replace(/(\{\{(?:[Cc]ite|[Cc]itation)(?:[^{}]|\{\{[^{}]*\}\})*\|[ ]*)(?:otros|obra|opera|periódico|pubblicazione|eser|çalışma|iş|czasopismo|périodique)([ ]*=)/g,'$1work$2'); myContent = myContent.replace(/(\{\{(?:[Cc]ite|[Cc]itation)(?:[^{}]|\{\{[^{}]*\}\})*\|[ ]*)(?:año|anno|ano|année|[Vv]uosi|yıl|rok|data)([ ]*=)/g,'$1year$2'); myContent = myContent.replace(/(\{\{(?:[Cc]ite|[Cc]itation)(?:[^{}]|\{\{[^{}]*\}\})*\|[ ]*)arşivengelli([ ]*=)[ ]*evet/g,'$1dead-url$2no'); myContent = myContent.replace(/(\{\{(?:[Cc]ite|[Cc]itation)(?:[^{}]|\{\{[^{}]*\}\})*\|[ ]*)day([ ]*=[^\|{}]*)\|[ ]*month[ ]*=([^\|{}]*)\|[ ]*year[ ]*=/g, '$1date$2 $3 '); myContent = myContent.replace(/(\{\{(?:[Cc]ite|[Cc]itation)(?:[^{}]|\{\{[^{}]*\}\})*\|[ ]*(?:archive[\-]*|access[\-]*|)date[ ]*=[ ]*[0-9]*[ ]*) (?:de |)(?:gennaio|enero|janvier|[Oo]cak) (?:de |)/g, '$1 January '); myContent = myContent.replace(/(\{\{(?:[Cc]ite|[Cc]itation)(?:[^{}]|\{\{[^{}]*\}\})*\|[ ]*(?:archive[\-]*|access[\-]*|)date[ ]*=[ ]*[0-9]*[ ]*) (?:de |)(?:febbraio|febrero|février|[Şş]ubat) (?:de |)/g, '$1 February '); myContent = myContent.replace(/(\{\{(?:[Cc]ite|[Cc]itation)(?:[^{}]|\{\{[^{}]*\}\})*\|[ ]*(?:archive[\-]*|access[\-]*|)date[ ]*=[ ]*[0-9]*[ ]*) (?:de |)(?:marzo|mars|[Mm]art) (?:de |)/g, '$1 March '); myContent = myContent.replace(/(\{\{(?:[Cc]ite|[Cc]itation)(?:[^{}]|\{\{[^{}]*\}\})*\|[ ]*(?:archive[\-]*|access[\-]*|)date[ ]*=[ ]*[0-9]*[ ]*) (?:de |)(?:aprile|abril|avril|[Nn]isan) (?:de |)/g, '$1 April '); myContent = myContent.replace(/(\{\{(?:[Cc]ite|[Cc]itation)(?:[^{}]|\{\{[^{}]*\}\})*\|[ ]*(?:archive[\-]*|access[\-]*|)date[ ]*=[ ]*[0-9]*[ ]*) (?:de |)(?:maggio|mayo|mai|[Mm]ayıs) (?:de |)/g, '$1 May '); myContent = myContent.replace(/(\{\{(?:[Cc]ite|[Cc]itation)(?:[^{}]|\{\{[^{}]*\}\})*\|[ ]*(?:archive[\-]*|access[\-]*|)date[ ]*=[ ]*[0-9]*[ ]*) (?:de |)(?:giugno|junio|juin|[Hh]aziran) (?:de |)/g, '$1 June '); myContent = myContent.replace(/(\{\{(?:[Cc]ite|[Cc]itation)(?:[^{}]|\{\{[^{}]*\}\})*\|[ ]*(?:archive[\-]*|access[\-]*|)date[ ]*=[ ]*[0-9]*[ ]*) (?:de |)(?:luglio|julio|juillet|[Tt]emmuz) (?:de |)/g, '$1 July '); myContent = myContent.replace(/(\{\{(?:[Cc]ite|[Cc]itation)(?:[^{}]|\{\{[^{}]*\}\})*\|[ ]*(?:archive[\-]*|access[\-]*|)date[ ]*=[ ]*[0-9]*[ ]*) (?:de |)(?:agosto|août|[Aa]ğustos) (?:de |)/g, '$1 August '); myContent = myContent.replace(/(\{\{(?:[Cc]ite|[Cc]itation)(?:[^{}]|\{\{[^{}]*\}\})*\|[ ]*(?:archive[\-]*|access[\-]*|)date[ ]*=[ ]*[0-9]*[ ]*) (?:de |)(?:settembre|septiembre|septembre|[Ee]ylül) (?:de |)/g, '$1 September '); myContent = myContent.replace(/(\{\{(?:[Cc]ite|[Cc]itation)(?:[^{}]|\{\{[^{}]*\}\})*\|[ ]*(?:archive[\-]*|access[\-]*|)date[ ]*=[ ]*[0-9]*[ ]*) (?:de |)(?:ottobre|octubre|octobre|[Ee]kim) (?:de |)/g, '$1 October '); myContent = myContent.replace(/(\{\{(?:[Cc]ite|[Cc]itation)(?:[^{}]|\{\{[^{}]*\}\})*\|[ ]*(?:archive[\-]*|access[\-]*|)date[ ]*=[ ]*[0-9]*[ ]*) (?:de |)(?:novembre|noviembre|novembre|[Kk]asım) (?:de |)/g, '$1 November '); myContent = myContent.replace(/(\{\{(?:[Cc]ite|[Cc]itation)(?:[^{}]|\{\{[^{}]*\}\})*\|[ ]*(?:archive[\-]*|access[\-]*|)date[ ]*=[ ]*[0-9]*[ ]*) (?:de |)(?:dicembre|diciembre|décembre|[Aa]ralık) (?:de |)/g, '$1 December ');

myContent = myContent.replace(/(\{\{(?:[Cc]ite|[Cc]itation)(?:[^{}]|\{\{[^{}]*\}\})*\|[ ]*)ref([ ]*=[ ]*)ISBN[ ]?/g, '$1isbn$2'); } // unroll citations now that we have finished processing myContent = myContent.replace(//g, '\n');

if(document.getElementById('wpTextbox1').value != myContent) { document.getElementById('wpTextbox1').value = myContent; document.getElementById('wpSummary').value = 'translating citations'; } document.getElementById('wpDiff').click; } // // });