Jump to content

User:Manishearth/sidebartranslinks.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
// This script is by User:Manishearth, using a script by User:Tra with changes by User:TheDJ and User:Voice_of_All
// It adds little (t) links next to the languages which, when clicked, directly translated the page via Google translate
// I have made it primarily as a research tool, as one can get ten times the info on enwiki by going through the other language wikis
// Screenshot at [[:File:Sidebartrans.jpg]]

var SidebarTrans = {};
  //The list of google translate languages
SidebarTrans.googlangs = "Afrikaans,Albanian,Arabic,Armenian,Azerbaijani,Basque,Belarusian,Bulgarian,Catalan,Chinese,Croatian,Czech,Danish,Dutch,English,Estonian,Filipino,Finnish,French,Galician,Georgian,German,Greek,Haitian,Creole,Hebrew,Hindi,Hungarian,Icelandic,Indonesian,Irish,Italian,Japanese,Korean,Latvian,Lithuanian,Macedonian,Malay,Maltese,Norwegian,Persian,Polish,Portuguese,Romanian,Russian,Serbian,Slovak,Slovenian,Spanish,Swahili,Swedish,Thai,Turkish,Ukrainian,Urdu,Vietnamese,Welsh,Yiddish"
SidebarTrans.langsArray = SidebarTrans.googlangs.split(",");

// run by addOnloadHook
SidebarTrans.init = function() {
  if ( !document.getElementById('p-lang') ) return;
  SidebarTrans.languageReplace();
  SidebarTrans.addTranslate();
}

// Add (t) link to Google Translate
SidebarTrans.addTranslate = function() {
  var LangNodes=document.getElementById('p-lang').getElementsByTagName('li');

  for( var x = 0; x < LangNodes.length; x++ ) {
    LangNodes[x].innerHTML=LangNodes[x].innerHTML + " " + SidebarTrans.mkLink(LangNodes[x]);
  }
}

// Creates the (t) links
SidebarTrans.mkLink = function( li ) {
  var a = li.getElementsByTagName('a')[0];
  if(!a) return "";
  var lname = a.textContent;
 
  if(SidebarTrans.googleSupported(lname)) {
    return ("<a href=\"http://translate.google.com/translate?hl=en&sl=auto&tl=en&u=" + a.href +
    "\" title=\"Translate " + lname + " to English\" ><b>(t)</b></a>");
  } else {
    return ("<a href=\"http://translate.google.com/translate?hl=en&sl=auto&tl=en&u=" + a.href +
    "\" title=\"Attempt to translate " + lname + " to English\" style=\"color: #FF8888;\" >(t)</a>");
  }
}

// Checks if the language is supported by Google Translate
SidebarTrans.googleSupported = function(lname) {
  for( var i=0;i<SidebarTrans.langsArray.length;i++){
    if(lname.indexOf(SidebarTrans.langsArray[i])!=-1){
      return true;
    }
  }
  return false;
}


 //This is a utility, made by User:Tra, modified by User:Manishearth to power this script:
 /////////////////////////////////////////////////////////////////////////
 // Translates the 'in other languages' list in the sidebar to English. //
 //               Note: does not translate all languages                //
 //                                                                     //
 //                                By Tra                               //
 //                       (bug fix by Voice_of_All)                     //
 /////////////////////////////////////////////////////////////////////////

SidebarTrans.languageReplace = function() {
  var LangNodes=document.getElementById('p-lang').getElementsByTagName('li');

  for( var x = 0; x < LangNodes.length; x++ ) {
  	var a = LangNodes[x].getElementsByTagName('a')[0];
    if(a) {
      a.title="Original language name: " + a.textContent;
      a.textContent = SidebarTrans.localtoEnglish( a.textContent );
    }
  }
}
 
