Module talk:Convert: Difference between revisions

Content deleted Content added
Repakr (talk | contribs)
 
(276 intermediate revisions by 42 users not shown)
Line 1:
{{notice|heading=<big>Please use [[Template talk:Convert]] to discuss units or any other feature related to {{tl|convert}}.</big>|<big>This page is for discussion about the internal operation of the modules, or their use on other Wikipedias.</big>}}
==Notes==
{{archives|search=yes|searchprefix=Module talk:Convert/Archive}}
This module provides an implementation of {{tl|convert}}. See the [[Module:Convert/doc|documentation]].
{{Lua sidebar}}
 
== Error on Tewiki for a testcase ==
Usage examples:
*<code><nowiki>{{convert/sandboxlua|5.2|m|ftin}}</nowiki></code> → {{convert/sandboxlua|5.2|m|ftin}}
*<code><nowiki>{{convert/sandboxlua|5+3/8|in}}</nowiki></code> → {{convert/sandboxlua|5+3/8|in}}
*<code><nowiki>{{convert/sandboxlua|1|yd|2|ft|3|in|hand}}</nowiki></code> → {{convert/sandboxlua|1|yd|2|ft|3|in|hand}}
*<code><nowiki>{{convert/sandboxlua|60|x|120|m|ft}}</nowiki></code> → {{convert/sandboxlua|60|x|120|m|ft}}
*<code><nowiki>{{convert/sandboxlua|1|e12BTU/cuft|e9kJ/L|lk=on}}</nowiki></code> → {{convert/sandboxlua|1|e12BTU/cuft|e9kJ/L|lk=on}}
 
