Module:Convert/extra/doc: Difference between revisions

Content deleted Content added
samples showing how to define new units
 
 
(14 intermediate revisions by 4 users not shown)
Line 1:
{{high-use|212}}
This module can be used to quickly add a new unit for use with {{tl|convert}}. When satisfied that a unit is working correctly, ask at [[Module talk:Convert]] for the unit to be moved to the permanent list of units.
 
See [[Template:Convert/unit sandbox]] for a good way to prepare unit definitions that can be copied into this page.
 
The following extracts from [[Module:Convert/data]] show examples that could be used to define a new unit. Any number of spaces can be used where blanks are shown in the following.
 
<syntaxhighlight lang="lua">
{{collapse top|title=Examples for additions to <code>Module:Convert/extra</code> {{nobold|1=(For the actual module code see [[#EndOfDoc|below]])}}|bg=#CEF2E0|b-color=#A3BFB1|bg2=#F5FFFA}}
 
<syntaxhighlight lang="lua" highlight="1">
-- These are EXAMPLES on the documentation page. Scroll down to see the module content.
local extra_units = {
-- Similar to a redirect: "sqm" is an alias for "m2".
-- {{convert|1.5|m2|sp=us}} → 1.5 square meters (16 sq ft)
-- {{convert|1.5|sqm|sp=us}} → 1.5 square meters (16 sq ft)
["sqm"] = {
Line 50 ⟶ 58:
utype = "density",
default = "lb/cuin",
},
-- If the automatic "per" link is not wanted, a link can be specified.
-- {{convert|125|g/cm3|lk=on|disp=unit}} → [[gram]]s per [[cubic centimetre]]
-- {{convert|125|g/m3|lk=on|disp=unit}} → [[density|grams per cubic metre]]
["g/m3"] = {
per = { "g", "m3" },
utype = "density",
default = "lb/cuyd",
link = "density",
},
-- Characters "$" and "£" are recognized as currency symbols.
Line 77 ⟶ 94:
}
</syntaxhighlight>
 
{{collapse bottom}}
 
{| class="wikitable"
Line 89 ⟶ 108:
| <code>name1_us</code> || Singular name when <code>sp=us</code> is in effect; not required if the same as <code>name1</code>.
|-
| <code>name2_us</code> || Plural name when <code>sp=us</code> is in effect; not required if the same as <code>name2name1_us</code> plus "s".
|-
| <code>utype</code> || Unit type; must be exactly the same as the <code>utype</code> of any other unit used in a conversion.
Line 103 ⟶ 122:
| <code>link</code> || Article title used when <code>lk=on</code> is in effect; not required if it is the same as <code>name1</code>.
|}
 
{{anchor|EndOfDoc}}
<noinclude>
[[Category:Module documentation pages]]
</noinclude>