User:V111P/js/Wiki Translation Tools

From Wikipedia, the free encyclopedia
< User:V111P‎ | js

Wiki Translation Tools is a user script for finding categories, filling the {{Translated page}} template, etc. when translating an article to or from another Wikipedia. The script is used in the Wikipedia where the original article is, then the resulting wiki code is copied to the article in the target Wikipedia. The script creates two new links in the Tools menu:

  • Cat/Tr/Comm
  • Links to ?

The results are shown in text input elements so that the text can be copied easily with Ctrl-C.

You can edit this page. If I don't like or understand something you wrote, I will correct it. ;)

Setting the language of your target wiki[edit]

If you installed this script directly from Wikipedia:User scripts you didn't set the language of your target wiki (the wiki you are translating articles to). In this case on clicking either of the two portlet links, you will be asked to enter the language code of your target wiki. That code will then be saved to your browsers' localStorage. To delete this entry, click on the link in the lower right corner of the panel which opens when you click the Cat/Tr/Comm portlet link, delete everything in the input box in the prompt window and press OK. See Installation below to see how to configure your target wiki in your common.js file.

The Cat/Tr/Comm function[edit]

The first link (an abbreviation from: Categories / {{Translated page}} / Commons), when clicked, first shows a list with the categories the page is in and gives you the chance to find corresponding categories in your target wiki. The [+] link next to a category name checks for a interwiki in that category and if none is found, reveals its parent categories. (If the article is in less than five categories, all of them are opened automatically.) Unfortunately the category trees in the different wikis do not always match exactly, but you should eventually reach a common parent category. When a category in your target wiki is found, it is listed and a checkbox appears next to its name. You have to check the checkbox to cause that category to appear in the final result. The @ sign next to a checkbox indicates that the interwiki-linked article in your target wiki already is in that category. Above the list with the categories you can select which other elements you want in the result. To get the final wikicode, click the OK button.

The resulting wikicode contains the selected categories (if you checked any) and depending on the check boxes you checked on top of the panel:

  • a filled template {{Translated page}} (you can configure the names of the template and its parameters so they match the template you use in your wiki, see Installation below)
  • the templates {{Commons}}, {{Commons category}}, and {{Wikiatlas}} (if there are links to Commons on the page)
  • interwikis - this option is turned off by default since the interwikis are no longer needed on most types of pages in Wikipedia. It adds the current wiki's article to the interwiki list, removes the target wiki from the list, and sorts it.

The Links to ? function[edit]

The ? part is the language code of your target wiki. Lets say your target wiki code is es. When you click on the portlet link, next to every wikilink in the page, another link will be added, looking like this: [[es:?]]. (Adding these links may take a couple of seconds on large articles.) When you click on such a link a text input element is added next to it with the name of the article in your target wiki, and before it - es: is a link to it (opens in another window/tab). If the link in the current article is a redirect, a greater than sign > is also added, and hovering over it with the mouse shows the name of the article to which the redirect redirects. If there is no corresponding article in your target wiki, the link changes to: [[es:?]]

Click again on the portlet link to remove all added elements from the page.

Installation[edit]

In the English Wikipedia[edit]

Add this to your common.js:

window.wikiTranslToolsConfig = {
	targetWiki: {
		lang: 'en',
		translatedPageTemplate: '{{Translated page|%sourceWiki%|%pageTitle%|version=%revisionId%}}'
	}
};
importScript('User:V111P/js/wikiTranslTools.js'); // [[User:V111P/js/wikiTranslTools.js]]

In the code above, you need to change en on the line lang: 'en', to the language code of your wiki, and on the next line you need to set up your Translated page template: %sourceWiki%, %pageTitle% and %revisionId% are variables which the script will replace with real values, so don't change them, just place them wherever they should go on your template (or delete them, if you don't need them). Change the name of the template and the names and positions of the parameters if you have to. If your wiki doesn't use a Translated page template, set the whole value to none: translatedPageTemplate: 'none'

In other Wikipedias[edit]

As for the English Wikipedia, but replace the importScript(...) line with:

mw.loader.load('//en.wikipedia.org/w/index.php?title='
	+ 'User:V111P/js/wikiTranslTools.js&action=raw&ctype=text/javascript');

Let me know if you are using on other wikis, because I can't see that, but I would like to know.

See also[edit]