Content deleted Content added
→Module version history: add version 18 which will be at Template talk:Convert/Archive July 2017#Module version 18 when archived |
document call from lua |
||
(31 intermediate revisions by 15 users not shown) | |||
Line 1:
{{Transwiki guide|
{{High-risk
{{Module rating|p}}
{{cascade-protected template|page=module}}
{{Lua|Module:Convert/data|Module:Convert/text|Module:Convert/wikidata|Module:Convert/wikidata/data|Module:Convert/extra|Module:ConvertNumeric|noprotcat=yes}}
{{Uses TemplateStyles|Template:Fraction/styles.css|Template:Sfrac/styles.css|noprotcat=yes}}
This module converts a value from one unit of measurement to another. For example:
* <code><nowiki>{{convert|123|lb|kg}}</nowiki></code> → 123 pounds (56 kg)
Line 7 ⟶ 10:
The module is called using a template—parameters passed to the template are used by this module to control how a conversion is performed. For example, units can be abbreviated (like <code>kg</code>), or displayed as names (like <code>kilogram</code>), and the output value can be rounded to a specified precision. For usage information, see [[Help:Convert]].
The _convert() and _unit() functions can also be called from other Lua modules.
The template that invokes this module is:▼
* [[Template:Convert]]▼
== Templates and modules ==
* {{t|convert}}
* {{t|cvt}} {{green|1=(convert with abbr=on)}}
The following modules are required:
Line 18 ⟶ 25:
* [[Module:Convert/extra]] – extra (temporary) unit definitions; used if a unit is not found in [[Module:Convert/data]]
* [[Module:ConvertNumeric]] – code to spell an input value in words (only English is supported; however, see [[:vi:Module:ConvertNumeric]])
For Wikidata support the following modules are required:
The following help pages are available:
Line 28 ⟶ 39:
Units are defined in the wikitext of the master list of units.
* [[Module:Convert/documentation/conversion data
* [[Module:Convert/makeunits]] – translates wikitext from the master list to Lua
* [[Module talk:Convert/makeunits]] – makeunits results; copy the text to [[Module:Convert/data]]
[[Module:Convert/data]] is transcluded into every page using the convert module, so experimenting with a new unit in that module would involve a significant overhead. The [[Module:Convert/extra]] module is an alternative which is only transcluded on pages with a unit that is not defined in the main data module.
[[Module talk:Convert/show]] lists all unit links so they can be checked.
== Sandbox ==
When making a change, copy the current modules to the sandbox pages, then edit the sandbox copies:
{{#invoke:convert/tester|compare}}▼
▲* [[Module:Convert/sandbox]]
Use the following template to test the results (example <code><nowiki>{{convert/sandbox|123|lb|kg}}</nowiki></code>):
Line 53 ⟶ 63:
== Configuration ==
The template that invokes this module can define options to configure the module. For example, to set the [[decimal mark]] to be a comma and the thousands separator to be a dot, use one of the following:
* <
* <source lang='lua' inline>p._convert({numdot=',', numsep='.'}, args)</source>
Other options, with default values, are:
Line 69 ⟶ 79:
== To do ==
Document the modules to access Wikidata!
▲{{#invoke:convert/tester|compare}}
== Module version history ==
Line 85 ⟶ 94:
* [[Template talk:Convert/Archive August 2015#Module version 12|Version 12]] August 2015
* [[Template talk:Convert/Archive March 2016#Module version 13|Version 13]] March 2016
* [[Template talk:Convert/Archive June 2016#Module version 14|Version 14]] June 2016 {{green|(introduced handling of Wikidata)}}
* [[Template talk:Convert/Archive September 2016#Module version 15|Version 15]] September 2016
* [[Template talk:Convert/Archive January 2017#Module version 16|Version 16]] January 2017
* [[Template talk:Convert/Archive May 2017#Module version 17|Version 17]] May 2017
* [[Template talk:Convert/Archive July 2017#Module version 18|Version 18]] July 2017
* [[Template talk:Convert/Archive August 2017#Module version 19|Version 19]] August 2017
* [[Template talk:Convert/Archive December 2017#Module version 20|Version 20]] December 2017 {{green|(changed symbols for dot and micro)}}
* [[Template talk:Convert/Archive January 2018#Module version 21|Version 21]] January 2018 {{green|(remove many deprecated options)}}
* [[Template talk:Convert/Archive February 2018#Module version 22|Version 22]] February 2018 {{green|(many unit link changes)}}
* [[Template talk:Convert/Archive June 2018#Module version 23|Version 23]] June 2018 {{green|1=(warnings for ignored numbered parameters; adj=pre/disp=preunit changes; currency units removed)}}
* [[Template talk:Convert/Archive May 2019#Module version 24|Version 24]] May 2019 {{green|1=(hidden sort key uses data-sort-value; avoid using the extra data module)}}
* [[Template talk:Convert/Archive 2#Module version 25|Version 25]] May 2021 {{green|1=(use templatestyles [[Template:Fraction/styles.css]] or [[Template:Sfrac/styles.css]] for fractions)}}
* [[Template talk:Convert/Archive 2#Module version 26|Version 26]] June 2021 {{green|1=(many unit link changes)}}
* [[Template talk:Convert/Archive 2#Module version 27|Version 27]] February 2022 {{green|1=(enhance Mach parameters; use spaced en dash when needed; unit tweaks)}}
* [[Template talk:Convert/Archive 3#Module version 28|Version 28]] April 2023 {{green|1=(new SI prefixes; add disp=semicolon; unit adjustments including fixing scales of mpge and BTU/lb)}}
* [[Template talk:Convert/Archive 3#Module version 29|Version 29]] May 2023 {{green|1=(liter/litre fix to show symbol 'L' rather than 'l' per MOS)}}
* [[Template talk:Convert/Archive 3#Module version 30|Version 30]] October 2024 {{green|1=(units can use convertPlural in languages with more than one plural form and can have a pername; E3km displays "thousand" even with abbr=on)}}
<includeonly>{{#ifeq:{{SUBPAGENAME}}|sandbox||
[[Category:Modules that add a tracking category]]
}}</includeonly>
<noinclude>
[[Category:Module documentation pages]]
</noinclude>
|