Open main menu

Changes

m
replace template name in first sentence, it is shown in numbered list below
{{Documentation subpage}}
<!-- Please place categories where indicated at the bottom of this page and interwikis at Wikidata (see [[Wikipedia:Wikidata]]) -->

This is one of three templates used to automatically add conversions of weight measurements displayed by [[Template:Infobox person]] and other [[:Category:Infobox templates|infoboxes]] with a {{para|weight}} parameter.

# [[Template:Infobox person/weight]] changes text for units of weight to the abbreviations "kg", "lb", or "st", then passes the string to:
# [[Template:Infobox person/weight/locate]] which replaces any instances of <code>&amp;nbsp;</code> with a space, and determines the positions of "kg", "lb", or "st" within that string, all of which is passed to:
# [[Template:Infobox person/weight/switch]] which does the conversion

== Usage ==

* <code><nowiki>{{Template:Infobox person/weight/locate|108 kg}}</nowiki></code> &rarr; {{Template:Infobox person/weight/locate|108 kg}}
* <code><nowiki>{{Template:Infobox person/weight/locate|108&amp;nbsp;kg}}</nowiki></code> &rarr; {{Template:Infobox person/weight/locate|108&nbsp;kg}}
* <code><nowiki>{{Template:Infobox person/weight/locate|238 lb}}</nowiki></code> &rarr; {{Template:Infobox person/weight/locate|238 lb}}
* <code><nowiki>{{Template:Infobox person/weight/locate|238&amp;nbsp;lb}}</nowiki></code> &rarr; {{Template:Infobox person/weight/locate|238&nbsp;lb}}
* <code><nowiki>{{Template:Infobox person/weight/locate|17 st}}</nowiki></code> &rarr; {{Template:Infobox person/weight/locate|17 st}}
* <code><nowiki>{{Template:Infobox person/weight/locate|17&amp;nbsp;st}}</nowiki></code> &rarr; {{Template:Infobox person/weight/locate|17&nbsp;st}}
* <code><nowiki>{{Template:Infobox person/weight/locate|108 kg (2012)}}</nowiki></code> &rarr; {{Template:Infobox person/weight/locate|108 kg (2012)}}
* <code><nowiki>{{Template:Infobox person/weight/locate|108&amp;nbsp;kg (2012)<ref>citation goes here</ref>}}</nowiki></code> &rarr; {{Template:Infobox person/weight/locate|108&nbsp;kg (2012)<ref>citation goes here</ref>}}

<references />

== Exceptions ==

Does not replace numbers in hard-coded conversions (examples intentionally show incorrect conversions):

* <code><nowiki>{{Template:Infobox person/weight/locate|108 kg (229 lb)}}</nowiki></code> &rarr; {{Template:Infobox person/weight/locate|108 kg (229 lb)}}
* <code><nowiki>{{Template:Infobox person/weight/locate|238 lb (119 kg)}}</nowiki></code> &rarr; {{Template:Infobox person/weight/locate|238 lb (119 kg)}}
* <code><nowiki>{{Template:Infobox person/weight/locate|17 st (229 lb; 119 kg)}}</nowiki></code> &rarr; {{Template:Infobox person/weight/locate|17 st (229 lb; 119 kg)}}

Does not replace numeric output of conversion templates such as {{tl|convert}} (examples have precision different than usual):

* <code><nowiki>{{Template:Infobox person/weight/locate|{{convert|108|kg|lb|1|abbr=on}}}}</nowiki></code> &rarr; {{Template:Infobox person/weight/locate|{{convert|108|kg|lb|1|abbr=on}}}}
* <code><nowiki>{{Template:Infobox person/weight/locate|{{convert|238|lb|kg|2|abbr=on}}}}</nowiki></code> &rarr; {{Template:Infobox person/weight/locate|{{convert|238|lb|kg|2|abbr=on}}}}
* <code><nowiki>{{Template:Infobox person/weight/locate|{{convert|17|st|3|abbr=on}}}}</nowiki></code> &rarr; {{Template:Infobox person/weight/locate|{{convert|17|st|3|abbr=on}}}}

== Technical details ==

The following examples show how the template works:

