Jump to content

User:Danski454/translate.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.
$(function(){
	var lang = "en";
	var text = "Translation";
	var url = document.location.toString().replace(/#.*/, "");//get url w/o fragment
	if (typeof window.translateLang === "string" && window.translateLang){
		lang = window.translateLang; // use window.translateLang = "es"; to switch target to spanish (for example)
	}
	if (typeof window.inactiveLang === "string" && window.inactiveLang === mw.config.get("wgContentLanguage")){
		return; // use window.inactiveLang = translateLang; to disable transaltion for your native language
	}
	if (typeof window.translateText === "string" && window.translateText){
		text = window.translateText; // use window.translateText = "Something"; to localise link text
	}
	//force current skin to be used
	if (url.match(/\?/)) {
		url = url + '&useskin=' + mw.config.get('skin');
	} else {
		url = url + '?useskin=' + mw.config.get('skin');
	}
	mw.util.addPortletLink ("p-tb", "https://translate.google.com/translate?sl=auto&tl=" + lang + "&u=" + encodeURIComponent(url), text, "tb-translate");
});