SidebarTrans.localtoEnglish = function(localname) {
switch (localname) {

case 'Deutsch': return 'German'; break;
case 'Français': return 'French'; break;
case 'Polski': return 'Polish'; break;
case '日本語': return 'Japanese'; break;
case 'Nederlands': return 'Dutch'; break;
case 'Italiano': return 'Italian'; break;
case 'Português': return 'Portuguese'; break;
case 'Svenska': return 'Swedish'; break;
case 'Español': return 'Spanish'; break;
case 'Русский': return 'Russian'; break;
case '中文': return 'Chinese'; break;
case 'Suomi': return 'Finnish'; break;
case 'Norsk \(bokm\ål\)‬': return 'Norwegian (bokmål)'; break;
case '‪Norsk (nynorsk)‬': return 'Norwegian (nynorsk)'; break;
case 'Esperanto': return 'Esperanto'; break;
case 'Slovenčina': return 'Slovak'; break;
case 'Dansk': return 'Danish'; break;
case 'Česky': return 'Czech'; break;
case 'עברית': return 'Hebrew'; break;
case 'Català': return 'Catalan'; break;
case 'Magyar': return 'Hungarian'; break;
case 'Bahasa Indonesia': return 'Indonesian'; break;
case 'Română': return 'Romanian'; break;
case 'Українська': return 'Ukrainian'; break;
case 'Српски / Srpski': return 'Serbian'; break;
case 'Türkçe': return 'Turkish'; break;
case 'Slovenščina': return 'Slovenian'; break;
case 'Lietuvių': return 'Lithuanian'; break;
case 'Български': return 'Bulgarian'; break;
case '한국어': return 'Korean'; break;
case 'Eesti': return 'Estonian'; break;
case 'Hrvatski': return 'Croatian'; break;
case 'తెలుగు': return 'Telugu'; break;
case 'العربية': return 'Arabic'; break;
case 'Galego': return 'Galician'; break;
case 'Norsk (nynorsk)': return 'Nynorsk'; break;
case 'ไทย': return 'Thai'; break;
case 'فارسی': return 'Persian'; break;
case 'Ελληνικά': return 'Greek'; break;
case 'Bahasa Melayu': return 'Malay'; break;
case 'Euskara': return 'Basque'; break;
case 'Ido': return 'Ido'; break;
case 'Nnapulitano': return 'Neapolitan'; break;
case 'বাংলা': return 'Bengali'; break;
case 'Íslenska': return 'Icelandic'; break;
case 'ქართული': return 'Georgian'; break;
case 'Simple English': return 'Simple English'; break;
case 'Tiếng Việt': return 'Vietnamese'; break;
case 'Bosanski': return 'Bosnian'; break;
case 'Lëtzebuergesch': return 'Luxembourgish'; break;
case 'Brezhoneg': return 'Breton'; break;
case 'Shqip': return 'Albanian'; break;
case 'Македонски': return 'Macedonian'; break;
case 'Walon': return 'Walloon'; break;
case 'Srpskohrvatski / Српскохрватски': return 'Serbo-Croatian'; break;
case 'Latina': return 'Latin'; break;
/* case 'Krèyol ayisyen': return 'Haitian'; break; */
case 'Sicilianu': return 'Sicilian'; break;
case 'Kurdî / كوردی': return 'Kurdish'; break;
case 'Сибирской': return 'Siberian/Nort Russian'; break;
case 'Latviešu': return 'Latvian'; break;
case 'मराठी': return 'Marathi'; break;
case 'Asturianu': return 'Asturian'; break;
case 'Afrikaans': return 'Afrikaans'; break;
case 'Basa Sunda': return 'Sundanese'; break;
case 'Occitan': return 'Occitan'; break;
case 'Ripoarisch': return 'Ripuarian'; break;
case 'Беларуская': return 'Belarusian'; break;
case 'Cymraeg': return 'Welsh'; break;
case 'Tagalog': return 'Tagalog'; break;
case 'O\'zbek': return 'Uzbek'; break;
case 'தமிழ்': return 'Tamil'; break;
case 'Corsu': return 'Corsican'; break;
case 'Aragonés': return 'Aragonese'; break;
case 'Чăвашла': return 'Chuvash'; break;
case 'ಕನ್ನಡ': return 'Kannada'; break;
case 'Gàidhlig': return 'Scottish Gaelic'; break;
case 'Gaeilge': return 'Irish Gaelic'; break;
case 'Tatarça/Татарча': return 'Tatar'; break;
case 'Azərbaycan': return 'Azeri'; break;
case 'Vèneto': return 'Venetian'; break;
case 'हिन्दी': return 'Hindi'; break;
case 'Basa Jawa': return 'Javanese'; break;
case 'Тоҷикӣ': return 'Tajik'; break;
case 'Frysk': return 'West Frisian'; break;
case 'اردو': return 'Urdu'; break;
case 'Interlingua': return 'Interlingua'; break;
case 'Plattdüütsch': return 'Low Saxon'; break;
case 'Lumbaart': return 'Lombard'; break;
case 'Alemannisch': return 'Alemannic'; break;
case 'Հայերեն': return 'Armenian'; break;
case 'Limburgs': return 'Limburgian'; break;
case 'ייִדיש': return 'Yiddish'; break;
case 'Kiswahili': return 'Swahili'; break;
case 'Bân-lâm-gú': return 'Min Nan'; break;
case 'Ilokano': return 'Ilokano'; break;
case 'Føroyskt': return 'Faroese'; break;
case 'Piemontèis': return 'Piedmontese'; break;
case 'Nouormand': return 'Norman'; break;
case 'Arpitan': return 'Franco-Provençal/Arpitan'; break;
case 'Winaray': return 'Waray-Waray'; break;
case 'Scots': return 'Scots'; break;
case 'Kapampangan': return 'Kapampangan'; break;
case 'Иронау': return 'Ossetian'; break;
case 'Furlan': return 'Friulian'; break;
case 'Cebuano': return 'Cebuano'; break;
case '粵語': return 'Cantonese'; break;
case 'Nedersaksisch': return 'Dutch Low Saxon'; break;
case 'മലയാളം': return 'Malayalam'; break;
case 'Kernewek': return 'Cornish'; break;
case 'Deitsch': return 'Pennsylvania German'; break;
case 'नेपाल भाषा': return 'Newar / Nepal Bhasa'; break;
case 'Uyghurche‎ / ئۇيغۇرچە': return 'Uighur'; break;
case 'Líguru': return 'Ligurian'; break;
case 'Novial': return 'Novial'; break;
case 'Basa Banyumasan': return 'Banyumasan'; break;
case 'Sámegiella': return 'Northern Sami'; break;
case 'Ladino': return 'Ladino'; break;
case 'Kaszëbsczi': return 'Kashubian'; break;
case 'Malti': return 'Maltese'; break;
case 'Volapük': return 'Volapük'; break;
case 'አማርኛ': return 'Amharic'; break;
case 'Anglo Saxon': return 'Anglo-Saxon'; break;
case 'پښتو': return 'Pashto'; break;
case 'West-Vlaoms': return 'West Flemish'; break;
case 'संस्कृत': return 'Sanskrit'; break;
case 'Žemaitėška': return 'Samogitian'; break;
case 'Võro': return 'Voro'; break;
case 'Māori': return 'Maori'; break;
case 'Zazaki': return 'Zazaki'; break;
case 'Runa Simi': return 'Quechua'; break;
case 'Молдовеняскэ': return 'Moldovan'; break;
case 'Reo Mā`ohi': return 'Tahitian'; break;
case 'Монгол': return 'Mongolian'; break;
case 'Lojban': return 'Lojban'; break;
case 'कश्मीरी - (كشميري)': return 'Kashmiri'; break;
case 'Nahuatl': return 'Nahuatl'; break;
case 'Türkmen': return 'Turkmen'; break;
case 'Tok Pisin': return 'Tok Pisin'; break;
case 'Interlingue': return 'Interlingue'; break;
case 'Кыргызча': return 'Kirghiz'; break;
case 'नेपाली': return 'Nepali'; break;
case 'Rumantsch': return 'Romansh'; break;
case 'ܕܥܒܪܸܝܛ': return 'Assyrian Neo-Aramaic'; break;
case 'Toki Pona': return 'Tokipona'; break;
case 'Lingala': return 'Lingala'; break;
case 'Ekakairũ Naoero': return 'Nauruan'; break;
case 'faka-Tonga': return 'Tongan'; break;
case 'Қазақша': return 'Kazakh'; break;
case 'Armâneashti': return 'Aromanian'; break;
case 'Удмурт': return 'Udmurt'; break;
case 'Wollof': return 'Wolof'; break;
case 'ગુજરાતી': return 'Gujarati'; break;
case 'Malagasy': return 'Malagasy'; break;
case 'བོད་ཡིག': return 'Tibetan'; break;
case 'Tetun': return 'Tetum'; break;
case 'ދިވެހިބަސް': return 'Divehi'; break;
case '文言': return 'Classical Chinese'; break;
case 'Romani': return 'Romani'; break;
case 'Sardu': return 'Sardinian'; break;
case 'Авар': return 'Avar'; break;
case 'Gaelg': return 'Manx'; break;
case 'Kongo': return 'Kongo'; break;
case '吴语': return 'Wu'; break;
case 'Pangasinan': return 'Pangasinan'; break;
case 'Башҡорт': return 'Bashkir'; break;
case 'ᏣᎳᎩ': return 'Cherokee'; break;
case 'සිංහල': return 'Sinhalese'; break;
case 'Bamanankan': return 'Bambara'; break;
case 'سنڌي': return 'Sindhi'; break;
case '𐌲𐌿𐍄𐌹𐍃𐌺': return 'Gothic'; break;
case 'Emilià': return 'Emilian-Romagnol'; break;
case 'Hornjoserbsce': return 'Upper Sorbian'; break;
case 'ភាសាខ្មែរ': return 'Khmer'; break;
case 'Gagana Samoa': return 'Samoan'; break;
case 'isiZulu': return 'Zulu'; break;
case 'Boarisch': return 'Bavarian'; break;
case 'ᐃᓄᒃᑎᑐᑦ/inuktitut': return 'Inuktitut'; break;
case 'Myanmasa': return 'Burmese'; break;
case 'Diné bizaad': return 'Navajo'; break;
case 'Словѣ́ньскъ / ⰔⰎⰑⰂⰡⰐⰠⰔⰍⰟ': return 'Old Church Slavonic'; break;
case 'Yorùbá': return 'Yoruba'; break;
case 'Kalaallisut': return 'Greenlandic'; break;
case 'Аҧсуа': return 'Abkhazian'; break;
case 'Hawai`i': return 'Hawaiian'; break;
case 'ລາວ': return 'Lao'; break;
case 'ਪੰਜਾਬੀ': return 'Punjabi'; break;
case 'Soomaaliga': return 'Somali'; break;
case 'Mìng-dĕ̤ng-ngṳ̄': return 'Min Dong'; break;
case 'seSotho': return 'Sesotho'; break;
case 'ইমার ঠার/বিষ্ণুপ্রিয়া মণিপুরী': return 'Bishnupriya Manipuri'; break;
case 'Papiamentu': return 'Papiamentu'; break;
case 'Avañe\'ẽ': return 'Guarani'; break;
case 'Aymar': return 'Aymara'; break;
case 'Kinyarwanda': return 'Kinyarwanda'; break;
case 'گیلکی': return 'Gilaki'; break;
case 'Zeêuws': return 'Zealandic'; break;
case 'isiXhosa': return 'Xhosan'; break;
case 'Na Vosa Vakaviti': return 'Fijian'; break;
case 'Bislama': return 'Bislama'; break;
case 'Коми': return 'Komi'; break;
case 'Tarandíne': return 'Tarantino'; break;
case 'Хальмг': return 'Kalmyk'; break;
case 'पािऴ': return 'Pali'; break;
case 'Setswana': return 'Tswana'; break;
case '(Cuengh)': return 'Zhuang'; break;
case 'Kanuri': return 'Kanuri'; break;
case 'Нохчийн': return 'Chechen'; break;
case 'Zamboangueño': return 'Zamboanga Chavacano'; break;
case 'هَوُسَ': return 'Hausa'; break;
case 'chiTumbuka': return 'Tumbuka'; break;
case 'Fulfulde': return 'Peul'; break;
case 'Twi': return 'Twi'; break;
case 'Igbo': return 'Igbo'; break;
case 'Nēhiyawēwin / ᓀᐦᐃᔭᐍᐏᐣ': return 'Cree'; break;
case 'ꆇꉙ': return 'Sichuan Yi'; break;
case 'Iñupiak': return 'Inupiak'; break;
case 'Kirundi': return 'Kirundi'; break;
case 'Luganda': return 'Luganda'; break;
case 'Afar': return 'Afar'; break;
case 'Sängö': return 'Sango'; break;
case 'Oromoo': return 'Oromo'; break;
case 'Chi-Chewa': return 'Chichewa'; break;
case 'chiShona': return 'Shona'; break;
case 'Hiri Motu': return 'Hiri Motu'; break;
case 'Akana': return 'Akan'; break;
case 'Norfuk / Pitkern': return 'Norfolk'; break;
case 'ᨅᨔ ᨕᨘᨁᨗ': return 'Buginese'; break;
case 'অসমীয়া': return 'Assamese'; break;
case 'Xitsonga': return 'Tsonga'; break;
case 'Eʋegbe': return 'Ewe'; break;
case 'Gĩkũyũ': return 'Kikuyu'; break;
case 'Kuanyama': return 'Kuanyama'; break;
case 'Tsetsêhestâhese': return 'Cheyenne'; break;
case 'Otsiherero': return 'Herero'; break;
case 'Ebon': return 'Marshallese'; break;
case 'भोजपुरी': return 'Bihari'; break;
case 'ትግርኛ': return 'Tigrinya'; break;
case 'Oshiwambo': return 'Ndonga'; break;
case 'Tshivenda': return 'Venda'; break;
case 'ଓଡ଼ିଆ': return 'Oriya'; break;
case 'SiSwati': return 'Swati'; break;
case 'Chamoru': return 'Chamorro'; break;
case 'Choctaw': return 'Choctaw'; break;
case 'Muscogee': return 'Muscogee'; break;
case 'Буряад': return 'Buryat (Russia)'; break;
case 'ཇོང་ཁ': return 'Dzongkha'; break;
case 'مَزِروني': return 'Mazandarani'; break;
case 'Лакку': return 'Lak'; break;
case 'ܐܪܡܝܐ': return 'Aramaic'; break;
case 'Kreyòl ayisyen': return 'Haitian Creole'; break;
case 'Беларуская (тарашкевіца)': return 'Belarusian (Tarashkevitsa)'; break;
case 'Armãneashce': return 'Aromanian'; break;
case 'Hak-kâ-fa': return 'Hakka Chinese'; break;
case 'Мокшень': return 'Moksha'; break;
case 'Qırımtatarca': return 'Crimean Tatar'; break;
case 'Ślůnski': return 'Silesian'; break;
case 'Seeltersk': return 'Saterland Frisian'; break;
case 'Dolnoserbski': return 'Lower Sorbian'; break;
case 'Саха тыла': return 'Sakha'; break;
case '贛語': return 'Gan Chinese'; break;
case 'Estremeñu': return 'Extremaduran'; break;
case 'Newar / Nepal Bhasa': return 'Nepal Bhasa'; break;
case 'Taqbaylit': return 'Kabyle'; break;
case 'မြန်မာဘာသာ': return 'Burmese'; break;
case 'مصرى': return 'Egyptian Arabic'; break;
case 'Aymar aru': return 'Aymara'; break;
case 'Чӑвашла': return 'Chuvash'; break;
case 'Qaraqalpaqsha': return 'Karakalpak'; break;
case 'Ποντιακά': return 'Pontic'; break;
case 'Эрзянь' : return 'Erzya'; break;

default: return localname;
}
 
}

$(SidebarTrans.init)