User:DavRosen/SidebarReorderTranslate.js

//

// Changes sidebar language links to use Google Translate, rearranges them in a specific order, & displays their English names.

//

// The order was chosen based roughly on how many translation engines (of three I knew) support the language, then

// translatability/relatedness to English (Romance ahead of Germanic due to difficulty of verb grammar differences),

// and then some quirky measures based on avg edits per article, active users, etc.

// No doubt you would choose a different order. If you wonder why some small wikipedias are so high on the list,

// remember that it only shows up on a page when that language *does* have an article; how many *other* articles it has is

// less important than the likelihood that this one is good. A WP with very few articles will seldom have a link at all,

// no matter how high it may be on the overall list here.

// (Originally from DavRosen's bookmarklet WpSortLangLinks+LinksToGoogTranslV2draft)

//

// Bugs:

// o Removes the special bullets that identify languages having particularly good articles

// o When clicking on the edit link of a specific section, it has you editing the *next* section instead.

// o On articles with no language links, this script messes up the "Add links" link.

// o On certain pages such as the main page, it doesn't behave as expected...

//

addOnloadHook // for use as bookmarklet, comment out this line and uncomment the next

// javascript:

(function (){

var i, anchors;

var ul = document.querySelectorAll('div#p-lang')[0].querySelectorAll('ul')[0];

ul.insertAdjacentHTML('afterbegin', "

  • English
  • Simple English
  • Spanish
  • French
  • Portuguese
  • Italian
  • Dutch
  • German
  • Romanian
  • Danish
  • Norwegian
  • Swedish
  • Russian
  • Czech
  • Bulgarian
  • Polish
  • Greek
  • Arabic
  • Chinese
  • Turkish
  • Hebrew
  • Thai
  • Japanese
  • Korean
  • Hungarian
  • Finnish
  • Haitian
  • Latvian
  • Serbian
  • Slovenian
  • Slovak
  • Lithuanian
  • Persian
  • Urdu
  • Hindi
  • Classical Chinese
  • Estonian
  • Catalan
  • Afrikaans
  • Yiddish
  • Bosnian
  • Ukrainian
  • Croatian
  • Macedonian
  • Hausa
  • Lao
  • Bengali
  • Indonesian
  • Maltese
  • Somali
  • Khmer
  • Kannada
  • Tamil
  • Armenian
  • Pashto
  • Albanian
  • Azerbaijani
  • Icelandic
  • Marathi
  • Georgian
  • Belarusian
  • Irish
  • Telugu
  • Tagalog
  • Esperanto
  • Galician
  • Gujarati
  • Vietnamese
  • Welsh
  • Swahili
  • Latin
  • Norwegian (Nynorsk)
  • Malay
  • Javanese
  • Basque
  • Cebuano
  • Hmong
  • Xhosa
  • Cree
  • Chamorro
  • Twi
  • Akan
  • Ewe
  • Fula
  • Tumbuka
  • Sesotho
  • Chichewa
  • Inupiak
  • Dzongkha
  • Kirundi
  • Venda
  • Min Dong
  • Fijian
  • Tsonga
  • Luganda
  • Sango
  • Old Church Slavonic
  • Cherokee
  • Inuktitut
  • Bambara
  • Buryat (Russia)
  • Zulu
  • Gothic
  • Anglo-Saxon
  • Aromanian
  • Oromo
  • Abkhazian
  • Norfolk
  • Tigrinya
  • Kashmiri
  • Bislama
  • Cheyenne
  • Swati
  • Assamese
  • Pontic
  • Samoan
  • Sindhi
  • Kikuyu
  • Tswana
  • Karakalpak
  • Acehnese
  • Wu
  • Avar
  • Igbo
  • Romani
  • Nauruan
  • Malayalam
  • Lojban
  • Wolof
  • Lower Sorbian
  • Emilian-Romagnol
  • Egyptian Arabic
  • Lak
  • Papiamentu
  • Kongo
  • Zamboanga Chavacano
  • Bavarian
  • Mirandese
  • Oriya
  • Zazaki
  • Tok Pisin
  • Mongolian
  • Kabyle
  • Silesian
  • Aramaic
  • Cantonese
  • Crimean Tatar
  • Tahitian
  • Greenlandic
  • Extremaduran
  • Tetum
  • Ripuarian
  • Moksha
  • Kabardian Circassian
  • Sinhalese
  • Pennsylvania German
  • Latgalian
  • Banjar
  • Aymara
  • Meadow Mari
  • Chechen
  • Kinyarwanda
  • Zhuang
  • Franco-Provençal/Arpitan
  • Ladino
  • Alemannic
  • Guarani
  • Lezgian
  • Interlingue
  • Hakka
  • Erzya
  • Sardinian
  • Gagauz
  • Friulian
  • Cornish
  • Kalmyk
  • Palatinate German
  • Gan
  • Shona
  • Romansh
  • Karachay-Balkar
  • Sranan
  • Sorani
  • Ligurian
  • Dutch Low Saxon
  • Northern Sotho
  • Uyghur
  • Lingala
  • Divehi
  • Faroese
  • Punjabi
  • Navajo
  • Venetian
  • Picard
  • Saterland Frisian
  • Manx
  • Scots
  • Kashubian
  • West Flemish
  • Turkmen
  • Sanskrit
  • Komi
  • Tongan
  • Upper Sorbian
  • Hawaiian
  • Udmurt
  • Tibetan
  • Limburgish
  • Bihari
  • Ossetian
  • Min Nan
  • Aragonese
  • Central_Bicolano
  • Corsican
  • Asturian
  • Vepsian
  • Kurdish
  • Fiji Hindi
  • Zeelandic
  • Novial
  • Norman
  • Võro
  • Belarusian (Taraškievica)
  • Serbo-Croatian
  • Komi-Permyak
  • Amharic
  • Interlingua
  • Scottish Gaelic
  • Mingrelian
  • Sakha
  • Rusyn
  • Ilokano
  • Northern Sami
  • Nepali
  • West Frisian
  • Low Saxon
  • Gilaki
  • North Frisian
  • Kapampangan
  • Luxembourgish
  • Walloon
  • Breton
  • Samogitian
  • Nahuatl
  • Tajik
  • Neapolitan
  • Sicilian
  • Sundanese
  • Quechua
  • Maori
  • Chuvash
  • Pangasinan
  • Lombard
  • Ido
  • Mazandarani
  • Kirghiz
  • Burmese
  • Pali
  • Hill Mari
  • Tarantino
  • Bashkir
  • Occitan
  • Tatar
  • Western Panjabi
  • Banyumasan
  • Kazakh
  • Yoruba
  • Uzbek
  • Bishnupriya Manipuri
  • Buginese
  • Malagasy
  • Piedmontese
  • Volapük
  • Newar / Nepal Bhasa
  • Waray-Waray
  • Afar
  • Choctaw
  • Hiri Motu
  • Kanuri
  • Kuanyama
  • Marshallese
  • Moldovan
  • Muscogee
  • Ndonga
  • Sichuan Yi
  • ");

    anchors=ul.querySelectorAll('a');

    for (i=anchors.length; --i >= 0;){

    var x=anchors[i];

    var hsplit=x.hostname.split(".");

    var lang=hsplit[0];

    if (!x.title && !x.href) x.parentNode.style.display="none";

    if ( hsplit.length==3 && hsplit[1]=="wikipedia" && hsplit[2]=="org"){

    if (a=document.getElementById('SRTL-'+lang)){

    var hr=x.href;

    var ti=x.title+' ('+(x.textContent||'')+', '+lang+')';

    x.removeAttribute('href');

    x.parentNode.style.display="none";

    a.href=hr;

    if(!(a.title&&a.title!=''))a.title=ti;

    a.parentNode.setAttribute('class','interwiki-'+lang);

    a.parentNode.style.display=null;

    if(!(a.parentNode.getAttribute('style')&&a.parentNode.getAttribute('style')!='')) a.parentNode.removeAttribute('style');}}}

    /*javascript:*/

    /*wpLinksToMsTransl*/(function(){

    var i;for (i=document.links.length; --i >= 0;) {

    var x=document.links[i], hsplit=x.hostname.split("."), lang=hsplit[0];

    if (hsplit.length==3 && hsplit[1]=="wikipedia" && hsplit[2]=="org" && lang!="en" && lang!='simple' && x.hostname!=window.location.hostname) {

    var e=(document.charset||document.characterSet);

    /* x.appendChild(document.createTextNode(" ("+lang+")")); */ /*append parenthesized language code*/

    x.setAttribute('href','http://translate.google.com/translate?u='+encodeURI(

    'http://'+x.host+x.pathname+x.hash+x.search)+'&hl=en&langpair=auto|en&tbb=1&ie='+e);}}})()

    });

    //();

    // uncomment line above only for bookmarklet