Multilingual Templates and Modules

Introduction
What is it? This project makes it possible for modules and templates to be used on multiple wikis, without any modifications. All translations are stored in one place, accessible from everywhere.

Why is this needed? Because we do not have a single Wikipedia, we have 300 separate Wikipedias plus many other projects, and every time someone creates a good new template or a Lua module, it has to be copied 300+ times. More importantly, each template has to be translated 300 times, which is often very difficult, in part because one has to thoroughly understand MediaWiki markup, and also because often authors assume templates will be used for just one language. Plus templates depend on other templates. Plus once copied, templates are often improved, and each copy has to be updated. The pure human expense of copying templates and modules is such, that most templates are either never copied or never updated, especially for the smaller wikis.

Is this the best approach? No, but it is the best approach with the current technology. A very significant MediaWiki rewrite is required to make this possible on the system level. This functionality has been requested from the start 18 years ago, but not much was done simply because this is a very hard problem to solve. With this approach it is possible to create multilingual content now, and once MediaWiki supports it, we can easily migrate this content to the new system without much work.

Method

 * DiBabel bot will copy templates and modules from mediawiki.org to all other sites/languages listed in Wikidata for that page, automatically changing the template and module names.
 * It will be copied ONLY if Wikidata item has "instance of" set to (Q63090714).
 * It will be copied ONLY if the current content of the page exists in the history of mediawiki.org's (origin) version. E.g. if a user modifies English version of the page, it will not be overwritten unless that exact text ever existed in the history of the page on mediawiki.org.  To resume automatic synchronization, a user must copy the latest version of the page from mediawiki.org. Note that simply reverting a page to an older version will not be enough to prevent a bot from copying it again. A page has to be different from any of origin's revisions (e.g. add a note why the page was modified).
 * Any template names will be automatically localized inside the wiki markup, e.g. text will become , as long as Template:MW name exists on mediawiki.org, and it has a corresponding template on the destination wiki. Shared templates should not use non-shared templates, as that may cause unexpected results.
 * Just like templates, modules text  will be converted to.

Quick Start
Here's how a simple template can be created and shared. This example does not contain any internationalized messages -- see next section for that.


 * Create a new template named Template:Shared/My_Simple_Box at mediawiki.org NOTE: Do not actually create this specific template, this is just an example. Your template should have a different name and content, and your template must not use any other templates and modules unless they are also shared.


 * Create a copy of this template on some other wiki, e.g. English Wikipedia, following enwiki's naming conventions, e.g. Template:My_Simple_Box (without the Shared/ prefix)
 * Create a new Wikidata item:
 * set the "instance-of" (P31) to Wikimedia multi-site page (Q63090714)
 * add a sitelink to mediawiki (Other sites section) to Template:Shared/My_Simple_Box
 * add a sitelink to enwiki (Wikipedia section) to Template:My_Simple_Box

You are done - now whenever the template on mediawiki is changed, the enwiki copy will be updated automatically (once the bot runs).

Requirements for the Shared Modules

 * Sandbox: Each module must have a .../sandbox sub-page with a copy of the module code (the code might have a few changes compared to the main module page)
 * Testcases: Each module must have a .../testcases page with good unit tests to ensure highly quality and stability of the shared module.
 * Testcases must use Module:ScribuntoUnit
 * Testcases must be able to run with both the module and module/sandbox versions (see TNT or TableTools examples)
 * Testcases should have require('Module:no globals') to avoid accidentally using non-declared variables
 * Documentation: Each module must have a good quality documentation in the /doc page:
 * The /doc page must start with.
 * If module has a translation table, add it as a second parameter in the warning, e.g.  would link to Data:I18n/Module:TNT.tab on Commons.
 * Add a quality control section at the top, listing the summary of the testcase runs for both the primary and the sandbox versions of the module. See Module:TNT for an example.
 * Document all public functions of the module.
 * Translations: module must not have any user-visible strings in any language. Instead, it should use TNT module to convert a message ID with optional parameters to a string for the current language. See below for an example.

Requirements for the Shared Templates

 * Translations: template must not have any user-visible strings in any language. Instead, it should use TNT module to convert a message ID with optional parameters to a string for the current language. See below for an example.
 * Documentation: Each template must have a good quality documentation in the /doc page:
 * The /doc page must start with.
 * If template has a translation table, add it as a second parameter in the warning, e.g.  would link to Data:I18n/Template:XX.tab on Commons.
 * Template one-line description and parameters must be stored in a template parameter table, see Translating Template Parameters below.
 * Insert  at the end of the /doc page, where Template_Name would mean Data:Templatedata/Template_Name.tab on Commons.
 * If possible, create a /testcases subpage to run unit tests.

Translating Content
There is very little value in having non-translated content copied as is. The Module:TNT was created specifically to solve that. Instead of storing English text in a module or a template, TNT allows them to be designed language-neutral, and store multilingual text in the tabular data pages on Commons. This way your module or template will use those translated strings (messages), or if the message has not yet been translated, will fallback to English. When someone updates the translation table, your page will automatically update (might take some time, or you can purge it), but no change in the template or module is needed on any of the wikis. This process is very similar to MediaWiki's localisation, and supports all standard localization conventions such as NaN undefineds and other parameters.

For a simple example, see Data:I18n/Template:Graphs.tab - a table with two messages, each message having a single parameter. By convention, all translation pages should have  Data:I18n/...  prefix to separate them from other types of data.

Global Modules
Just like templates, modules should also use TNT module for localization:

Translating Template Parameters
Template parameters are usually stored as a JSON templatedata block inside the template's /doc subpage. This makes it convenient to translate, but when a new parameter is added to a global template, all /doc pages need to be updated in every language. TNT helps with this by automatically generating the templatedata block from a table stored on Commons. Placing this line into every /doc sub-page will use Data:Templatedata/Graph:Lines.tab table to generate all the needed templatedata information in every language. Even if the local community has not translated the full template documentation, they will be able to see all template parameters, centrally updated.

Pending

 * Module:No globals (translations) -- implemented, needs to be moved to communities

Pages OK to use without synchronization
These templates and modules exist on most wikis, but contain too much language-specific customizations to benefit from this system. A shared module/template can rely on these in addition to any other shared module/templates. Any new wiki should copy and modify these templates by hand.


 * Template:Documentation -- most templates on most wikis use this template to show a documentation header on the template pages.
 * Module:Yesno -- what each language accepts as "yes" and "no" for template parameters

Proposed

 * Module:I18n
 * - if i am not mistaken, this module does similar things to TNT, only it uses a sub-page with data. If so, any module that uses it would not use it once we convert it to TNT. --Yurik (talk)
 * Module:TableTools
 * - seems good, no translations needed. --Yurik (talk) 19:06, 7 May 2019 (UTC)
 * Module:Arguments
 * - while we can adapt it as is, we may also enhance it to allow parameter name translation table to come from Commons (many templates localize their parameters). --Yurik (talk) 19:06, 7 May 2019 (UTC)
 * Module:Navbar
 * Module:Infobox
 * - eventually yes, but I suspect infobox has some dependencies we need to solve first. --Yurik (talk) 19:06, 7 May 2019 (UTC)
 * - hard CSS dependencies. Missing navbar module can be handled with code. --Zache (talk) 02:01, 8 May 2019 (UTC)
 * Module:Location map
 * Module:String
 * - the _error function should be changed to accept (message_id, ...) (id + optional params). If not ignoring errors, use TNT to translate messages. --Yurik (talk)