Template talk:Convert

From Wikimedia Commons, the free media repository
Jump to: navigation, search

Trying to get this work[edit]

As requested on the village pump, think someone could try and get this going properly over here? Vipersnake151 20:02, 5 February 2008 (UTC)

I think it would require: 18:09, 7 May 2008 (UTC)
P.S.: someone created {{Size}} which works beautifully for 2D conversions (width × height) such as paintings. 15:01, 4 August 2008 (UTC)
  • I have copied over a small subset of the templates to Commons so many of the frequent uses now work (e.g. metres to feet, °C to °F). It's possible though that certain parameter values may still cause problems. If more conversions are required, someone will need to copy the necessary templates from the English Wiki. RedWolf (talk) 22:22, 4 April 2009 (UTC)

Decimal separator[edit]

It would be good to have a parameter to allow for "," (coma) instead of "." (period dot) for the decimal separator. It is, after all, the SI standard. -- Tuválkin 15:36, 22 January 2013 (UTC)


Ghouston has copied en:Module:Convert to Module:Convert (with its submodules), and has copied Template:Convert/sandboxlua that can be used to replace Template:Convert. That is very likely to work well, but I was persuaded to add some tricky stuff to the module with regard to how it reports errors, so I have created Help:Convert messages because it is used as the target in a link when convert errors occur. There are two error tracking categories which should be created. Here are links to the enwiki versions so anyone interested can see how they are intended: en:Category:Convert invalid units and en:Category:Convert invalid options. The categories will still work despite the pages not existing, so they are not needed at the moment.

I haven't had a chance to capture the converts used here yet, but here are the examples from the template doc page using the module:

  • {{convert/sandboxlua|5959|m|ft|0}} → 5,959 metres (19,551 ft)
  • {{convert/sandboxlua|3.21|kg|lb}} → 3.21 kilograms (7.1 lb)
  • {{convert/sandboxlua|3.21|kg|lb|0}} → 3.21 kilograms (7 lb)
  • {{convert/sandboxlua|0|kg|lb}} → 0 kilograms (0 lb)
  • {{convert/sandboxlua|6|ft|5|in|m}} → 6 feet 5 inches (1.96 m)
  • {{convert/sandboxlua|18|°C|°F|sigfig=2}} → 18 °C (64 °F)
  • {{convert/sandboxlua|1250|sqft|sqm|lk=on}} → 1,250 square feet (116 m2)
  • {{convert/sandboxlua|20.5|sqkm|sqmi|1|lk=on|abbr=on}} → 20.5 km2 (7.9 sq mi)
  • {{convert/sandboxlua|641|acre|sqmi sqkm|3|lk=on|abbr=on}} → 641 acres (1.002 sq mi; 2.594 km2)
  • {{convert/sandboxlua|641|acre|sqmi sqkm|2|lk=on|abbr=on}} → 641 acres (1.00 sq mi; 2.59 km2)

I might get a chance to check this page for any comments, but if someone wants me later, please ping me at enwiki. Johnuniq (talk) 11:54, 20 November 2013 (UTC)

  • Thanks. It looks like it's already working better than the current template, probably because it never had a complete set of subtemplates from Wikipedia. The Lua version is obviously a big improvement, trying to debug the templates reminded me of struggling with TeX macros many years ago, it rapidly becomes a nightmare. ghouston (talk) 12:10, 20 November 2013 (UTC)
Though job, my sympathies. Some remarks:
  • Abbreviations should be on by default for metric units — something like "1234 kilograms" looks really odd, "1234 kg" is expected: Abbreviated unit name (its symbol, in SI parlance) is to be used always when the number is expressed in digits.
  • The metric separator between value and symbol should be a   (or equivalent).
  • Decimal separator should be comma by default for metric units, as per the SI rules; non-breaking figure space instead of period for the thousands separator is a good idea, to be used by default only when there’s more 4 digits after the decimal separator.
-- Tuválkin 12:49, 20 November 2013 (UTC)
  • It looks like it's designed to be compatible with the old templates, regardless of how odd they were. The period for decimal separator may be the right default in English, since it's rare to see the comma, regardless of SI rules. However it's interesting that Commons is a multi-lingual project, and potentially Convert should be available for text in other languages (although I suspect that in some languages the SI units would be sufficient, and nobody would care about miles and gallons.) It seems that this version of Convert supports a separate language plugin, but it looks like you'd need to copy the entire system with a new name (e.g. Convert-de) to make it multilingual on a single wiki. ghouston (talk) 21:18, 20 November 2013 (UTC)
OK I activated the Lua version on Template:Convert. Is there a documentation page that could go with it? ghouston (talk) 12:22, 20 November 2013 (UTC)
Good. You might like to inspect the two edits I made to the template. The first was to stop it outputting a newline. Then, after noticing that the error categories are empty, I added "|nscat=0,4,6,10,14" which makes the module output a category if an error occurs on a page in one of the listed namespaces. Those numbers are namespaces content, project, file, template, category respectively. The default is just content + template as that is what is wanted at enwiki, but most converts are in other namespaces here.
Re doc page: I haven't fixed that yet, but see en:Help:Convert and have a look at Help:Convert messages. The two error categories are Category:Convert invalid units and Category:Convert invalid options.
I'll have to contemplate Tuválkin's comments later, but putting "{{convert|3.21|kg|lb|abbr=on}}" into Special:ExpandTemplates shows that it is outputting   between number and symbol. The module can be configured to use comma decimal mark and gap separators. I'll add a template to demo that later. Johnuniq (talk) 19:54, 20 November 2013 (UTC)
  • Whoops, sorry about the new line. I checked that it was working, then modified it to fix the documentation and went to bed. Classic way to mess things up. ghouston (talk) 21:01, 20 November 2013 (UTC)

Number format[edit]

As promised above, I have created Template:Convert2 as a demonstration of how the template can be configured (using Module:Convert) to use "," for the decimal mark and "." for the group separator. I was wrong about being able to configure gaps—I have only made that an option for a particular convert. Number formatting was a very secondary concern while writing the module, so I have not got it working as people may want. It can do some clever things—at bn:User:Johnuniq/Translation (for the Bengali wiki), it is grouping numbers with three digits for the first group, then two digits for subsequent groups, but it can't yet do all things that may be wanted.

Here is a demo:

  • {{convert2|123.456.789,12345|ft|m|abbr=on}} → 123.456.789,12345 ft (37.629.629,32483 m)
  • {{convert2|123456789,12345|ft|m|abbr=on}} → 123.456.789,12345 ft (37.629.629,32483 m)
  • {{convert2|1234,12345|ft|m|abbr=on|comma=gaps5}}1234,12345 ft (376,16083 m)*
  • {{convert2|123456789,12345|ft|m|abbr=on|comma=gaps5}}123456789,12345 ft (37629629,32483 m)*

The input number on the first line uses "." as a separator, and that is ignored by convert. The "," is the decimal mark. The second line shows that the output is formatted regardless of the input. The third line has the "gaps5" option I was thinking of—it inserts gaps, but only if there are 5 or more digits before the decimal mark. It uses complex html so you can copy the number in the browser, and it copies without gaps. Also, the gaps are non-breaking. There is no facility to group digits after the decimal mark (only the integer part can be grouped; the fractional part is not grouped). I'm mentioning this for general interest, but it's of no value in the short term because the modules would need a fair bit of planning and work to implement a scheme whereby some converts would output 12,345.6 while others show 12345,6. Johnuniq (talk) 07:37, 21 November 2013 (UTC)