MediaWiki:Gadget-SidebarTranslate.js

/* _____________________________________________________________________________ * |                                                                             | * |                    === WARNING: GLOBAL GADGET FILE ===                      | * |                 Changes to this page affect many users. | * | Please discuss changes on the talk page or on WT:Gadget before editing. | * |_____________________________________________________________________________| * * Imported from User:Equazcion/SidebarTranslate.js on 2013-11-27 * See User:Equazcion/SidebarTranslate * Note that when syncing to disable the importStylesheet call. */

var plang = $('#p-lang').hide;

$(document).ready( function {	function sort( a, b ) {		return ( $(b).text ) < ( $(a).text ) ? 1 : -1;	}	var plangUL = plang.find('ul');	var interwikis = plangUL.find('li[class^="interlanguage-link"]').detach;	if ( interwikis.length > 0 ) {		// importStylesheet('User:Equazcion/SidebarTranslate.css'); // loaded separately in gadget		var langReg = /(.*? – )?(.*)/;		var gtPre = 'http://translate.google.com/translate?hl=en&sl=auto&tl=en&u=';		var hardLangs = {			'lumbaart': 'Lombard', 			'tarandíne': 'Tarantino', 			'vèneto': 'Venetian', 			'Беларуская (тарашкевіца)': 'Belarusian (Taraškievica)',			'буряад': 'Buryat', 			'лакку': 'Lak'		};		var googleSupported = ['Afrikaans', 'Albanian', 'Arabic', 'Armenian', 'Azerbaijani', 'Basque', 'Belarusian', 'Bengali', 'Bulgarian',			'Catalan', 'Chinese', 'Croatian', 'Czech', 'Danish', 'Dutch', 'English', 'Esperanto', 'Estonian', 'Filipino', 'Finnish',			'French', 'Galician', 'Georgian', 'German', 'Greek', 'Haitian', 'Creole', 'Hebrew', 'Hindi', 'Hungarian', 'Icelandic',			'Indonesian', 'Irish', 'Italian', 'Japanese', 'Javanese', 'Kannada', 'Korean', 'Khmer', 'Latin', 'Latvian', 'Lithuanian',			'Macedonian', 'Malay', 'Maltese', 'Marathi', 'Norwegian', 'Norwegian (bokmål)', 'Norwegian Nynorsk', 'Persian', 'Polish', 'Portuguese', 'Romanian', 'Russian', 'Serbian', 'Slovak', 'Slovenian', 'Spanish', 'Swahili', 'Swedish', 'Tamil', 'Telugu', 'Thai', 'Turkish', 'Ukrainian', 'Urdu', 'Vietnamese', 'Welsh', 'Yiddish']; interwikis.find('a').each( function {			var $this = $(this);			var origLangName = $this.text;			var langMatches = langReg.exec( $this.attr('title') );			if ( langMatches != null ) {				var newLangName = (langMatches[2] in hardLangs) ? hardLangs[ langMatches[2] ] : langMatches[2];					if ( $this.attr('hreflang') == 'be-x-old' ) newLangName = 'Belarusian (Taraškievica)'; // Doesn't match object key for some reason				var hrefs = $this.attr('href');				$this.text( newLangName ).removeAttr('lang style').attr( 'title', 'Original language name: ' + origLangName );				var unsup = ( googleSupported.indexOf(langMatches[2]) < 0 ) ? '#FA8540' : '#4085FA';				$('', { 'text': 'G', 'class': 'external gTrans', 'target': '_blank', 'href': gtPre + hrefs, 'title': 'Google Translate: ' + newLangName + ' to English', 'style': 'color:' + unsup + ';' }).insertAfter( $this ).before(' ');				if ( $this.text.length > 17 ) $this.html( $this.html.replace('-','- ').replace(' ', ' ') );				$this.siblings('.gTrans').hover( function { $(this).css( {'background-color': unsup, 'color': 'white'} ) }, function { $(this).css( {'background-color': 'transparent', 'color': unsup} ) } );				$this.parent('li').hover( function { $(this).find('.gTrans').fadeIn(200).css('margin-left','0') }, function { $(this).find('.gTrans').fadeOut(100).css('margin-left','5px') } );			}		});		plangUL.prepend( interwikis.sort(sort) ); }	plang.show; });