While most [[Te:మూస:Convert|test cases on Tewiki]] are successful, {convert|2|and|5|km|mi|sigfig=3|abbr=off}} gives → '''Lua error in మాడ్యూల్:Convert at line 1850: attempt to index local 'en_value' (a nil value).''' Need help to fix this. [[User:Arjunaraoc|Arjunaraoc]] ([[User talk:Arjunaraoc|talk]]) 04:38, 17 August 2022 (UTC)
The [[Template:Convert/testcases|testcases]] show good agreement between the templates and the module. There are some minor rounding and other differences, and the only significant disagreements appear to be problems in the templates. Substantive differences occur at:
:{{ping|Arjunaraoc}} The reason is that you have the most recent [[Module:Convert]] but an old [[Module:Convert/text]]. Several other things would also fail, for example fractions. Try this at tewiki (it won't work):
*[[Template:Convert/testcases/bytype/energy2|energy2]]: different default output for in.lbf
:*<code><nowiki>{{convert|1+2/3|ft|in}}</nowiki></code> → {{convert|1+2/3|ft|in}}
*[[Template:Convert/testcases/bytype/energypervolume|energypervolume]]: template problems
:I'll do some editing possibly in a few hours or possibly in a day or two. Wait for me to contact you again before proceeding. Feel free to remind me if 48 hours passes and it looks like I've forgotten. [[User:Johnuniq|Johnuniq]] ([[User talk:Johnuniq|talk]]) 05:32, 17 August 2022 (UTC)
*[[Template:Convert/testcases/bytype/exhaustemission|exhaustemission]]: template problem
:{{ping|Arjunaraoc}} I was able to update [[:te:Module:Convert/text]] sooner than expected. That should fix errors due to inconsistency due to differing versions. For your information, I put some notes at [[:te:User:Johnuniq/translate]] in 2015. You might like to review that and let me know if anything is wanted. For example, I was told that <code><nowiki>{{convert|1234567890|m|m}}</nowiki></code> should display 1,23,45,67,890 for the input number. If that is wanted, I have to add more options to Module:Convert/text. [[User:Johnuniq|Johnuniq]] ([[User talk:Johnuniq|talk]]) 07:52, 17 August 2022 (UTC)
*[[Template:Convert/testcases/bytype/length2|length2]]: different micro sign (should be "µ" U+00B5, not "μ" GREEK SMALL LETTER MU U+03BC)
::@[[User:Johnuniq|Johnuniq]], Thanks for your quick action. The errors have disappeared. I have reviewed the past discussion notes. Many of the usecases are covered. In Tewiki, we use International and Indian number punctuation depending on the units (Ex:million (International), lakhs (Indian, equivalent to 1/10 of million), in articles. So unless we have a way of specifying that, we may not be able to use that. [[User:Arjunaraoc|Arjunaraoc]] ([[User talk:Arjunaraoc|talk]]) 12:36, 22 August 2022 (UTC)
*[[Template:Convert/testcases/bytype/mole|mole]]: different micro sign
:::There is no option to sometimes use one numeric style and sometimes another so you might have to put up with how it is. [[User:Johnuniq|Johnuniq]] ([[User talk:Johnuniq|talk]]) 08:51, 23 August 2022 (UTC)
*[[Template:Convert/testcases/bytype/power|power]]: calorie disagreements
*[[Template:Convert/testcases/bytype/time|time]]: module cannot handle unit horse year (unit not used)
*[[Template:Convert/testcases/bytype/torque|torque]]: template problems and minor differences
*[[Template:Convert/testcases/bytype/volume|volume]]: template hectolitre problems
*[[Template:Convert/testcases/bytype/misc|misc]]: module cannot handle units note, spanner, wrench (units not used)
*[[Template:Convert/testcases/options|options]]: template problems and minor differences
*[[Template:Convert/testcases/options2|options2]]: template problems and minor differences
*[[Template:Convert/testcases/spell|spell]]: minor differences
 
== bnwiki ==
The module appears to correctly implement the main features of the template. There are some minor disagreements concerning rounding of results, and some units and options have not yet been implemented. More testing is needed. [[User:Johnuniq|Johnuniq]] ([[User talk:Johnuniq|talk]]) 10:52, 26 April 2013 (UTC) <small>Updated 09:56, 19 July 2013 (UTC)</small>
 
Hi, We didn't update bnwiki's [https://bn.wikipedia.org/w/index.php?title=%E0%A6%AE%E0%A6%A1%E0%A6%BF%E0%A6%89%E0%A6%B2:Convert&action=history Module:Convert since 2014]. Can i update it without updating [[:bn:Module:Convert/data]], [[:bn:Module:Convert/text]]? Will it break anything? [[User:আফতাবুজ্জামান|আফতাবুজ্জামান]] ([[User talk:আফতাবুজ্জামান|talk]]) 19:15, 17 December 2023 (UTC)
==Discussion==
:@[[User:আফতাবুজ্জামান|আফতাবুজ্জামান]]: Convert and Convert/text must be updated together. The above section describes a problem due to use of a new Convert with an old Convert/text. Convert/data would generally not be a problem and would not need to be updated. I have prepared a new Convert/text for bnwiki but have no idea where to save it. [[User:Johnuniq|Johnuniq]] ([[User talk:Johnuniq|talk]]) 03:56, 18 December 2023 (UTC)
Some interesting performance challenges exist. The "NewPP limit report" in the html source for this [[Template:Convert/testcases/bytype/force|test page]] says "Lua time usage: 0.295s". [[User:Johnuniq|Johnuniq]] ([[User talk:Johnuniq|talk]]) 09:35, 19 February 2013 (UTC)
::I worked out the ___location of the bnwiki module sandbox and created:
::presuming that a page that requires data conversion might require many of them, and consideing the sheer size of [[Module:Convert/data]], you might want to look at the [[mw:Extension:Scribunto/Lua_reference_manual#mw.loadData|mw.loadData documentaion]] and see if you can use this to improve performance. peace - [[User:קיפודנחש|קיפודנחש (aka kipod)]] ([[User talk:קיפודנחש|talk]]) 16:45, 2 March 2013 (UTC)
::*[[:bn:Module:খেলাঘর/Johnuniq/Convert]] • Copy from [[Module:Convert]] (I used the wrong edit summary: the comment fix is in the next module).
:::Mentioned at http://test2.wikipedia.org/wiki/User:Johnuniq -- [[User:WOSlinker|WOSlinker]] ([[User talk:WOSlinker|talk]]) 17:13, 2 March 2013 (UTC)
::*[[:bn:Module:খেলাঘর/Johnuniq/Convert/text]] • Copy from [[Module:Convert/text]] and then edited with the bnwiki translations.
::I think this will work but there are some very significant changes and it would take hours of examination to be confident about that. You might have to try it and see what happens. [[User:Johnuniq|Johnuniq]] ([[User talk:Johnuniq|talk]]) 05:31, 18 December 2023 (UTC)
:::In Convert/text, see the two TODO comments that I left for your attention. You will need to also fix the cvt_xxx messages under <code>all_messages</code>. That is because the old convert used <code>%s</code> to identify where substituted parameters need to go, while the new convert uses <code>$1</code> for the first parameter, <code>$2</code> for the second, etc. That should be better but it means every <code>%s</code> needs to be replaced. [[User:Johnuniq|Johnuniq]] ([[User talk:Johnuniq|talk]]) 05:47, 18 December 2023 (UTC)
::::@[[User:Johnuniq|Johnuniq]], <nowiki>{{convert|12|cm|disp=or}}</nowiki> is giving "12 centimetres '''('''4.7 inches''')'''" instead of "12 centimetres '''or''' 4.7 inches". Other than that, everything is working as before. Thank you. [[User:আফতাবুজ্জামান|আফতাবুজ্জামান]] ([[User talk:আফতাবুজ্জামান|talk]]) 18:33, 18 December 2023 (UTC)
:::::@[[User:আফতাবুজ্জামান|আফতাবুজ্জামান]]: Try my most recent edit at bnwiki. I wondered why "or" was missing from that table while comparing the enwiki/bnwiki versions. You can change the text on the right-hand side but "or" on the left-hand side must be unchanged. If that doesn't work, you would need to set up sandbox modules and a template that I can experiment with and add links to them maybe on my bnwiki talk so I can find them in the future. [[User:Johnuniq|Johnuniq]] ([[User talk:Johnuniq|talk]]) 22:30, 18 December 2023 (UTC)
::::::@[[User:Johnuniq|Johnuniq]], Thanks. [[User:আফতাবুজ্জামান|আফতাবুজ্জামান]] ([[User talk:আফতাবুজ্জামান|talk]]) 22:14, 19 December 2023 (UTC)
 
==Discussion at [[:Wikipedia:Village pump (technical)#Let's make Template:convert go away.|Wikipedia:Village pump (technical) §&nbsp;Let's make Template:convert go away.]]==
:::Thanks, but this page is a little out of date, and I will update it with the info that WOSlinker linked to. My comment about "performance challenges" was written when I had not absorbed the fact that some testcase timeouts were due to use of <code>frame:preprocess</code>. It actually looks as if Module:Convert is reasonably fast, although I haven't yet hammered it. In [[User:Johnuniq/sandbox|my sandbox]], there are 122 calls of {{tl|convert/sandboxlua}}, and the HTML source shows the Lua time usage is 0.348s (2.8 ms per call). That makes me think that Lua is fast enough even with the current bloated modules. Nevertheless, I'm thinking of some ways I could improve performance and will update the "Plans" section above with info, possibly within a few hours. [[User:Johnuniq|Johnuniq]] ([[User talk:Johnuniq|talk]]) 04:08, 3 March 2013 (UTC)
[[File:Symbol watching blue lashes high contrast.svg|25px|link=|alt=]]&nbsp;You are invited to join the discussion at [[:Wikipedia:Village pump (technical)#Let's make Template:convert go away.|Wikipedia:Village pump (technical) §&nbsp;Let's make Template:convert go away.]]. –[[User:Novem Linguae|<span style="color:blue">'''Novem Linguae'''</span>]] <small>([[User talk:Novem Linguae|talk]])</small> 07:37, 15 January 2024 (UTC)<!-- [[Template:Please see]] -->
{{od|3}}I've removed the plans as they were obsolete. Also, while the testcase pages require a significant time to render, the convert module appears to be sufficiently fast, so there is no reason to look for ways to speed it up. I now have 1689 calls in [[User:Johnuniq/sandbox|my sandbox]], and the Lua time usage is about 1 millisecond per convert. There is a per-page overhead, and it looks like a small number of converts takes around 40&nbsp;ms total. [[User:Johnuniq|Johnuniq]] ([[User talk:Johnuniq|talk]]) 10:52, 26 April 2013 (UTC)
 
== Doubled SI prefix in singular form with varname ==
== Status? ==
 
Now I am working on the Ukranian localisation of Module:Convert and I am faced with the bug of doubled SI prefix that appears if parameter varname is used in translation_table. The module uses the singular form of a unit. If the unit uses a plural or declensed singular form defined in parameter varname, then the SI prefix shows as normal. I tried to delete all the modifications that I have done to the module in the Ukranian wiki, and it seems that the bug also appears on a clean version of the English module. Also, it affects only units that have a specified varname, and units that don't work as normal.
I'm curious what the status is here, and when you might hope to be ready for deployment, etc.? [[User:Dragons flight|Dragons flight]] ([[User talk:Dragons flight|talk]]) 02:13, 6 June 2013 (UTC)
For example, unit Mbit shows as megamegabit ({{lang|uk|мегемегабіт}}), and Mm2 shows as megasquare megametre ({{lang|uk|мегаквадратний мегаметр}}). [[User:Repakr|Repakr]] ([[User talk:Repakr|talk]]) 08:42, 14 September 2024 (UTC)
:Yes, I've been wondering that too! I believe there are no significant problems: there are some minor rounding differences between the outputs from the template and the module, and some klunkiness where I'm not happy with the result of some combinations of options, but those same options cause the template to fail, so I do not know of anything significant. However, I've still been doing large refactoring, and I need to wait a week after I decide to stop that before moving towards deployment. The item currently at the top of my ''todo'' list is the fact that Unicode minus ('−' U+2212) is accepted with the precision (as in <code><nowiki>{{convert|123|mi|km|−2}}</nowiki></code>), and I'm wondering whether to support that. The module accepts Unicode minus and <code>&amp;minus;</code> with the input value, but the function for that does a bunch of other stuff so I would need to replace a simple <code>tonumber(x)</code> with yet another function. I'll also spend a couple of days doing some docs, and see if anything turns up in that process. My guess is that in about a week or two I'll ask for opinions on the next step. Deployment would show other problems, for example, there would probably be quite a few unusual units that I have not implemented. [[User:Johnuniq|Johnuniq]] ([[User talk:Johnuniq|talk]]) 03:17, 6 June 2013 (UTC)
:{{ping|Repakr}} Are you working with the [[:Someuk:Мodule:Convert]] real-lifeset issuesof caughtmodules upor withthe me,sandbox andmodules Isuch haven'tas done[[:uk:Мodule:Convert/пісочниця]]? anyIs convertthere worka test page forshowing the lastproblem? weekPreferably andthat would be in a half.sandbox somewhere with almost nothing else so I'm justcan slowlyeasily gettingsee backwhat modules are being used and tocan itexperiment. [[User:Johnuniq|Johnuniq]] ([[User talk:Johnuniq|talk]]) 0308:3659, 2114 JuneSeptember 20132024 (UTC)
::@[[User:Johnuniq|Johnuniq]]. I am currently working with the sandbox modules. I haven't created test case for template Convert yet, but there is section in my sandbox: [[uk:Користувач:Repakr/Чернетка#Тестування convert]], where I tested some feature. [[User:Repakr|Repakr]] ([[User talk:Repakr|talk]]) 09:14, 14 September 2024 (UTC)
:::My excuse this week is that I have got into a quagmire trying to adapt the module to work properly on [[:bn:]] (Bengali Wikipedia; anyone interested may like to follow [[:bn:User talk:Johnuniq#Links|my links]]). The unit names and so forth are pretty easy to handle, but lots of the code depends on the numbers using English digits, and it will take some time to work out how best to handle translations. [[User:Johnuniq|Johnuniq]] ([[User talk:Johnuniq|talk]]) 03:25, 28 June 2013 (UTC)
::::It{{ping|Repakr}} turnsThat outpage thathas theredozens isof quitetemplates aand lotI'm ofnot trickygoing stuffto take the time to play with involvedit. TheIf codeyou shouldpost nowa besimple ok,test butcase at [[:uk:User talk:Johnuniq]] I'mll stillhave workinga withlook somealthough editorsit theremight onnot gettingbe for a day or two. In the unittest, symbolspoint out what is wrong and nameswhat it should fixeddisplay. [[User:Johnuniq|Johnuniq]] ([[User talk:Johnuniq|talk]]) 1109:1624, 514 AugustSeptember 20132024 (UTC)
::::@[[User:Johnuniq|Johnuniq]], I am sorry, I didn't catch the meaning first time reading it. So, I added a test to your talk page. [[User:Repakr|Repakr]] ([[User talk:Repakr|talk]]) 09:30, 14 September 2024 (UTC)
:::::{{ping|Repakr}} I'm looking at function <code>variable_name</code> in [[:uk:Module:Convert/пісочниця]] and wondering what <code>exp_multiplier</code> is and why the function is so different from my ten-year old code. I'll have to leave it at the moment but will look again in a day or two. [[User:Johnuniq|Johnuniq]] ([[User talk:Johnuniq|talk]]) 10:40, 14 September 2024 (UTC)
::::::@[[User:Johnuniq|Johnuniq]], the function is different because Ukrainian uses a different declension than Polish. Ukrainian also has three field declension (metry, metriv, metra) as Polish, but declension differs based on numbers. It works like this singular form is used if the number is 1 or its combination with tens (except 11; like 21, 31), hundreds (like 101, 121, etc.), thousands, and so on; form metry is used if the number is 2, 3, 4 or its combination with tens (except 12, 13, 14; like 22, 32), hundreds (like 102, 122, etc.), thousands and so on; metriv is used if the number is 0 or higher than 4 (it includes 11, 12, 13, 14) or its combination with tens (like 24, 35), hundreds (like 104, 125, etc.), thousands and so on. Form metra is used for both 1/2 and 1.2 fractions. So for me, it was easier to rewrite a code using a function built in MediaWiki that chose the correct form for Ukrainian.
::::::<code>exp_multiplier</code> stands for expotential multiplier and it stores the value of <code>eng_scales</code>, so the text of <code>eng_scales</code> can be also declened based on forms of numbers, like milion, miliony, milioniv, miliona.
::::::Although I did the modification, I tried without those modifications and a bug was present. [[User:Repakr|Repakr]] ([[User talk:Repakr|talk]]) 13:12, 14 September 2024 (UTC)
Testing on this problem is at [[:uk:User:Johnuniq/convert]] with discussion at [[:uk:User talk:Johnuniq/convert]]. The bug seems to have been present since the original <code>varname</code> used for certain languages was developed more than ten years ago. [[User:Johnuniq|Johnuniq]] ([[User talk:Johnuniq|talk]]) 11:05, 15 September 2024 (UTC)
 
== Call from other Lua module ==
==Extra units==
Following is a quick test of a new module ([[Module:Convert/extra]]) showing how temporary units can be created without significant overhead.
*<code><nowiki>{{subst:convert/sandboxlua|12|RDF|lk=on}}</nowiki></code> → 12 [[double foot|double feet]] (7.3&nbsp;[[Metre|m]])
*<code><nowiki>{{subst:convert/sandboxlua|12|RM|lk=on}}</nowiki></code> → 12 [[metre]]s (39&nbsp;[[Foot (unit)|ft]])
*<code><nowiki>{{subst:convert/sandboxlua|12|J/DM|lk=on}}</nowiki></code> → 12 [[joule]]s per [[double metre]] (6.0&nbsp;[[Kilojoule|kJ]]/[[Kilometre|km]])
*<code><nowiki>{{subst:convert/sandboxlua|12|J/DM|lk=on|sp=us}}</nowiki></code> → 12 [[joule]]s per [[Double metre|double meter]] (6.0&nbsp;[[Kilojoule|kJ]]/[[Kilometre|km]])
*<code><nowiki>{{subst:convert/sandboxlua|12|DF|lk=on}}</nowiki></code> → 12 [[double foot|double feet]] (7.3&nbsp;[[Metre|m]])
*<code><nowiki>{{subst:convert/sandboxlua|12|DM|lk=on}}</nowiki></code> → 12 [[double metre]]s (79&nbsp;[[Foot (unit)|ft]])
[[Module:Convert/extra]] should be transcluded into only those pages which refer to a unit that is not defined in [[Module:Convert/data]]. [[User:Johnuniq|Johnuniq]] ([[User talk:Johnuniq|talk]]) 11:16, 5 August 2013 (UTC)
:I have inserted <code>subst:</code> into the above to freeze the results as they were at the time of this comment. The units were just a temporary experiment (which can be seen in {{oldid|Module:Convert/extra|567889408|this permalink}}), and I will remove them soon. [[User:Johnuniq|Johnuniq]] ([[User talk:Johnuniq|talk]]) 04:52, 14 August 2013 (UTC)
 
There currently doesn't seem to be an easy way to call this module from another Lua module. I made a small change to the sandbox code [[Special:Diff/1252830342/1303398379|here]] that works well in my tests, and if there are no objections I can implement it in the main module. <span class="nowrap">--[[User:Ahecht|Ahecht]] ([[User talk:Ahecht|<b style="color:#FFF;background:#04A;display:inline-block;padding:1px;vertical-align:middle;font:bold 50%/1 sans-serif;text-align:center">TALK<br />PAGE</b>]])</span> 19:02, 30 July 2025 (UTC)
== Error message enhancing ==
:Doesn't the 'standard' naming style (if there is one) use an underscore-prefixed function name for functions called from an external module as a way to distinguish those functions from template-called function names? So instead of <code>do_convert</code> it would be <code>_main_convert</code>? That seems to be in keeping with [[Module:Convert]]'s use of an underscore prefix for the helper function <code>_unit</code> which is called from another module.
:—[[User:Trappist the monk|Trappist the monk]] ([[User talk:Trappist the monk|talk]]) 19:19, 30 July 2025 (UTC)
::@[[User:Trappist the monk|Trappist the monk]] Makes sense, I've updated the sandbox. <span class="nowrap">--[[User:Ahecht|Ahecht]] ([[User talk:Ahecht|<b style="color:#FFF;background:#04A;display:inline-block;padding:1px;vertical-align:middle;font:bold 50%/1 sans-serif;text-align:center">TALK<br />PAGE</b>]])</span> 19:23, 30 July 2025 (UTC)
:::The sandbox code looks good to me. I put a test at [[Module:Sandbox/Johnuniq/temp]] with result at [[Module talk:Sandbox/Johnuniq/temp|talk]]. [[User:Johnuniq|Johnuniq]] ([[User talk:Johnuniq|talk]]) 04:25, 31 July 2025 (UTC)
::::{{done}} <span class="nowrap">--[[User:Ahecht|Ahecht]] ([[User talk:Ahecht|<b style="color:#FFF;background:#04A;display:inline-block;padding:1px;vertical-align:middle;font:bold 50%/1 sans-serif;text-align:center">TALK<br />PAGE</b>]])</span> 21:03, 31 July 2025 (UTC)
 
== Template-protected edit request on 27 August 2025 ==
IIC, the default inline error message reads like: <span style="background:#ffa500">[[Module talk:Convert|Conversion error]]: Cannot convert "torque" to "energy"</span> (the link is to this talkpage).
 
{{edit template-protected|Module:Convert|answered=yes}}
Let's compare this with the earlier [[Module:citation/CS1]]: <code><span style="color:red">|accessdate= requires |url= ([[Help:CS1_errors#accessdate_missing_url|help]])</span></code>. It links a specific helppage section, and adding the page to [[Category:Pages using citations with accessdate and no URL]] (example now on [[1948 Australian Grand Prix|this]] page).
Module doesn't have a fraction slash in pattern that look for floats. I added proposed change to the sanbox of the module. (It only affects in wikis that uses varname. I have already fixed it in ukwiki, but I propose my changes here aswell to make it synchronized with enwiki module.) [[User:Repakr|Repakr]] ([[User talk:Repakr|talk]]) 15:28, 27 August 2025 (UTC)
 
:I'll have a look a little later. We batch changes to convert so it might take a while. I'm afraid I had forgotten about our discussion at ukwiki, life got in the way. [[User:Johnuniq|Johnuniq]] ([[User talk:Johnuniq|talk]]) 02:48, 28 August 2025 (UTC)
First, the link to this talkpage is very generic (the same for all errors), and not that helpful (are we supposed to report it, or to fix it?). I suggest it links to a documentation page section, at least as precise as the four categories are. It can ''also'' add a link like <tt><small>(talk)</small></tt> to this talkpage indeed.
::{{ping|Repakr}} I see the change is very straightforward and, as you say, only affects sites like ukwiki which use variable names. However, <code>clean:match('[./⁄]')</code> is not correct. The fraction slash is a Unicode character which is encoded in UTF-8 here. It is three hex bytes: E2 81 84. That regex is fast because it uses Lua's built-in and simplistic procedure, namely it looks only at the bytes, not the characters. It would match anything with a dot or a slash, but also anything with the byte E2, or byte 81, or byte 84. That might be good enough for typical wikitext but I'll think about adding something with Lua's <code>find</code> or <code>mw.ustring.match</code>. Using ustring is much slower because it uses Lua code to emulate Lua's compiled-C regex—an amazing accomplishment. However, that might be simplest and very adequate. Module:Convert defines ustring = mw.ustring so the replacement would be <code>ustring.match(clean, '[./⁄]')</code>. [[User:Johnuniq|Johnuniq]] ([[User talk:Johnuniq|talk]]) 06:00, 28 August 2025 (UTC)
 
:::Yeah, I hadn't taken into account that fraction slash is a Unicode character. Therefore, I should have used <code>mw.ustring.match</code>. As for our discussion at ukwiki, I planned to remind you by the end of this month. However, it isn't an urgent feature, so you can take as much time as you need to look into it. [[User:Repakr|Repakr]] ([[User talk:Repakr|talk]]) 09:13, 28 August 2025 (UTC)
Second, about that orange color. Note that these messages are inline, warning a reader who most likely does not know what to do with it (there are 100 readers for one knowing editor). Isn't there a less-alarming way of messaging? Put () brackets around it, to separate it from content text maybe? And anyway, it is way too dark as a background color (black or blue text does not contrast enough this way). The same standout effect on a white page is provided by a lighter orange color say <span style="background:#ffcc69">#ffcc69, makes easier reading</span>.
 
 
Together: <span clas="noprint" style="background:#ffcc69;">&#x20;([[Template:Convert/list of units#LENGTH|Conversion error]] <small>([[Module talk:Convert|talk]])</small>: Cannot convert "torque" to "energy")</span> -[[User:DePiep|DePiep]] ([[User talk:DePiep|talk]]) 14:17, 19 September 2013 (UTC)
:I hope to give a substantive reply later (RL issues are interfering now), but meanwhile I have dumped a reasonably complete list of all messages that the module can display [[User:Johnuniq/Convert messages|here]]. That may be useful while considering what should happen. [[User:Johnuniq|Johnuniq]] ([[User talk:Johnuniq|talk]]) 03:03, 20 September 2013 (UTC)
::It's later, and I'm not likely to get any quality time to spend on this, so I'll just add it to my long todo list. I like the links produced by CS1, but there's a fair bit of work getting that all organized. I don't even have a good doc page, although I made a start [[User:Johnuniq/Convert documentation|here]]. I prefer your lighter orange, will do soon if no one offers an alternative suggestion. [[User:Johnuniq|Johnuniq]] ([[User talk:Johnuniq|talk]]) 10:43, 20 September 2013 (UTC)
----
{{ping|DePiep}} I have implemented as much of your above suggestion as I can at the moment. I would like to include links to a help page as above, and have thought about how to implement that. However, it will have to wait for a decent help page, and a bit of time to do the work. I used [[Special:ExpandTemplates]] to capture the following:
*<code><nowiki>{{convert/sandboxlua|12|m|kg}}</nowiki></code> → {{convert/sandboxlua|12|m|kg}}
*:<code><nowiki><span class="noprint" style="background:#ffcc69;">[[Module talk:Convert|Conversion error]]: Cannot convert "length" to "mass"</span></nowiki></code>
*<code><nowiki>{{convert/sandboxlua2|12|m|ft|abr=off}}</nowiki></code> → {{convert/sandboxlua2|12|m|ft|abr=off}}
*:<code><nowiki>12 metres (39&amp;nbsp;ft)<span class="noprint" style="background:peachpuff;">[[Module talk:Convert|Conversion warning]]: Ignored invalid option "abr=off"</span></nowiki></code>
The second example uses the new template {{tl|convert/sandboxlua2}} which includes "warnings&nbsp;=&nbsp;on" (that parameter has to be in the template, not the convert).
 
I also implemented WOSlinker's suggestion on my talk so tracking categories are only included in the error or warning if the current page is in a wanted namespace (default "0,10", that is, main and template, per your suggestion). In case you missed it, I'll mention here that I updated a reply on my talk to say that some testing shows that 31 warnings were generated in 7,540 converts scraped from various articles. [[User:Johnuniq|Johnuniq]] ([[User talk:Johnuniq|talk]]) 09:54, 21 September 2013 (UTC)
:::Thanks. The link I propose could point to the type-section (in the input list), when applicable (when it is a unit-issue). Like: [[Help:Convert#length]] (and add piped label). But maybe the idea Wikid77 launched the other day might be better (using a superimposed linked text). btw, the message could use a starting space. -[[User:DePiep|DePiep]] ([[User talk:DePiep|talk]]) 10:12, 21 September 2013 (UTC)
:::That is, the warning could use a leading space. Error messages not. -[[User:DePiep|DePiep]] ([[User talk:DePiep|talk]]) 11:06, 21 September 2013 (UTC)
 
== parameter warnings=true ==
 
If I am correct, there is a parameter {{para|warnings}} that can be set to {{para|warnings|true}} (see [[User:Johnuniq/Using the convert module#Module problems]]). If set, it should fill [[:Category:Convert invalid option]] (when an errors occurs).
 
 
I cannot check the category filling, because I do not know how to force an "invalid option" error. A hint anyone?
 
Some tests:
* <nowiki>{{Convert/sandboxlua|5|km|mi}}</nowiki> &rarr; {{Convert/sandboxlua|5|km|mi}}
* <nowiki>{{Convert/sandboxlua|5|km|mi|warnings=true}}</nowiki> &rarr; {{Convert/sandboxlua|5|km|mi|warnings=true}}
* <nowiki>{{Convert/sandboxlua|5|km|mi|warnings=false}}</nowiki> &rarr; {{Convert/sandboxlua|5|km|mi|warnings=false}}
* <nowiki>{{Convert/sandboxlua|5|km|mi|warnings=foo}}</nowiki> &rarr; {{Convert/sandboxlua|5|km|mi|warnings=foo}}
* <nowiki>{{Convert/sandboxlua|5|km|mi|warnings=}}</nowiki> &rarr; {{Convert/sandboxlua|5|km|mi|warnings=}}
* <nowiki>{{Convert/sandboxlua|5|km|mi|foo=true}}</nowiki> &rarr; {{Convert/sandboxlua|5|km|mi|foo=true}}
 
I find this code confusing, because the parameter name "warnings" is used (checked) twice for apparently opposing values. The logic may be right, but clear it is not.
<syntaxhighlight lang="lua">
local function add_warning(parms, mcode, text)
if warnings then
if parms.warnings == nil then
parms.warnings = message({ mcode, text })
end
end
end
</syntaxhighlight>
 
-[[User:DePiep|DePiep]] ([[User talk:DePiep|talk]]) 15:49, 19 September 2013 (UTC)
:I hoped that the comments that are in the code would help:
:: <code>-- If enabled, add a warning that will be displayed after the convert result.</code>
:: <code>-- To reduce output noise, only the first warning is displayed.</code>
:The <code>warnings</code> variable is set from the configuration:
:: <code>warnings = boolean(args.warnings) -- true if want warnings for invalid options</code>
:The line "<code>if warnings then</code>" tests if warnings are enabled.
:The line "<code>if parms.warnings == nil then</code>" means only the first warning is displayed (if there already is a warning, <code>parms.warnings</code> will be set, not nil). That is to reduce clutter that would appear in an article if malformed input was given. As I just commented above, a new list of messages is [[User:Johnuniq/Convert messages|here]], and it includes some warnings. [[User:Johnuniq|Johnuniq]] ([[User talk:Johnuniq|talk]]) 03:14, 20 September 2013 (UTC)
----
I've had time to investigate the above interesting bug where using "warnings=true" causes "true" to be appended to the result. [[Module:Convert]] includes the following code:
<syntaxhighlight lang="lua">
-- The wikitext with the final result is set (not shown here).
wikitext = ...
-- If any warnings have been generated, they are appended.
if parms.warnings then
wikitext = wikitext .. parms.warnings
end
</syntaxhighlight>
The problem is that the parms table contains what the user entered, and because the convert contains "warnings=true", the module sets <code>parms.warnings = true</code>. That is then appended, and Lua helpfully converts the Boolean "true" to the string "true". I'll think about making that more robust. [[User:Johnuniq|Johnuniq]] ([[User talk:Johnuniq|talk]]) 06:29, 20 September 2013 (UTC)
:Don't explain it, code should be self-explaining. Just don't use the same name twice. It is bad programming practice. -[[User:DePiep|DePiep]] ([[User talk:DePiep|talk]]) 14:07, 20 September 2013 (UTC)
::That's an interesting issue which has been widely debated. At one time I used to make all my variables unique (check my user name!), mainly because I hated searches that gave false hits, although I was inclined to also agree with the "bad programming practice" sentiment. But then namespaces became fashionable and I had to adapt, and now can't see a problem with similar things having the same name. [[User:Johnuniq|Johnuniq]] ([[User talk:Johnuniq|talk]]) 00:24, 21 September 2013 (UTC)
:::The problem is confusion, as I said. For the reader, it is an extra mental step to keep them apart. That is, if the reader realizes a difference. They are not always mentioned in each others vicinity. (About mental steps: after studying (not reading) I discovered that 'mcode' means message code. I do not see why it would not be like msgcode to be clear a day earlier). -[[User:DePiep|DePiep]] ([[User talk:DePiep|talk]]) 09:17, 21 September 2013 (UTC)
:::(And prefix 'cvt' as in 'cvt_bad_sigfig' probably means message too). -[[User:DePiep|DePiep]] ([[User talk:DePiep|talk]]) 09:22, 21 September 2013 (UTC)
::::I hear you, but I will offer a suggestion that applies to most code that I write: search the module to see if "mcode" is used somewhere else where there might be an explanation. I know that's not answering you, but it is a practical suggestion that will help in my code perhaps a quarter of the time. Re "cvt_": I wanted a unique prefix so that all the message codes could be found with a search, and while "msg_" would have fitted that description, I picked "cvt_" because it is very easy to find reasons to use "msg" in a program, and conceivably also "msg_". The "cvt_" is to indicate a ''convert'' code (perhaps later I would have found reason for other kinds of codes, and used a different prefix for them). The first usage of "cvt_" in the module explains that it is a string used as a key to get message information. I remember your advice about "don't explain", and am mentioning all this to show my reasoning, not in the hope that you will agree.
::::I fixed the bug that used to be shown above when "warnings=xxx" is used in a convert. [[User:Johnuniq|Johnuniq]] ([[User talk:Johnuniq|talk]]) 10:09, 21 September 2013 (UTC)
 
==boolean==
The function boolean is wrong. It should return either "false" or "true", never nil. nil is not a boolean value. The input parameter called "text" can be a numerical value too, so is named wrong. No need to bend meanings. -[[User:DePiep|DePiep]] ([[User talk:DePiep|talk]]) 14:10, 20 September 2013 (UTC)
:Option value should be "on" just as other such params have. No need to introduce "yes", "y", "1" as option value. -[[User:DePiep|DePiep]] ([[User talk:DePiep|talk]]) 14:24, 20 September 2013 (UTC)
::It's true that my boolean function is self-indulgent as I have had to implement similar stuff on different systems where all the possible "true" values are required, however, it's perfectly valid Lua. The parameter is called "text" because it can only be a string, not numeric (it's not intended to be used from other modules where arbitrary parameters could be passed). Also, it's conventional Lua to not return anything for false, although I do feel unclean after doing that, and my more recent functions have tended to always return a value. I'll try to look around some other templates/modules to gauge what boolean option values are generally used, but we're talking about a pretty minor issue that isn't even used currently. One issue about only regarding "on" as true is error reporting—should the module report an error if the invoking template contains "warnings = yes"? [[User:Johnuniq|Johnuniq]] ([[User talk:Johnuniq|talk]]) 00:16, 21 September 2013 (UTC)
::I trimmed the boolean function so it accepts only "on" and "yes". [[User:Johnuniq|Johnuniq]] ([[User talk:Johnuniq|talk]]) 10:11, 21 September 2013 (UTC)
:::OK then. Saves testing all these variants. -[[User:DePiep|DePiep]] ([[User talk:DePiep|talk]]) 10:59, 21 September 2013 (UTC)
 
== Before going live ==
 
Before going live we need more testing. All options, and all extremes (for example). Also we better test the border issues
(like input '0'). -[[User:DePiep|DePiep]] ([[User talk:DePiep|talk]]) 22:35, 19 September 2013 (UTC)
:The module code is chaotic. -[[User:DePiep|DePiep]] ([[User talk:DePiep|talk]]) 22:42, 19 September 2013 (UTC)
::Yes please. More brutal testing would be good, and please let me know any good or bad findings. I guess you've seen [[User:Johnuniq/Using the convert module]] which has links to various tests, as well as a "roadblocks" section. I'll plead guilty to "complex", but I can't agree with "chaotic"! [[User:Johnuniq|Johnuniq]] ([[User talk:Johnuniq|talk]]) 10:36, 20 September 2013 (UTC)
 
== Range with a negative ==
 
About writing a range of values that contain a negative value.
Consider
* <nowiki>{{convert|-8|-|-3|F|C}}</nowiki> &rarr; {{convert|-8|-|-3|F|C}}
* <nowiki>{{convert/sandboxlua|-8|-|-3|F|C}}</nowiki> &rarr; {{convert/sandboxlua|-8|-|-3|F|C}}
The minuses and dashes are formally correct in lua, but make awkward writing/reading. [[WP:MOSNUM]] gives this option:<br>
''If negative values are involved, an en dash might be confusing. Use words instead: {{xt|−10 to 10}}, not {{!xt|−10 &ndash; 10}}.''<br>
The example would then look like: −8 to −3 °F (−22 to −19 °C). For ease of reading, 'to' should be used in both ranges, even when only one would have a negative. Ideas anyone? -[[User:DePiep|DePiep]] ([[User talk:DePiep|talk]]) 00:17, 21 September 2013 (UTC)
:I agree that the en-dash-minus is ugly and should not be used, however I wanted to emulate the current templates as closely as possible (although there is a slight spacing bug in the current template, as shown above). If "to" is wanted, that parameter can be used:
:*<code><nowiki>{{convert/sandboxlua|-8|to|-3|F|C}}</nowiki></code> → {{convert/sandboxlua|-8|to|-3|F|C}}
:[[User:Johnuniq|Johnuniq]] ([[User talk:Johnuniq|talk]]) 00:29, 21 September 2013 (UTC)
::Fair enough. Feature request, maybe later on. -[[User:DePiep|DePiep]] ([[User talk:DePiep|talk]]) 08:20, 21 September 2013 (UTC)