Jump to content

User:Dereckson/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.
/*  -------------------------------------------------------------
    Call http://toolserver.org/~dereckson/translate
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Author:         Dereckson
    Tags:           toolserver translate
    Description:    Add a new tab 'Translate' to go to the tool
                    http://toolserver.org/~dereckson/translate
    Filename:       User:Dereckson/translate.js
    Version:        1.0
    Created:        2011-05-11
    Updated:        2011-05-11
    Licence:        Dual licensed: BSD and CC-BY 3.0
    Dependencies:   MediaWiki wikibits.js
    -------------------------------------------------------------    */

$(function () {
	var translate = {
		//The language you translate to
		targetLanguage: 'fr',

		//The language you translate from
		sourceLanguage: mw.config.get('wgDBname').substr(0, mw.config.get('wgDBname').length - 4),

		//The name of the link
		tabLinkName: 'Translate',

	        getLink: function () {
        	        return 'http://toolserver.org/~dereckson/translate/text.php?article=' + mw.config.get('wgPageName') + '&from=' + this.sourceLanguage + '&to=' + this.targetLanguage;
	        },

		//Initializes script
		initialize: function() {
			if (mw.config.get('wgNamespaceNumber') == 0) {
				mw.util.addPortletLink('p-cactions', this.getLink(), this.tabLinkName, "tab-translate", 'Translate to ' + this.targetLanguage, "t");
			}
		}
	};

	translate.initialize();
})