Jump to content

MediaWiki:Gadget-TranslationAdder.js/documentation

From Wiktionary, the free dictionary
Documentation for MediaWiki:Gadget-TranslationAdder.js. [edit]
This page contains usage information, categories, interwiki links and other content describing the template.

Uses data in MediaWiki:Gadget-TranslationAdder-Data.js.

For usage instructions, see MediaWiki:Gadget-TranslationAdder.js/help.

Todo

Bugs/Enhancements
  • Handle API errors.
  • A field for additional edit summary
  • Reset checkboxes and fields when language code is changed
Features
  • Edit existing translations.
  • Add translation gloss.
  • Make gadget recognize special high-performance translation templates {{tt}}, {{tt+}}, {{multitrans}} (discussion).

Coding

This code adds an input box below the translation table and passes an edit-object to the Editor.js-script when the user press "preview". It stores settings in cookies for every time the user press save on the blue editor-popup.

At the basic level, edits can be made by passing an edit object to the editor. Edit objects consist of a "redo" function which modifies the page HTML to reflect the edit, an "undo" function which does exactly the opposite of "redo", an "edit" function which performs the edit, and a "summary" string to be added to the edit summary.

How to edit the code and test

Disable the gadget "Enable the buttons that allow editing of translation tables on by default" in Special:Preferences#mw-prefsection-gadgets. Make an editable version by copying the code in MediaWiki:Gadget-TranslationAdder.js to User:YourNameHere/scripts/TranslationAdder.js. (Put your name in place of YourNameHere and change the page name however you want.) Run this editable version by putting this code in Special:MyPage/common.js:

// This array of dependencies comes from [[MediaWiki:Gadgets-definition]].
// If the list of dependencies changes, copy the text after dependencies=
// for TranslationAdder and run console.log(JSON.stringify("paste dependencies here".split(/, ?/)))
// in your browser's JavaScript console. Put the resulting array as the first argument to mw.loader.using.
mw.loader.using(["ext.gadget.Editor","ext.gadget.LegacyScriptsNewNode","mediawiki.cookie","ext.gadget.LanguageUtils","mediawiki.util","ext.gadget.TranslationAdder-Data"],
function() {
	importScript('User:YourNameHere/scripts/TranslationAdder.js');
});

Edit and see if you can make any improvements.