Template:Unit/doc: Difference between revisions

From Eco - English Wiki
[unchecked revision][checked revision]
m (Remove references to sandboxes.)
m (Add note about updating.)
 
(2 intermediate revisions by the same user not shown)
Line 3: Line 3:
{
{
"params": {
"params": {
"number": {
"label": "Number",
"type": "number",
"description": "Numerical value to format for display with the unit.",
"example": "2, -2, 3.45"
},
"abbr": {
"abbr": {
"label": "Unit abbreviation",
"label": "Unit abbreviation",
"description": "Case sensitive abbreviation of a unit of measure. If the abbreviation contains a forward slash \"/\" it may be replaced with the character \"p\".",
"description": "Case sensitive abbreviation of a unit of measure. If the abbreviation contains a forward slash \"/\" it may be replaced with the character \"p\".",
"example": "m/s, mps, GHz, ppm, kg, m2, kWh",
"example": "m/s, mps, GHz, ppm, kg, m2, kWh",
"type": "string",
"type": "string"
"required": true
}
}
},
},
Line 14: Line 19:
"format": "inline",
"format": "inline",
"paramOrder": [
"paramOrder": [
"number",
"abbr"
"abbr"
]
]
Line 20: Line 26:


== Usage ==
== Usage ==
{{tlx|Unit|''abbr''}}
* With a formatted number: {{tlx|Unit|''number''|''abbr''}}
** If a number is specified, it is formatted with a space " " as a thousands separator and a period "." as the decimal separator.
* With unit abbreviation only: {{tlx|Unit|''abbr''}}


== New units ==
== New units ==
Line 33: Line 41:
| {{tlx|Unit|ppm}} || {{Unit|ppm}}
| {{tlx|Unit|ppm}} || {{Unit|ppm}}
|-
|-
| {{tlx|Unit|m}} || {{Unit|m}}
| {{tlx|Unit|1200|m}} || {{Unit|1200|m}}
|-
|-
| {{tlx|Unit|m/s}} || {{Unit|m/s}}
| {{tlx|Unit|1|m/s}} || {{Unit|1|m/s}}
|-
|-
| {{tlx|Unit|mps}} || {{Unit|mps}}
| {{tlx|Unit|mps}} || {{Unit|mps}}
|-
|-
| {{tlx|Unit|kg}} || {{Unit|kg}}
| 34 {{tlx|Unit|kg}} || 34 {{Unit|kg}}
|-
|-
| {{tlx|Unit|degc}} || {{Unit|degc}}
| {{tlx|Unit|+2|degc}} || {{Unit|+2|degc}}
|}
|}


Line 50: Line 58:
! Code !! Result
! Code !! Result
|-
|-
| {{tlx|Unit|mHz}} || {{Unit|mHz}}
| {{tlx|Unit|-2,1|mHz}} || {{Unit|-2,1|mHz}}
|-
|-
| {{tlx|Unit|MHz}} || {{Unit|MHz}}
| {{tlx|Unit|-0.1||MHz}} || {{Unit|-0.1|MHz}}
|-
|-
| {{tlx|Unit|m2}} || {{Unit|m2}}
| {{tlx|Unit|0|m2}} || {{Unit|0|m2}}
|-
|-
| {{tlx|Unit|kohm}} || {{Unit|kohm}}
| {{tlx|Unit|+1|kohm}} || {{Unit|+1|kohm}}
|-
|-
| {{tlx|Unit|kWh}} || {{Unit|kWh}}
| {{tlx|Unit|852001,99|kWh}} || {{Unit|852001,99|kWh}}
|-
|-
| {{tlx|Unit|um}} || {{Unit|um}}
| 4–8 {{tlx|Unit|um}} || 4–8 {{Unit|um}}
|-
|-
| {{tlx|Unit|J/(Kmol)}} || {{Unit|J/(Kmol)}}
| {{tlx|Unit|J/(Kmol)}} || {{Unit|J/(Kmol)}}
|}
|}


