Jump to content

Template talk:Convert

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia

... in conception
... and in reality

Plans for new version

[edit]

I am slowly planning a new version of the module. This is mainly a result of a discussion at the Ukrainian Wikipedia regarding a bug in the way variable names are handled. Languages such as Ukrainian have more than one plural form for a unit name. Some examples are at uk:User:Johnuniq/convert with discussion at its talk.

I also want to clean up some minor issues:

  • Units mile and miles will set abbr=off for that unit. That means {{convert|4|km|miles}} would display "4 kilometres (2.5 miles)" rather than the current "4 kilometres (2.5 mi)". This was mentioned in June 2021.
  • Think about whether any other aliases should similarly set abbr=off. I would probably leave that for another time as it is only mile/miles that I have noticed being a problem with a result of "mi" when the editor went to the trouble of typing "miles".
  • Want a fix for {{convert|10|e6kg|e6lb|abbr=unit}} so result can be "10 million kg (22 million pounds)" rather than the current "10 million kg (22 million lb)".
  • Perhaps add an alias for abbr=~ (maybe adj=~?) to avoid the problem mentioned above. That would allow {{convert|1|C|K|abbr=off|adj=~}} to display "1 degree Celsius [°C] (274 kelvins)".

The abbr=unit issue has been raised several times. The problem is that abbr=off results in "million kilograms" while abbr=on gives the unappealing "10×10^6 kg". Using abbr=unit means the units will be abbreviated (kg and lb) while million will not.

I haven't been able to think of a clean way to specify that million should be spelled but I am currently wondering whether this trick would be ok:

  • e6lb would work as it does now (million or engineering notation depending on abbr).
  • E6lb would give million (never engineering notation).

Thoughts? Any clean alternative syntax? Johnuniq (talk) 23:34, 21 October 2024 (UTC)[reply]

Here's a couple ideas on expanding abbr options:
  1. Concatenate the options with a delimiter: {{convert|10|e6kg|e6lb|abbr=innum;inunit;outnum;outunit}} would be equivalent to abbr=on. Using a subset of the options would allow fine-tuning the output.
  2. Add parameters abbrin, abbrout, which allow on, off, unit, num.
Indefatigable (talk) 21:21, 25 October 2024 (UTC)[reply]
Thanks, they are good ideas. However, I think I'll go with the simple although obscure E6lb. That is a small extra thing for editors to recall as compared with four new keywords. No matter how convert handles it, people will have difficulty knowing what to do and will have to ask or study the long documentation. An implementation difficulty is that I want to continue supporting other languages and the current translation system would need very large changes to accommodate delimited options. Johnuniq (talk) 01:24, 26 October 2024 (UTC)[reply]

Module version 30

[edit]

Some changes to the convert modules are in the sandbox and I intend switching the main modules to use the sandbox soon.

  • Module:ConvertModule:Convert/sandboxsame content
  • Module:Convert/dataModule:Convert/data/sandboxsame content
  • Module:Convert/textModule:Convert/text/sandboxsame content
  • Module:Convert/extraModule:Convert/extra/sandboxsame content
  • Module:Convert/wikidataModule:Convert/wikidata/sandboxsame content
  • Module:Convert/wikidata/dataModule:Convert/wikidata/data/sandboxsame content
  • Option adj=~ is an alias for abbr=~ so either may be used to display the input name and symbol.
    • {{convert|1|C|K|abbr=off|adj=~}} → 1 degree Celsius [°C] (274 kelvins)
  • Option link=... is an alias for lk=... so either may be used to control whether units are linked.
    • {{convert|12.3|kn|link=in}} → 12.3 knots (22.8 km/h; 14.2 mph)
  • Units can be entered with an engineering factor using "e" or "E", for example, e3km or E3km. Using uppercase E3km displays the factor as a word ("thousand") rather than as ×103. Using lowercase e3km continues to display the word if abbr=unit is used, or if abbr=off applies to the unit.
    • {{convert|10|e3mi|e3km}} → 10 thousand miles (16×10^3 km)
    • {{convert|10|e3mi|E3km}} → 10 thousand miles (16 thousand km)
    • {{convert|10|E6kg|E6lb|abbr=in}} → 10 million kg (22 million pounds)
  • For ukwiki (and others), function variable_name has been enhanced to use mw.language.getContentLanguage():convertPlural rather than the inadequate home-grown code that was developed for slwiki in 2014. In addition a bug fix to prevent duplication of the local language's equivalent of "kilo" was implemented. See uk:User:Johnuniq/convert and its talk.
  • For ukwiki, a unit can have a pername that will be used if the unit is the second in a "per". For example, the definition for mi can include the names that it normally has, as well as a pername that would be used in a per unit such as $/mi.
  • For ukwiki, the eng_scales table in Module:Convert/text has been enhanced to allow variable names for factors such as "kilo" that depend on the value.
  • Units mile and miles set abbr=off.
    • {{convert|4|km|mi}} → 4 kilometres (2.5 mi)
    • {{convert|4|km|miles}} → 4 kilometres (2.5 miles)
  • Module:Convert/makeunits
    • The definition for an alias accepts abbr=off to force use of the unit name, not symbol.
    • Unit definitions can include a pername.

The above examples use fixed wikitext so the outputs won't change in the future.

For posterity, I will record that Module:Convert/extra has had unit bit since August 2022. It also had byte but I removed it as it was unused and had a small error, and was not supported in October 2020 or in April 2023. Unit bit has a good use in Patterned media so I intend to keep it. Normally, I would move extra units to the main data module but there would have to be another unit (byte) to be the default output for bit. Therefore, I'm just leaving bit as an extra unit for consideration another time.

