Usuario:Stargazer/Template Guide

De La Coppermind
Ir a la navegación Ir a la búsqueda

If you're going to be working with templates, I recommend going to the "Gadgets" section of your Preferences and turning on the syntax highlighter; it makes it a bit easier to tell what's going on.

Template Name

Calls to a template will follow a redirect, so you can move templates to a new name without issue, as long as you leave behind a redirect. As usual with page moves, make sure you fix any double redirects.

Parts of a Template

Broadly speaking, templates will be composed of four parts:

  1. Words that are part of the template output and are hard-coded into the template (i.e., they cannot be changed when you use the template). For example, the names of the rows on infoboxes (like "World," "Universe," "Featured in," etc.) fall into this category. These parts of a template should generally be able to be translated without issue.
  2. Parameters, which allow you to input information when using a template. In MediaWiki syntax, parameters are designated in a template with three curly brackets. Parameters can be either named or unnamed. In a template, named parameters will look like {{{name}}}. If a parameter is not named, MediaWiki identifies it with a number based on the order in which it is passed when the template is used, so unnamed parameters will look like {{{1}}}. Some parameters may also have a pipe (|) immediately after their name or number. Everything between the pipe and the ending curly braces is a default value; if, when the template is used, the editor doesn't specify a value for a parameter with a default value, the default value will be used instead. Some default values are nothing.
    • Named parameters can be translated if you want, though be aware that changing a parameter's name will mean that any page (including other templates) using the old parameter name won't work until each page is updated with the new parameter name.
    • Unnamed parameters shouldn't need to be translated.
    • Default values are generally hard-coded words, as discussed above.
  3. Most of the remainder of a template will be MediaWiki syntax. This includes parser functions like {{#if:...}} and {{#switch:...}}, partial transclusion tags like <noinclude>, instructions for creating a table (markup between a {| and a |}), and calls to other templates. Most of these, as far as I know, will not be translated. Calls to other templates should probably be updated when the parameters and name of the template being called are translated, so that they aren't broken until someone gets around to the template making the call.
  4. Comments are something of a special case. Anything that looks like <!-- comment text here --> won't show up when the template is used. This is often used to space out parts of the template to make it easier to read and, occasionally, to leave note for other editors about how a template works. Any text in a comment can be translated without concern.

Partial transclusion

By default, when you call a template, MediaWiki will import all of the contents of the template page. This usually is not desirable. Therefore, there are three partial transclusion tags that tell MediaWiki what parts to use when:

  • <noinclude>: This tag tells MediaWiki not to include anything after the tag when the template is used on a page. Usually, there will only be one <noinclude> tag in a template. Everything before the tag will be template code, everything after it will be documentation telling editors how the template works. So, only the parts before the <noinclude> tag need to be translated for the template to be "translated," though you'll want to translate the documentation as well, at least at some point.

The other partial transclusion tags are less relevant to translation:

  • <includeonly>: This tag tells MediaWiki to only include the content that follows when the template is called on another page, not the template page itself. For example, the {{character}} infobox automatically adds pages to Category: Characters. However, we don't want the template itself to show up in that category. So, the infobox template has the line <includeonly>[[Category: Characters]]</includeonly> (well, there are a few other things between the <includeonly> tags, but you get the point).
  • <onlyinclude>: This tag is used much less frequently. It tells MediaWiki that only the content that follows should be used when the template is called on another page (i.e., it effectively makes it as though the rest of the page has been subject to a <noinclude> tag)