User:Frenezulo/TemplateTranslator.js

// This program will "translate" Wikipedia citation templates from English to Spanish. // This program is intended to be called using an HTML "wrapper", and run from a local hard drive. // It doesn't work directly from the wiki (yet). // // JavaScript under Mozilla v61.0.1, Windows 7 // by Jon Liechty // function TranslateOne (thistemplate) { // Split the parameters of the template into separate array elements var template = thistemplate.split("|"); //  // Initialize the parameter dictionary var englishparams = new Array ( "access-date", "archive-url", "arxiv", "at", 	                               "author", "author1", "author2", "author3", "author4", "author5",                                "author-link1", "author-link2", "author-link3", "author-link4", "author-link5",                                 "author-mask", "bibcode", "booktitle", "chapter", "chapter-url", "date", "doi", "doi-broken-date",                                                                     "edition", "editor1-first","editor2-first", "editor3-first", "editor4-first",                                 "editor5-first",                                 "editor1-last","editor2-last", "editor3-last", "editor4-last", "editor5-last",                                 "editor1-link", "editor2-link", "editor3-link", "editor4-link", "editor5-link",                                "first", "first1", "first2", "first3", "first4", "first5", "format", "id", "isbn", "journal", "language", "last", "last1", "last2", "last3", "last4", "last5", "lay-date", "lay-summary", "location", "nopp", "number", "oclc", "orig-year", "publication-date", "page", "pages", "publisher", "quote", "ref", "series", "title", "trans-title", "trans-chapter", "url", "volume", "work", "year");  //   var spanishparams = new Array( "fechaacceso", "urlarchivo", "arxiv", "en", "autor", "autor1", "autor2", "autor3", "autor4", "autor5", "enlaceautor1", "enlaceautor2", "enlaceautor3", "enlaceautor4", "enlaceautor5", "m&aacute;scaraautor", "bibcode", "publicaci\u00f3n", "cap&iacute;tulo", "url-cap&iacute;tulo", "fecha", "doi", "fecha-doi-roto", "edici\u00f3n", "nombre-editor", "nombre-editor2", "nombre-editor3", "nombre-editor4", "nombre-editor5", "apellido-editor", "apellido-editor2", "apellido-editor3", "apellido-editor4", "apellido-editor5", "enlace-editor", "enlace-editor2", "enlace-editor3", "enlace-editor4", "enlace-editor5", "nombre", "nombre1", "nombre2", "nombre3", "nombre4", "nombre5", "formato", "id", "isbn", "publicaci\u00f3n", "idioma", "apellido", "apellido1", "apellido2", "apellido3", "apellido4", "apellido5", "fecha-resumen", "resumen", "lugar-publicaci\u00f3n", "sinpp", "n\u00famero", "oclc", "a\u00f1o-original", "fecha-publicación", "p\u00e1gina", "p\u00e1ginas", "editorial", "cita", "ref", "serie", "t\u00edtulo", "t\u00edtulo-trad", "cap\u00edtulo-trad", "url", "volumen", "publicaci\u00f3n", "a\u00f1o");  //   //   // Uncomment the below to print out the "dictionary" used for translation    //   //for (var c=0; c");   //}   //   //   var englishformats = new Array( "article", "book", "conference", "journal", "news", "web");   //   var spanishformats = new Array( "publicaci\u00f3n", "libro", "publicaci\u00f3n", "publicaci\u00f3n", "publicaci\u00f3n", "web" );   //   //   // template[0] is "cite book", "cite web", etc.;   // the other elements are parameters and values, separated by "=".   //   // Figure out what format the document is in (book, web, etc.)   //   var thisformat = template[0].substring(template[0].indexOf(" ")+1, template[0].length);   thisformat = thisformat.trim(thisformat);   //      var outputtemplate = "" is included in the last parameter value //  return outputtemplate; } //

var engtemplate = ""; while (engtemplate !== "DONE"){ engtemplate = prompt( "Enter the template to translate; enter 'DONE' to quit:"); if (engtemplate !== "DONE") { alert("The translated template is: " + TranslateOne( engtemplate )); } }