There is a little more information at #Plans for new version above. Johnuniq (talk) 05:35, 23 October 2024 (UTC)[reply]

Excellent. I'm looking forward to the miles treatment.  Stepho  talk  23:52, 25 October 2024 (UTC)[reply]
This version is now live. @Slowking Man: {convert|1|C|K|abbr=off|adj=~}} now works (example above). Johnuniq (talk) 23:18, 26 October 2024 (UTC)[reply]
I suppose it's a coincidence that the power just went out in a 10-mile radius around me? EEng 00:39, 27 October 2024 (UTC)[reply]
👍 Best feature - ever!  Stepho  talk  00:51, 27 October 2024 (UTC)[reply]
Hey EEng, I'm disappointed. You mean a 10-mile (16 km) radius. Anyway, I'm glad you noticed. Johnuniq (talk) 02:42, 27 October 2024 (UTC)[reply]
A 10-mile radius centred exactly on you? Spoookyy... --Redrose64 🌹 (talk) 08:19, 27 October 2024 (UTC)[reply]

Multiple values, shorter abbreviation?

[edit]

Is it possible to display a shorter version than

{{convert|149.6x71.5x8.25|2|mm|2}}
149.6 by 71.5 by 8.25 millimetres (5.89 in × 2.81 in × 0.32 in)

Or?

{{convert|149.6x71.5x8.25|mm|2|abbr=on}}
149.6 mm × 71.5 mm × 8.25 mm (5.89 in × 2.81 in × 0.32 in)

In some infoboxes (eg, {{Infobox mobile phone}}), where space is limited, it is desired to list the dimensions of some object, and its conversion, but it seems unnecessary to list the “mm” and the “in” three times. I might be missing something, but I would like an option to display something like:

149.6 × 71.5 × 8.25 mm (5.89 × 2.82 × 0.32 in)

— HTGS (talk) 23:14, 6 November 2024 (UTC)[reply]

Use xx instead of x.
{{convert|149.6xx71.5xx8.25|mm|2}} gives 149.6 × 71.5 × 8.25 mm (5.89 × 2.81 × 0.32 in)
Beware that this technically violates MOS:UNITSYMBOLS. |by| is an option that obeys the MOS (but looks clumsier).
{{convert|149.6|by|71.5|by|8.25|mm|2}} gives 149.6 by 71.5 by 8.25 mm (5.89 by 2.81 by 0.32 in)  Stepho  talk  23:49, 6 November 2024 (UTC)[reply]
Thank you! I might actually ask at MOSNUM, because this feels like an oversight (for use in small spaces), and I’d like to standardise this across a lot of infoboxes. — HTGS (talk) 00:06, 7 November 2024 (UTC)[reply]

Troy weight

[edit]

I'm not sure if this is the right place to discuss this, but is it possible to integrate troy weight into this template? Basically another obscure, antiquated unit of mass that still sticks around out of tradition in the precious metals industry. TheTechnician27 (Talk page) 12:23, 10 November 2024 (UTC)[reply]

@TheTechnician27: It's already provided, e.g. {{convert|1|ozt|g|3}} → 1 troy ounce (31.103 g). See full list of mass units. --Redrose64 🌹 (talk) 15:48, 10 November 2024 (UTC)[reply]
@Redrose64: Oooh, thank you! I was trying to use 'oz t' with no success. TheTechnician27 (Talk page) 17:26, 10 November 2024 (UTC)[reply]

Indian numbering system: lakhs and crores

[edit]
Moved from Module talk:Convert. Johnuniq (talk) 01:45, 19 November 2024 (UTC)[reply]

I request that we enhance the module to include lakhs and crores.

The Indian numbering system is the main nomenclature used in South Asia to name large numbers. From the lead:

The terms lakh or 1,00,000 (one hundred thousand, written as 100,000 in Pakistan, and outside the Indian subcontinent) and crore or 1,00,00,000 (ten million, written as 10,000,000 outside the subcontinent) are the most commonly used terms in Indian English to express large numbers in the system.

This is a dimensionless unit, or if you wish, the units are integers. (Hence if implemented, the data item in 'all_units' at Module:Convert/data could be named ["ins"] for 'Indian numbering system'). Note also the main pattern of comma-separation into groups of two and three digits, not just three.

These terms should be converted to standard English terms, mostly with the term million, except for values up to 9 lakh, which could be 900,000. Sample usage in articles:

The plural sometimes has the -s, and sometimes doesn't; so both '2 lakhs' and '2 lahk' are seen; same for crore(s).

This arose at the Rfc at Wikipedia talk:Manual of Style/Dates and numbers, where in my !vote (diff) I called for using template {{Convert}}, only to realize after the fact that the template will not handle it. This conversion is badly needed, as it will resolve a sore point about usage of lakhs and crores in many articles. Thanks, Mathglot (talk) 23:46, 18 November 2024 (UTC)[reply]

Earlier discussions.
I have not yet examined the RfC at WT:Manual of Style/Dates and numbers#RfC Indian numbering conventions. The above discussions point out that lakh and crore are not units. They are like million which is also not a unit. However, if convert could do something useful that is not provided by {{lakh}} and {{crore}}, it could be investigated. Johnuniq (talk) 02:03, 19 November 2024 (UTC)[reply]
The {{lakh}} and {{crore}} templates make more sense than overloading {{convert}}.  Stepho  talk  23:07, 19 November 2024 (UTC)[reply]