From FamilySearch Wiki
Jump to navigation Jump to search

description 1=en 2=Helper template for passing parameters to templates using the Ajax in-line template translation feature|inline=



description 1=en 2=The value of the "args" parameter should be a list of template parameters separated by whitespace (not by "|"), with each parameter URL-encoded.|inline=

{{urlencode: 1={{{1|}}} }}
{{urlencode: 2={{{2|}}} }}
{{urlencode: foo={{{foo|}}} }}
{{urlencode: bar={{{bar|}}} }}


Parameter name Description Default value required or optional?

args inline= empty required
template inline= empty required

Additional information

The template is intended to be used in the following namespaces: the Template namespace

The template is intended to be used by the following user groups: all users


description 1=en 2=This template should be used on the "/layout" subpage of an autotranslated template, within the element with the "layouttemplate" class, preferably before any actual content.|inline=

Relies on:

See also

Using this template

These instructions assume that you're starting with a standard {{Autotranslate}}-style template (whether it actually uses {{Autotranslate}} or not) with the usual "/layout", "/lang" subpages and one or more "/xx" ISO 639 language code subpages.

Step 0: First, to enable the in-line translation feature for the template, the outermost containing element for each translated version must be given the "layouttemplate" class if it doesn't already have it. What this means in practice is that you should edit the "/layout" subpage of the template and add class="layouttemplate" to the first <div> tag or table there. (If it already has a class attribute, append "layouttemplate" to the value; e.g. replace class="someclass otherclass" with class="someclass otherclass layouttemplate". If the classes are specified via yet another template, edit that template instead.) If there is no single <div> or table that would enclose the entire content, you can add one: just wrap the whole thing in <div class="layouttemplate">...</div>. Finally, make sure there are no other elements with the "layouttemplate" class.

If the in-line translation feature already works for your template, you can skip the previous paragraph and start here. Also, if the template takes no parameters, you don't need to do anything more. If it does, do the following:

Step 1: Make sure all the parameters given to the template are passed to the "/layout" subpage. If not, you first need to edit all the translated versions of the template so that this is the case. For example, if your template takes three numbered parameters and the named parameter "foo", insert the following lines into each of the translated subpages:


Step 2: Edit the "/layout" subpage and insert {{LayoutTemplateArgs}} inside the element with the "layouttemplate" class, as early as possible. If the element is a div, you can just put it immediately after the <div> tag; if it's a table, put it at the beginning of the the first table cell. The value of the "args" parameter should contain all the parameters you want to have passed to the translated versions during in-line replacement, individually URL-encoded and separated by whitespace (i.e. spaces or linebreaks; not pipes as in normal template calls). For example, if your template takes the same parameters as above, and is named Template:FooBar, the code you should add to Template:FooBar/layout would be:

{{urlencode: 1={{{1|}}} }}
{{urlencode: 2={{{2|}}} }}
{{urlencode: 3={{{3|}}} }}
{{urlencode: foo={{{foo|}}} }}

Now test your template to see that it works as expected. If not, fix it or ask for help.

Known issues

There are a couple of known bugs in this template and in the associated Ajax translation script, including:

Parameters containing <nowiki>, <pre>, <poem>, <ref>, <gallery>, etc. tags turn into gibberish cause the in-line replacement not to work.

This is a known bug in the MediaWiki {{:}} parser function: when given input containing "parser extension tags", those tags and their content get replaced by internal "strip markers" which look something like "&#x7F;UNIQ77ef13a860481bc0-nowiki-00000010-QINU&#x7F;". Unfortunately, there's no way for the Ajax translation script to work out what the content replaced by such strip markers might've originally been. The current implementation reverts to opening the translated template on a new page if it detects any strip markers in the parameters.

Very long parameter values cause the in-line replacement not to work.

The in-line replacement code uses a MediaWiki API query to load the translated version of the template. For simplicity and efficiency, the current implementation uses HTTP GET requests to access the API, which means that the name of the template and all the parameters are included in the query URL. If this URL gets longer than about 4 kilobytes, the servers will reject it as excessively long. The current code simply refuses to generate such long URLs, and reverts to opening the translated template on a new page instead.

Autotranslated templates included in parameters will be shown in the user's default language even after in-line replacement.

This happens simply because those templates get parsed and expanded before the Ajax translation code ever sees them. Note that passing complex templates in parameters is also likely to trigger the previous bug as well.