Template:Infobox person/length/locate/doc

From MOASSpedia
Jump to navigation Jump to search

This is one of three templates used to automatically add conversions of length measurements displayed by infoboxes, such as the |reach= parameter in {{Infobox boxer}} or the |spike= and |block= parameters in {{Infobox volleyball biography}}.

  1. Template:Infobox person/length changes text for units of length to the abbreviations "in", "cm" or "m", then passes the string to:
  2. Template:Infobox person/length/locate which replaces any instances of   with a space, and determines the positions of "in", "cm" or "m" within that string, all of which is passed to:
  3. Template:Infobox person/length/switch which does the conversion

Usage

  • {{Template:Infobox person/length/locate|198 cm}} → 198 cm (78 in)
  • {{Template:Infobox person/length/locate|198 cm}} → 198 cm (78 in)
  • {{Template:Infobox person/length/locate|78 in}} → 78 in (198 cm)
  • {{Template:Infobox person/length/locate|78 in}} → 78 in (198 cm)
  • {{Template:Infobox person/length/locate|198 cm (2012)}} → 198 cm (78 in) (2012)
  • {{Template:Infobox person/length/locate|78&nbsp;in (2012)<ref>citation goes here</ref>}} → 78 in (198 cm) (2012)[1]
  1. ^ citation goes here

Exceptions

Does not replace numbers in manually entered conversions (examples intentionally show incorrect conversions):

  • {{Template:Infobox person/length/locate|198 cm (71 in)}} → 198 cm (71 in)
  • {{Template:Infobox person/length/locate|1.98 m (71 in)}} → 1.98 m (71 in)
  • {{Template:Infobox person/length/locate|78 in (191 cm)}} → 78 in (191 cm)
  • {{Template:Infobox person/length/locate|78 in (1.91 m)}} → 78 in (1.91 m)

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

  • {{Template:Infobox person/length/locate|{{convert|198|cm|in|2|abbr=on}}}} → 198 cm (77.95 in)
  • {{Template:Infobox person/length/locate|{{convert|1.98|m|in|2|abbr=on}}}} → 1.98 m (77.95 in)
  • {{Template:Infobox person/length/locate|{{convert|78|in|cm|1|abbr=on}}}} → 78 in (198.1 cm)
  • {{Template:Infobox person/length/locate|{{convert|78|in|m|3|abbr=on}}}} → 78 in (1.981 m)

Technical details

The following examples show how the template works:

cm

{{Infobox person/length/switch
  |{{{1|198&nbsp;cm}}}
  |{{#invoke:String|replace|{{{1|198&nbsp;cm}}}|&nbsp;| }}
  |c={{#invoke:String|find|{{#invoke:String|replace|{{{1|198&nbsp;cm}}}|&nbsp;| }}|cm}}
  |m={{#invoke:String|find|{{#invoke:String|replace|{{{1|198&nbsp;cm}}}|&nbsp;| }}|m}}
  |i={{#invoke:String|find|{{#invoke:String|replace|{{{1|198&nbsp;cm}}}|&nbsp;| }}|in}}
}}

Result:
{{Infobox person/length/switch |198&nbsp;cm |198 cm |c=5 |m=6 |i=0 }}

198 cm (78 in)

m

{{Infobox person/length/switch
  |{{{1|1.98&nbsp;m}}}
  |{{#invoke:String|replace|{{{1|1.98&nbsp;m}}}|&nbsp;| }}
  |c={{#invoke:String|find|{{#invoke:String|replace|{{{1|1.98&nbsp;m}}}|&nbsp;| }}|cm}}
  |m={{#invoke:String|find|{{#invoke:String|replace|{{{1|1.98&nbsp;m}}}|&nbsp;| }}|m}}
  |i={{#invoke:String|find|{{#invoke:String|replace|{{{1|1.98&nbsp;m}}}|&nbsp;| }}|in}}
}}

Result:
{{Infobox person/length/switch |1.98&nbsp;m |1.98 m |c=0 |m=6 |i=0 }}

1.98 m (78 in)

in

{{Infobox person/length/switch
  |{{{1|78&nbsp;in}}}
  |{{#invoke:String|replace|{{{1|78&nbsp;in}}}|&nbsp;| }}
  |c={{#invoke:String|find|{{#invoke:String|replace|{{{1|78&nbsp;in}}}|&nbsp;| }}|cm}}
  |m={{#invoke:String|find|{{#invoke:String|replace|{{{1|78&nbsp;in}}}|&nbsp;| }}|m}}
  |i={{#invoke:String|find|{{#invoke:String|replace|{{{1|78&nbsp;in}}}|&nbsp;| }}|in}}
}}

Result:
{{Infobox person/length/switch |78&nbsp;in |78 in |c=0 |m=0 |i=4 }}

78 in (198 cm)

See also