Template:LayoutTemplateArgs/docEdit This Page

From FamilySearch Wiki

English: Helper template for passing parameters to templates using the Ajax in-line template translation feature

Contents

Usage

{{LayoutTemplateArgs|args=|template=}}

English: The value of the "args" parameter should be a list of template parameters separated by whitespace (not by "|"), with each parameter URL-encoded.

Example:
{{LayoutTemplateArgs|template=FooBar|args=
{{urlencode: 1={{{1|}}} }}
{{urlencode: 2={{{2|}}} }}
{{urlencode: foo={{{foo|}}} }}
{{urlencode: bar={{{bar|}}} }}
}}

Parameters

Parameter name Description Default value required or optional?

args
English: List of template parameters, URL-encoded and separated by whitespace (see above)
empty required
template
English: The name of the template for which these parameters are meant for, without the "Template:" prefix
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

Placement:

English: 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.

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:

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

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:

{{LayoutTemplateArgs|template=FooBar|args=
{{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 {{urlencode:}} parser function: when given input containing "parser extension tags", those tags and their content get replaced by internal "strip markers" which look something like "UNIQ77ef13a860481bc0-nowiki-00000010-QINU". 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.
  • This page was last modified on 24 February 2012, at 00:12.
  • This page has been accessed 93 times.