Template:Infobox person/weight/locate
{{#switch:0
|000= |00={{#iferror:{{#expr:Lua error: bad argument #1 to 'gsub' (string is not UTF-8).}} | |[convert: needs a number] }} |00={{#iferror:{{#expr:Lua error: bad argument #1 to 'gsub' (string is not UTF-8).}} | |[convert: needs a number] }} |00={{#iferror:{{#expr:Lua error: bad argument #1 to 'gsub' (string is not UTF-8).}} | |[convert: needs a number] }} |0={{#iferror:{{#expr: + }} | |[convert: needs a number] }} |
}}
{{#ifeq:locate |doc
|
{{#ifeq:show |show
|This is a documentation subpage for Template:Infobox person/weight. It contains usage information, categories and other content that is not part of the original {{#if: |{{{text2}}} |{{#if: |{{{text1}}} |{{#ifeq:Template |User |template template page |{{#if:Template |template page|article}}}}}}}}. |
}}{{#if: | | {{#ifexist:Template:Infobox person/weight | [[Category:{{#switch:Template |Template=Template |Module=Module |User=User |#default=Wikipedia}} documentation pages]] | }} }} | }}
Template:Infobox person/weight is one of three templates used to automatically add conversions of weight measurements displayed by Template:Infobox person and other infoboxes with a |{{#if:weight|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
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[edit]
{{Template:Infobox person/weight/locate|108 kg}}
→ {{#switch:0
|500=108 kg |00={{#iferror:{{#expr:Lua error: bad argument #1 to 'gsub' (string is not UTF-8).}} |108 kg |[convert: invalid number]108 kg }} |50={{#iferror:{{#expr:Lua error: bad argument #1 to 'gsub' (string is not UTF-8).}} |108 kg |[convert: invalid number]108 kg }} |50={{#iferror:{{#expr:Lua error: bad argument #1 to 'gsub' (string is not UTF-8).}} |108 kg |[convert: invalid number]108 kg }} |5={{#iferror:{{#expr:108 kg +108 kg }} |108 kg |[convert: invalid number]108 kg }} |108 kg
}}
{{Template:Infobox person/weight/locate|108 kg}}
→ {{#switch:0
|500=108 kg |00={{#iferror:{{#expr:Lua error: bad argument #1 to 'gsub' (string is not UTF-8).}} |108 kg |[convert: invalid number]108 kg }} |50={{#iferror:{{#expr:Lua error: bad argument #1 to 'gsub' (string is not UTF-8).}} |108 kg |[convert: invalid number]108 kg }} |50={{#iferror:{{#expr:Lua error: bad argument #1 to 'gsub' (string is not UTF-8).}} |108 kg |[convert: invalid number]108 kg }} |5={{#iferror:{{#expr:108 kg +108 kg }} |108 kg |[convert: invalid number]108 kg }} |108 kg
}}
{{Template:Infobox person/weight/locate|238 lb}}
→ {{#switch:0
|050=238 lb |50={{#iferror:{{#expr:Lua error: bad argument #1 to 'gsub' (string is not UTF-8).}} |238 lb |[convert: invalid number]238 lb }} |00={{#iferror:{{#expr:Lua error: bad argument #1 to 'gsub' (string is not UTF-8).}} |238 lb |[convert: invalid number]238 lb }} |05={{#iferror:{{#expr:Lua error: bad argument #1 to 'gsub' (string is not UTF-8).}} |238 lb |[convert: invalid number]238 lb }} |0={{#iferror:{{#expr:238 lb +238 lb }} |238 lb |[convert: invalid number]238 lb }} |238 lb
}}
{{Template:Infobox person/weight/locate|238 lb}}
→ {{#switch:0
|050=238 lb |50={{#iferror:{{#expr:Lua error: bad argument #1 to 'gsub' (string is not UTF-8).}} |238 lb |[convert: invalid number]238 lb }} |00={{#iferror:{{#expr:Lua error: bad argument #1 to 'gsub' (string is not UTF-8).}} |238 lb |[convert: invalid number]238 lb }} |05={{#iferror:{{#expr:Lua error: bad argument #1 to 'gsub' (string is not UTF-8).}} |238 lb |[convert: invalid number]238 lb }} |0={{#iferror:{{#expr:238 lb +238 lb }} |238 lb |[convert: invalid number]238 lb }} |238 lb
}}
{{Template:Infobox person/weight/locate|17 st}}
→ {{#switch:0
|004=17 st |04={{#iferror:{{#expr:Lua error: bad argument #1 to 'gsub' (string is not UTF-8).}} |17 st |[convert: invalid number]17 st }} |04={{#iferror:{{#expr:Lua error: bad argument #1 to 'gsub' (string is not UTF-8).}} |17 st |[convert: invalid number]17 st }} |00={{#iferror:{{#expr:Lua error: bad argument #1 to 'gsub' (string is not UTF-8).}} |17 st |[convert: invalid number]17 st }} |0={{#iferror:{{#expr:17 st +17 st }} |17 st |[convert: invalid number]17 st }} |17 st
}}
{{Template:Infobox person/weight/locate|17 st}}
→ {{#switch:0
|004=17 st |04={{#iferror:{{#expr:Lua error: bad argument #1 to 'gsub' (string is not UTF-8).}} |17 st |[convert: invalid number]17 st }} |04={{#iferror:{{#expr:Lua error: bad argument #1 to 'gsub' (string is not UTF-8).}} |17 st |[convert: invalid number]17 st }} |00={{#iferror:{{#expr:Lua error: bad argument #1 to 'gsub' (string is not UTF-8).}} |17 st |[convert: invalid number]17 st }} |0={{#iferror:{{#expr:17 st +17 st }} |17 st |[convert: invalid number]17 st }} |17 st
}}
{{Template:Infobox person/weight/locate|108 kg (2012)}}
→ {{#switch:0
|500=108 kg (2012) |00={{#iferror:{{#expr:Lua error: bad argument #1 to 'gsub' (string is not UTF-8).}} |108 kg (2012) |108 kg ([convert: unknown unit])108 kg (2012) }} |50={{#iferror:{{#expr:Lua error: bad argument #1 to 'gsub' (string is not UTF-8).}} |108 kg (2012) |108 kg ([convert: unknown unit])108 kg (2012) }} |50={{#iferror:{{#expr:Lua error: bad argument #1 to 'gsub' (string is not UTF-8).}} |108 kg (2012) |108 kg ([convert: unknown unit])108 kg (2012) }} |5={{#iferror:{{#expr:108 kg (2012) +108 kg (2012) }} |108 kg (2012) |108 kg ([convert: unknown unit])108 kg (2012) }} |108 kg (2012)
}}
{{Template:Infobox person/weight/locate|108 kg (2012)<ref>citation goes here</ref>}}
→ {{#switch:0
|500=108 kg (2012)<ref>citation goes here</ref> |00={{#iferror:{{#expr:Lua error: bad argument #1 to 'gsub' (string is not UTF-8).}} |108 kg (2012)<ref>citation goes here</ref> |108 kg ([convert: unknown unit])108 kg (2012)<ref>citation goes here</ref> }} |50={{#iferror:{{#expr:Lua error: bad argument #1 to 'gsub' (string is not UTF-8).}} |108 kg (2012)<ref>citation goes here</ref> |108 kg ([convert: unknown unit])108 kg (2012)<ref>citation goes here</ref> }} |50={{#iferror:{{#expr:Lua error: bad argument #1 to 'gsub' (string is not UTF-8).}} |108 kg (2012)<ref>citation goes here</ref> |108 kg ([convert: unknown unit])108 kg (2012)<ref>citation goes here</ref> }} |5={{#iferror:{{#expr:108 kg (2012)<ref>citation goes here</ref> +108 kg (2012)<ref>citation goes here</ref> }} |108 kg (2012)<ref>citation goes here</ref> |108 kg ([convert: unknown unit])108 kg (2012)<ref>citation goes here</ref> }} |108 kg (2012)<ref>citation goes here</ref>
}}
<references />
Exceptions[edit]
Does not replace numbers in hard-coded conversions (examples intentionally show incorrect conversions):
{{Template:Infobox person/weight/locate|108 kg (229 lb)}}
→ {{#switch:0
|5130=108 kg (229 lb) |130={{#iferror:{{#expr:Lua error: bad argument #1 to 'gsub' (string is not UTF-8).}} |108 kg (229 lb) |108 kg ([convert: unknown unit])108 kg (229 lb) }} |50={{#iferror:{{#expr:Lua error: bad argument #1 to 'gsub' (string is not UTF-8).}} |108 kg (229 lb) |108 kg ([convert: unknown unit])108 kg (229 lb) }} |513={{#iferror:{{#expr:Lua error: bad argument #1 to 'gsub' (string is not UTF-8).}} |108 kg (229 lb) |108 kg ([convert: unknown unit])108 kg (229 lb) }} |5={{#iferror:{{#expr:108 kg (229 lb) +108 kg (229 lb) }} |108 kg (229 lb) |108 kg ([convert: unknown unit])108 kg (229 lb) }} |108 kg (229 lb)
}}
{{Template:Infobox person/weight/locate|238 lb (119 kg)}}
→ {{#switch:0
|1350=238 lb (119 kg) |50={{#iferror:{{#expr:Lua error: bad argument #1 to 'gsub' (string is not UTF-8).}} |238 lb (119 kg) |238 lb ([convert: unknown unit])238 lb (119 kg) }} |130={{#iferror:{{#expr:Lua error: bad argument #1 to 'gsub' (string is not UTF-8).}} |238 lb (119 kg) |238 lb ([convert: unknown unit])238 lb (119 kg) }} |135={{#iferror:{{#expr:Lua error: bad argument #1 to 'gsub' (string is not UTF-8).}} |238 lb (119 kg) |238 lb ([convert: unknown unit])238 lb (119 kg) }} |13={{#iferror:{{#expr:238 lb (119 kg) +238 lb (119 kg) }} |238 lb (119 kg) |238 lb ([convert: unknown unit])238 lb (119 kg) }} |238 lb (119 kg)
}}
{{Template:Infobox person/weight/locate|17 st (229 lb; 119 kg)}}
→ {{#switch:0
|20124=17 st (229 lb; 119 kg) |124={{#iferror:{{#expr:Lua error: bad argument #1 to 'gsub' (string is not UTF-8).}} |17 st (229 lb; 119 kg) |17 st ([convert: unknown unit])17 st (229 lb; 119 kg) }} |204={{#iferror:{{#expr:Lua error: bad argument #1 to 'gsub' (string is not UTF-8).}} |17 st (229 lb; 119 kg) |[convert: invalid number]17 st (229 lb; 119 kg) }} |2012={{#iferror:{{#expr:Lua error: bad argument #1 to 'gsub' (string is not UTF-8).}} |17 st (229 lb; 119 kg) |17 st ([convert: unknown unit])17 st (229 lb; 119 kg) }} |20={{#iferror:{{#expr:17 st (229 lb; 119 kg) +17 st (229 lb; 119 kg) }} |17 st (229 lb; 119 kg) |17 st ([convert: unknown unit])17 st (229 lb; 119 kg) }} |17 st (229 lb; 119 kg)
}}
Does not replace numeric output of conversion templates such as {{convert}} (examples have precision different than usual):
{{Template:Infobox person/weight/locate|{{convert|108|kg|lb|1|abbr=on}}}}
→ {{#switch:0
|5150=108 kg (238.1 lb) |150={{#iferror:{{#expr:Lua error: bad argument #1 to 'gsub' (string is not UTF-8).}} |108 kg (238.1 lb) |108 kg ([convert: unknown unit])108 kg (238.1 lb) }} |50={{#iferror:{{#expr:Lua error: bad argument #1 to 'gsub' (string is not UTF-8).}} |108 kg (238.1 lb) |108 kg ([convert: unknown unit])108 kg (238.1 lb) }} |515={{#iferror:{{#expr:Lua error: bad argument #1 to 'gsub' (string is not UTF-8).}} |108 kg (238.1 lb) |108 kg ([convert: unknown unit])108 kg (238.1 lb) }} |5={{#iferror:{{#expr:108 kg (238.1 lb) +108 kg (238.1 lb) }} |108 kg (238.1 lb) |108 kg ([convert: unknown unit])108 kg (238.1 lb) }} |108 kg (238.1 lb)
}}
{{Template:Infobox person/weight/locate|{{convert|238|lb|kg|2|abbr=on}}}}
→ {{#switch:0
|1650=238 lb (107.95 kg) |50={{#iferror:{{#expr:Lua error: bad argument #1 to 'gsub' (string is not UTF-8).}} |238 lb (107.95 kg) |238 lb ([convert: unknown unit])238 lb (107.95 kg) }} |160={{#iferror:{{#expr:Lua error: bad argument #1 to 'gsub' (string is not UTF-8).}} |238 lb (107.95 kg) |238 lb ([convert: unknown unit])238 lb (107.95 kg) }} |165={{#iferror:{{#expr:Lua error: bad argument #1 to 'gsub' (string is not UTF-8).}} |238 lb (107.95 kg) |238 lb ([convert: unknown unit])238 lb (107.95 kg) }} |16={{#iferror:{{#expr:238 lb (107.95 kg) +238 lb (107.95 kg) }} |238 lb (107.95 kg) |238 lb ([convert: unknown unit])238 lb (107.95 kg) }} |238 lb (107.95 kg)
}}
{{Template:Infobox person/weight/locate|{{convert|17|st|3|abbr=on}}}}
→ {{#switch:0
|28164=17 st (238.000 lb; 107.955 kg) |164={{#iferror:{{#expr:Lua error: bad argument #1 to 'gsub' (string is not UTF-8).}} |17 st (238.000 lb; 107.955 kg) |17 st ([convert: unknown unit])17 st (238.000 lb; 107.955 kg) }} |284={{#iferror:{{#expr:Lua error: bad argument #1 to 'gsub' (string is not UTF-8).}} |17 st (238.000 lb; 107.955 kg) |[convert: invalid number]17 st (238.000 lb; 107.955 kg) }} |2816={{#iferror:{{#expr:Lua error: bad argument #1 to 'gsub' (string is not UTF-8).}} |17 st (238.000 lb; 107.955 kg) |17 st ([convert: unknown unit])17 st (238.000 lb; 107.955 kg) }} |28={{#iferror:{{#expr:17 st (238.000 lb; 107.955 kg) +17 st (238.000 lb; 107.955 kg) }} |17 st (238.000 lb; 107.955 kg) |17 st ([convert: unknown unit])17 st (238.000 lb; 107.955 kg) }} |17 st (238.000 lb; 107.955 kg)
}}
Technical details[edit]
The following examples show how the template works:
kg[edit]
{{Infobox person/weight/switch |108 kg |{{#invoke:String|replace|108 kg| | }} |k={{#invoke:String|find|{{#invoke:String|replace|108 kg| | }}|kg}} |s={{#invoke:String|find|{{#invoke:String|replace|108 kg| | }}|st}} |l={{#invoke:String|find|{{#invoke:String|replace|108 kg| | }}|lb}} }}
Result:
{{Infobox person/weight/switch
|108 kg
|108 kg
|k=5
|s=0
|l=0
}}
lb[edit]
{{Infobox person/weight/switch |238 lb |{{#invoke:String|replace|238 lb| | }} |k={{#invoke:String|find|{{#invoke:String|replace|238 lb| | }}|kg}} |s={{#invoke:String|find|{{#invoke:String|replace|238 lb| | }}|st}} |l={{#invoke:String|find|{{#invoke:String|replace|238 lb| | }}|lb}} }}
Result:
{{Infobox person/weight/switch
|238 lb
|238 lb
|k=0
|s=0
|l=5
}}
st[edit]
{{Infobox person/weight/switch |17 st |{{#invoke:String|replace|17 st| | }} |k={{#invoke:String|find|{{#invoke:String|replace|17 st| | }}|kg}} |s={{#invoke:String|find|{{#invoke:String|replace|17 st| | }}|st}} |l={{#invoke:String|find|{{#invoke:String|replace|17 st| | }}|lb}} }}
Result:
{{Infobox person/weight/switch
|17 st
|17 st
|k=0
|s=4
|l=0
}}
st/lb[edit]
{{Infobox person/weight/switch |17 st 7 lb |{{#invoke:String|replace|17 st 7 lb| | }} |k={{#invoke:String|find|{{#invoke:String|replace|17 st 7 lb| | }}|kg}} |s={{#invoke:String|find|{{#invoke:String|replace|17 st 7 lb| | }}|st}} |l={{#invoke:String|find|{{#invoke:String|replace|17 st 7 lb| | }}|lb}} }}
Result:
{{Infobox person/weight/switch
|17 st 7 lb
|17 st 7 lb
|k=0
|s=4
|l=9
}}
See also[edit]
{{#ifeq:locate|sandbox | |
}}
The above documentation is transcluded from Template:Infobox person/weight/locate/doc. (edit | history) Editors can experiment in this template's sandbox (create | mirror) and testcases (create) pages. Please add categories to the /doc subpage. Subpages of this template. |
{{#if:|
[[Category:Template documentation pages{{#translation:}}]] }}