=== kg ===
<pre>
{{Infobox person/weight/switch
|108&amp;nbsp;kg
|{{#invoke:String|replace|108&amp;nbsp;kg|&amp;nbsp;| }}
|k={{#invoke:String|find|{{#invoke:String|replace|108&amp;nbsp;kg|&amp;nbsp;| }}|kg}}
|s={{#invoke:String|find|{{#invoke:String|replace|108&amp;nbsp;kg|&amp;nbsp;| }}|st}}
|l={{#invoke:String|find|{{#invoke:String|replace|108&amp;nbsp;kg|&amp;nbsp;| }}|lb}}
}}
</pre>

Result:<br /><code>
<nowiki>{{Infobox person/weight/switch</nowiki>
<nowiki> |108&amp;nbsp;kg</nowiki>
<nowiki> |</nowiki>{{#invoke:String|replace|108&nbsp;kg|&nbsp;| }}
<nowiki> |k=</nowiki>{{#invoke:String|find|{{#invoke:String|replace|108&nbsp;kg|&nbsp;| }}|kg}}
<nowiki> |s=</nowiki>{{#invoke:String|find|{{#invoke:String|replace|108&nbsp;kg|&nbsp;| }}|st}}
<nowiki> |l=</nowiki>{{#invoke:String|find|{{#invoke:String|replace|108&nbsp;kg|&nbsp;| }}|lb}}
<nowiki>}}</nowiki>
</code>

=== lb ===
<pre>
{{Infobox person/weight/switch
|238&amp;nbsp;lb
|{{#invoke:String|replace|238&amp;nbsp;lb|&amp;nbsp;| }}
|k={{#invoke:String|find|{{#invoke:String|replace|238&amp;nbsp;lb|&amp;nbsp;| }}|kg}}
|s={{#invoke:String|find|{{#invoke:String|replace|238&amp;nbsp;lb|&amp;nbsp;| }}|st}}
|l={{#invoke:String|find|{{#invoke:String|replace|238&amp;nbsp;lb|&amp;nbsp;| }}|lb}}
}}
</pre>

Result:<br /><code>
<nowiki>{{Infobox person/weight/switch</nowiki>
<nowiki> |238&amp;nbsp;lb</nowiki>
<nowiki> |</nowiki>{{#invoke:String|replace|238&nbsp;lb|&nbsp;| }}
<nowiki> |k=</nowiki>{{#invoke:String|find|{{#invoke:String|replace|238&nbsp;lb|&nbsp;| }}|kg}}
<nowiki> |s=</nowiki>{{#invoke:String|find|{{#invoke:String|replace|238&nbsp;lb|&nbsp;| }}|st}}
<nowiki> |l=</nowiki>{{#invoke:String|find|{{#invoke:String|replace|238&nbsp;lb|&nbsp;| }}|lb}}
<nowiki>}}</nowiki>
</code>

=== st ===
<pre>
{{Infobox person/weight/switch
|17&amp;nbsp;st
|{{#invoke:String|replace|17&amp;nbsp;st|&amp;nbsp;| }}
|k={{#invoke:String|find|{{#invoke:String|replace|17&amp;nbsp;st|&amp;nbsp;| }}|kg}}
|s={{#invoke:String|find|{{#invoke:String|replace|17&amp;nbsp;st|&amp;nbsp;| }}|st}}
|l={{#invoke:String|find|{{#invoke:String|replace|17&amp;nbsp;st|&amp;nbsp;| }}|lb}}
}}
</pre>

Result:<br /><code>
<nowiki>{{Infobox person/weight/switch</nowiki>
<nowiki> |17&amp;nbsp;st</nowiki>
<nowiki> |</nowiki>{{#invoke:String|replace|17&nbsp;st|&nbsp;| }}
<nowiki> |k=</nowiki>{{#invoke:String|find|{{#invoke:String|replace|17&nbsp;st|&nbsp;| }}|kg}}
<nowiki> |s=</nowiki>{{#invoke:String|find|{{#invoke:String|replace|17&nbsp;st|&nbsp;| }}|st}}
<nowiki> |l=</nowiki>{{#invoke:String|find|{{#invoke:String|replace|17&nbsp;st|&nbsp;| }}|lb}}
<nowiki>}}</nowiki>
</code>

=== st/lb ===
<pre>
{{Infobox person/weight/switch
|17&amp;nbsp;st&amp;nbsp;7&amp;nbsp;lb
|{{#invoke:String|replace|17&amp;nbsp;st&amp;nbsp;7&amp;nbsp;lb|&amp;nbsp;| }}
|k={{#invoke:String|find|{{#invoke:String|replace|17&amp;nbsp;st&amp;nbsp;7&amp;nbsp;lb|&amp;nbsp;| }}|kg}}
|s={{#invoke:String|find|{{#invoke:String|replace|17&amp;nbsp;st&amp;nbsp;7&amp;nbsp;lb|&amp;nbsp;| }}|st}}
|l={{#invoke:String|find|{{#invoke:String|replace|17&amp;nbsp;st&amp;nbsp;7&amp;nbsp;lb|&amp;nbsp;| }}|lb}}
}}
</pre>

Result:<br /><code>
<nowiki>{{Infobox person/weight/switch</nowiki>
<nowiki> |17&amp;nbsp;st&amp;nbsp;7&amp;nbsp;lb</nowiki>
<nowiki> |</nowiki>{{#invoke:String|replace|17&nbsp;st&nbsp;7&nbsp;lb|&nbsp;| }}
<nowiki> |k=</nowiki>{{#invoke:String|find|{{#invoke:String|replace|17&nbsp;st&nbsp;7&nbsp;lb|&nbsp;| }}|kg}}
<nowiki> |s=</nowiki>{{#invoke:String|find|{{#invoke:String|replace|17&nbsp;st&nbsp;7&nbsp;lb|&nbsp;| }}|st}}
<nowiki> |l=</nowiki>{{#invoke:String|find|{{#invoke:String|replace|17&nbsp;st&nbsp;7&nbsp;lb|&nbsp;| }}|lb}}
<nowiki>}}</nowiki>
</code>

== See also ==
* [[Template:Infobox person]]
* [[Template:Infobox person/height]]
** [[Template:Infobox person/height/locate]]
** [[Template:Infobox person/height/switch]]
* [[Template:Infobox person/length]]
** [[Template:Infobox person/length/locate]]
** [[Template:Infobox person/length/switch]]

<includeonly>{{#ifeq:{{SUBPAGENAME}}|sandbox | |
<!-- Categories below this line, please; interwikis at Wikidata -->
[[Category:Template implementation details]]

}}</includeonly>
Anonymous user