Changes

Jump to navigation Jump to search
use TemplateData
{{TemplateBox
|1=args
|1label-en=parameters
|1d-en=List of template parameters, URL-encoded and separated by whitespace (see above)
|1type=content
|1def=
|1stat=required

|2=template
|2label-en=template name
|2d-en=The name of the template for which these parameters are meant for, without the "Template:" prefix
|2type=wiki-template-name
|2def=
|2stat=required

|name=LayoutTemplateArgs
|desc-en=Helper template for passing parameters to templates using the [[MediaWiki talk:AjaxTranslation.js|Ajax in-line template translation]] feature
|desc-td-en=Helper template for passing parameters to templates using the Ajax in-line template translation feature
|namespace=10
|usergroup=all
|placement={{en|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.}}
|usage-notes={{en|The value of the "args" parameter should be a list of template parameters separated by whitespace (''not'' by "|"), with each parameter URL-encoded.}}

'''Example:'''<br />
<tt>
&#123;&#123;LayoutTemplateArgs&#124;template=<var>&lt;Template name&gt;</var>&#124;args=<br />
&#123;&#123;urlencode: 1=&#123;&#123;&#123;1&#124;&#125;&#125;&#125; &#125;&#125;<br />
&#123;&#123;urlencode: 2=&#123;&#123;&#123;2&#124;&#125;&#125;&#125; &#125;&#125;<br />
&#123;&#123;urlencode: foo=&#123;&#123;&#123;foo&#124;&#125;&#125;&#125; &#125;&#125;<br />
&#123;&#123;urlencode: bar=&#123;&#123;&#123;bar&#124;&#125;&#125;&#125; &#125;&#125;<br />
&#125;&#125;
</tt>

|type=
|example=
|i18n-method=-
|i18n-desc=
|seealso=
* [[MediaWiki talk:AjaxTranslation.js]]
* [[Template:Autotranslate]]
|setscats=
|lines=
|shorthand=
|relieson=
* [[MediaWiki:AjaxTranslation.js]]
|useTemplateData=only
}}

== Using this template ==

These instructions assume that you're starting with a standard {{tl|Autotranslate}}-style template (whether it actually uses {{tl|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 [[MediaWiki talk:AjaxTranslation.js|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 <code>class="layouttemplate"</code> to the first &lt;div&gt; tag or table there. (If it already has a <code>class</code> attribute, append "layouttemplate" to the value; e.g. replace <code>class="someclass otherclass"</code> with <code>class="someclass otherclass layouttemplate"</code>. If the classes are specified via yet another template, edit that template instead.) If there is no single &lt;div&gt; or table that would enclose the entire content, you can add one: just wrap the whole thing in <code>&lt;div class="layouttemplate"&gt;...&lt;/div&gt;</code>. 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:

<pre>
|1={{{1|}}}
|2={{{2|}}}
|3={{{3|}}}
|foo={{{foo|}}}
</pre>

'''Step 2:'''
Edit the "/layout" subpage and insert <code>{{tl|LayoutTemplateArgs|2=template=...&#124;args=...}}</code> ''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 &lt;div&gt; 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:

<pre>
{{LayoutTemplateArgs|template=&lt;Template name&gt;|args=
{{urlencode: 1={{{1|}}} }}
{{urlencode: 2={{{2|}}} }}
{{urlencode: 3={{{3|}}} }}
{{urlencode: foo={{{foo|}}} }}
}}
</pre>

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 [[MediaWiki:AjaxTranslation.js|Ajax translation script]], including:

'''Parameters containing &lt;nowiki&gt;, &lt;pre&gt;, &lt;poem&gt;, &lt;ref&gt;, &lt;gallery&gt;, etc. tags <s>turn into gibberish</s> cause the in-line replacement not to work.'''
:This is a known bug in the MediaWiki &#123;&#123;[[mw:Help:Magic words#URL data|urlencode]]:&#125;&#125; 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 [[mw:API|MediaWiki API query]] to load the translated version of the template. For simplicity and efficiency, the current implementation uses [[w:HTTP GET|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.
Anonymous user

Navigation menu