Module talk:Convert: Difference between revisions

Content deleted Content added
Overview: mw.loadData ?
Repakr (talk | contribs)
 
(318 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>}}
==Overview==
{{archives|search=yes|searchprefix=Module talk:Convert/Archive}}
This module provides a possible implementation of <nowiki>{{convert}}</nowiki>. Associated pages are:
{{Lua sidebar}}
#[[Template:Convert/sandboxlua]] – template which invokes the module
#[[Template:Convert/testcases]] – template tests
#[[Module:Convert]] – module to convert units
#[[Module:Convertdata]] – module with unit definitions, used by #3
#[[User:Johnuniq/Conversion data]] – master list of unit definitions
#[[User:Johnuniq/Making the units table]] – program to translate #5 to #4
#[[Template talk:Convert#Lua Module:Convert]] – some notes about plans
 
== Error on Tewiki for a testcase ==
Usage examples:
*<code><nowiki>{{convert|5.2|m|ftin}}</nowiki></code> → {{convert|5.2|m|ftin}}
*<code><nowiki>{{convert|5+3/8|in}}</nowiki></code> → {{convert|5+3/8|in}}
*<code><nowiki>{{convert|60|x|120|m|ft}}</nowiki></code> → {{convert|60|x|120|m|ft}}
 
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)
Currently, the real master list of unit definitions is a text file on my computer (I have a script to convert that text file to the wikitext used at #5). The uniformly formatted text file is easier for making bulk changes, but will be discarded when the module nears completion.
:{{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):
:*<code><nowiki>{{convert|5.1+2/3|mft|ftinin}}</nowiki></code> → {{convert|5.1+2/3|mft|ftinin}}
: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)
:{{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)
::@[[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)
:::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)
 
== bnwiki ==
In addition to the test page (#2 above), I run a test program on my local system that feeds hundreds of tests into the module.
 
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)
Module:Convert has many issues to be fixed, and some features that need to be implemented. It does not support inputs with multiple units, such as {{nowrap|<code>3 ft 6 in</code>}}, and does not support large scale units like <code>e3km</code>. Complex units like the <code>hand</code> unit of length have not been implemented, and there are hundreds of unit codes that are not yet defined (the units which are defined are listed at #5).
:@[[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)
::I worked out the ___location of the bnwiki module sandbox and created:
::*[[:bn:Module:খেলাঘর/Johnuniq/Convert]] • Copy from [[Module:Convert]] (I used the wrong edit summary: the comment fix is in the next module).
::*[[: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.]]==
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)
[[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]] -->
::presuming that a page that requires data conversion might require many of them, and consideing the sheer size of [[Module:Convertdata]], 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)
 
== Doubled SI prefix in singular form with varname ==
 
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.
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)
:{{ping|Repakr}} Are you working with the [[:uk:Мodule:Convert]] set of modules or the sandbox modules such as [[:uk:Мodule:Convert/пісочниця]]? Is there a test page showing the problem? Preferably that would be in a sandbox somewhere with almost nothing else so I can easily see what modules are being used and can experiment. [[User:Johnuniq|Johnuniq]] ([[User talk:Johnuniq|talk]]) 08:59, 14 September 2024 (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)
:::{{ping|Repakr}} That page has dozens of templates and I'm not going to take the time to play with it. If you post a simple test case at [[:uk:User talk:Johnuniq]] I'll have a look although it might not be for a day or two. In the test, point out what is wrong and what it should display. [[User:Johnuniq|Johnuniq]] ([[User talk:Johnuniq|talk]]) 09:24, 14 September 2024 (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 ==
 
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)
: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 ==
 
{{edit template-protected|Module:Convert|answered=yes}}
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)
::{{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)