If a unit definition is not found, the abbreviation (or text) is returned unchanged.
If a unit definition is not found, the abbreviation (or text) is returned unchanged. However, if the unit definition data is later ''updated'' to include the unit, it will begin using the tooltip correctly later.
{| class="wikitable"
{| class="wikitable"
|+ Invalid units.
|+ Invalid units.
Line 71: Line 79:
! Code !! Result
! Code !! Result
|-
|-
| {{tlx|Unit|things}} || {{Unit|things}}
| {{tlx|Unit|99|things}} || {{Unit|99|things}}
|-
|-
| {{tlx|Unit|something/other}} || {{Unit|something/other}}
| {{tlx|Unit|something/other}} || {{Unit|something/other}}
|-
|-
| {{tlx|Unit|players per hour}} || {{Unit|players per hour}}
| {{tlx|Unit|-2|players per hour}} || {{Unit|-2|players per hour}}
|-
| {{tlx|Unit|7|lbft}} of torque || {{Unit|7|lbft}} of torque
|-
| {{tlx|Unit}} || {{Unit}}
|}
|}


Line 82: Line 94:
*[[Module:Unit]]
*[[Module:Unit]]
{{doc/end}}
{{doc/end}}
<includeonly>[[Category:Formatting templates]]</includeonly>

Latest revision as of 15:26, 27 February 2022

Template:Doc/start

Add a tooltip to an abbreviation of a unit of measure showing the actual name of the unit.

Template parameters

This template prefers inline formatting of parameters.

ParameterDescriptionTypeStatus
Numbernumber

Numerical value to format for display with the unit.

Example
2, -2, 3.45
Numberoptional
Unit abbreviationabbr

Case sensitive abbreviation of a unit of measure. If the abbreviation contains a forward slash "/" it may be replaced with the character "p".

Example
m/s, mps, GHz, ppm, kg, m2, kWh
Stringoptional

Usage[edit source]

  • With a formatted number: {{Unit|number|abbr}}
    • If a number is specified, it is formatted with a space " " as a thousands separator and a period "." as the decimal separator.
  • With unit abbreviation only: {{Unit|abbr}}

New units[edit source]

Recognized units are defined and documented in Module:Unit/data.

Examples[edit source]

Commonly used units.
Code Result
{{Unit|ppm}} Script error: No such module "Unit".
{{Unit|1200|m}} Script error: No such module "Unit".
{{Unit|1|m/s}} Script error: No such module "Unit".
{{Unit|mps}} Script error: No such module "Unit".
34 {{Unit|kg}} 34 Script error: No such module "Unit".
{{Unit|+2|degc}} Script error: No such module "Unit".

Note that the abbreviation is case sensitive and if the unit contains special symbols they are displayed correctly:

Various units.
Code Result
{{Unit|-2,1|mHz}} Script error: No such module "Unit".
{{Unit|-0.1|MHz}} Script error: No such module "Unit".
{{Unit|0|m2}} Script error: No such module "Unit".
{{Unit|+1|kohm}} Script error: No such module "Unit".
{{Unit|852001,99|kWh}} Script error: No such module "Unit".
4–8 {{Unit|um}} 4–8 Script error: No such module "Unit".
{{Unit|J/(Kmol)}} Script error: No such module "Unit".

If a unit definition is not found, the abbreviation (or text) is returned unchanged. However, if the unit definition data is later updated to include the unit, it will begin using the tooltip correctly later.

Invalid units.
Code Result
{{Unit|99|things}} Script error: No such module "Unit".
{{Unit|something/other}} Script error: No such module "Unit".
{{Unit|-2|players per hour}} Script error: No such module "Unit".
{{Unit|7|lbft}} of torque Script error: No such module "Unit". of torque
{{Unit}} ERROR: No value given to Unit template!

Modules[edit source]

This template is using the following Modules:

Template:Doc/end