Обговорення користувача:Johnuniq/convert
Додати темуLinks
[ред. код]- Template:Convert/пісочниця
- Module:Convert/пісочниця
- Module:Convert/data/пісочниця
- Module:Convert/text/пісочниця
- Module:Convert/makeunits
- Module:Convert/документація/дані перетворень
Convert
[ред. код]@Repakr: I've moved the test from my talk. It is more than ten years since I developed varname
for Slovene Wikipedia and it looks like there was always a bug that no one noticed/reported. See test using kilo at sl:User:Johnuniq/translate#2024 where "kilo" is duplicated. I'll think about it. Johnuniq (обговорення) 08:03, 15 вересня 2024 (UTC)
- slwiki configures
abbr
todefault on
. That means, almost all their converts use symbols, not names. Therefore, no one has reported seeing duplicate prefixes such askilokilometer
. Johnuniq (обговорення) 06:48, 16 вересня 2024 (UTC)
@Repakr: Your use of mw.language.getContentLanguage():convertPlural
is obviously better than the code I had in Module:Convert. The clever language functions did not exist when I started working on convert and I never noticed that they were added. The bug is that the SI prefix is inserted twice for singular values with a unit that defines varname
. The reason is that in function variable_name
, the variable unit_table.name1
actually uses the metatable unit_prefixed_mt
. That metatable inserts the SI prefix and then variable_name
inserts it again. I'm thinking about how to fix that and will comment here later, possibly not until the weekend. Johnuniq (обговорення) 06:07, 17 вересня 2024 (UTC)
@Repakr: I have edited Module:Convert/пісочниця. I haven't fully thought about it yet and will return. Let me know what you think.
I have some questions about function variable_name
:
- How can
clean
contain '/'? - Currently, the function will always return
unit_table.name2
ifvarname
is not defined. It would never returnunit_table.name1
. Is that what is wanted? Are you planning to definevarname
for all units?
At enwiki, I could run test code in a module with a name like Module:Sandbox/Johnuniq/test
. What name would I use here? Johnuniq (обговорення) 05:25, 20 вересня 2024 (UTC)
- @Johnuniq, thank you for your work.
- Here are some answers:
- 1. I assumed it would have / if the user enters fractions with a slash, like 1+1/2. Also, today I tried without it, and it doesn't work.
- 2. No, it isn't. As for defining
varname
, I am planning to add it for most units except units that don't have plural forms like bu. - You can run test code in a module
Модуль:Пісочниця/Johnuniq/test
. Also, I have one more request: is it possible to add a new optional parameter (likepername
) for units in case the singular form of units doesn't work for the phrase "per unitname" (I added an example in Користувач:Johnuniq/convert#Test for per units)? --Repakr (обговорення) 08:03, 20 вересня 2024 (UTC)- Thanks, I'll look at all that including pername. Re clean, it's a long time since I spent much time with convert and testing confirms that input 1+1/2 turns up just like that in variable_name. I had forgotten that. Johnuniq (обговорення) 09:17, 20 вересня 2024 (UTC)
@Repakr: I have done quite a lot of changes. See my recent contributions and please check them. I added some dummy names such as acrePER which you will need to fix. I will have to do a lot of checking before I have an opinion on whether this is complete. Meanwhile, please give try it out. Johnuniq (обговорення) 10:06, 22 вересня 2024 (UTC)
- Thank you. I will check and try a bit later. --Repakr (обговорення) 18:29, 22 вересня 2024 (UTC)
@Repakr: You will see that I made some edits to the module. Let me know if there are any problems. I have now examined your extras and see that you had to go to a lot of trouble to make convert work properly. Thanks, I will try to incorporate as much of that as reasonable in the enwiki version. Life is much easier when the module is only slightly different at each Wikipedia. We will need a significant number of tests to check that edits to the modules give correct results. It would be good if you could add a list at Користувач:Johnuniq/convert. Just the converts is all that is needed, each with an asterisk before to make a bulleted list. That makes it easy to see if an edit has changed anything (I put the page before the edit in a browser window, and the page after the edit in another tab, then alternate between them). There is no need to do this soon. Take as much time as wanted. Johnuniq (обговорення) 05:07, 25 вересня 2024 (UTC)
- I need to do more testing, and I'm hoping you can give things a thorough test here. The sandbox convert that I uploaded last should work at all Wikipedias and that is what I would like to use so long as it works here. Johnuniq (обговорення) 06:59, 26 вересня 2024 (UTC)
- @Johnuniq, I was busy this week, so I didn't have free time till this Saturday. I will add tests. As for problems, firstly, I wasn't sure, but now I know that units with a fraction that uses engineering notation like 1.2 million have to use the next forms: meters numerals (like thousand, millions) have to use the third form of varname, and units have to use the second form of varname. --Repakr (обговорення) 11:31, 28 вересня 2024 (UTC)
- I assume convertPlural has no way of handling that? Therefore special code would be needed? I would like to keep it as generic as possible but if special code for ukwiki is needed, of course that can be done. It would be great if you could work out some examples that demonstrate what is needed. That would preferably be done using dummy names that are easy for me to follow such as "one" for name1 and "two!three!four" for varname. When you have time, the most important work as far as I am concerned would be to check what I did to the sandbox module and decide if it is ok. Then we can work out what needs to be added. Do you want me to ping you each time I comment here? Johnuniq (обговорення) 11:59, 28 вересня 2024 (UTC)
- I have tested and think that something like this needs to be added to the line 2934:
if exp_multiplier then clean = 1 * exp_multiplier -- force selection of name if the exponent is present else clean = 34.5 -- force selection of name for a float value end
- Also, I found out that pername doesn't work with SI prefixes. Test of this is at Користувач:Johnuniq/convert, see last two last test of pername. --Repakr (обговорення) 13:23, 28 вересня 2024 (UTC)
- It is unnecessary to ping me every time, I have added a page to the watch list. But it could speed up a response from me. --Repakr (обговорення) 13:34, 28 вересня 2024 (UTC)
- @Johnuniq. As for anything else, it seems it works as expected. --Repakr (обговорення) 13:45, 28 вересня 2024 (UTC)
- It is hard for me to understand what is going on so please spell out exactly what text is wrong. What should it be? I have stared at
{{convert|10|mm/s|m/h|abbr=off}}
and{{convert|10|mm/ms|m/h|abbr=off}}
for ten minutes and cannot see a problem. What is a test case that failed before your above change to the module? What was wrong with its output? Johnuniq (обговорення) 05:57, 29 вересня 2024 (UTC)- The problem is that the first test uses seconds, and the second one uses milliseconds, but the output for both shows second (секунду). If I remove the pername from seconds, then the first output would be 10 millimeters per second, and the second will be 10 millimeters per millisecond. --Repakr (обговорення) 06:39, 29 вересня 2024 (UTC)
- OK, I'll fix that in a day or two. Please specify at least one convert that failed before your change to the module above, and explain what is wrong and what it should be. Is "1 * exp_multiplier" a typo (why multiply by 1)? Johnuniq (обговорення) 08:28, 29 вересня 2024 (UTC)
- The test for it is 3+1⁄2 тисячі квадратних метрів (3 500 квадратних метрів) or 1,0 тисячі квадратних метрів (1 000 квадратних метрів). If the module is used without the code above, the result would be 1,0 тисячі квадратного метра, but the correct form is 1,0 тисячі квадратних метрів. So to get the right form the clean needs to be multiplied if the exponent is present. However, if the input is 3+1/2, convertPlural would throw an error message. To mitigate that, the dummy input was used as 1. --Repakr (обговорення) 08:46, 29 вересня 2024 (UTC)
- Thanks, I'll think about all that. I'm still confused about multiplying by 1. It may as well be
clean = exp_multiplier
. Johnuniq (обговорення) 11:03, 29 вересня 2024 (UTC)
- Thanks, I'll think about all that. I'm still confused about multiplying by 1. It may as well be
- The test for it is 3+1⁄2 тисячі квадратних метрів (3 500 квадратних метрів) or 1,0 тисячі квадратних метрів (1 000 квадратних метрів). If the module is used without the code above, the result would be 1,0 тисячі квадратного метра, but the correct form is 1,0 тисячі квадратних метрів. So to get the right form the clean needs to be multiplied if the exponent is present. However, if the input is 3+1/2, convertPlural would throw an error message. To mitigate that, the dummy input was used as 1. --Repakr (обговорення) 08:46, 29 вересня 2024 (UTC)
- OK, I'll fix that in a day or two. Please specify at least one convert that failed before your change to the module above, and explain what is wrong and what it should be. Is "1 * exp_multiplier" a typo (why multiply by 1)? Johnuniq (обговорення) 08:28, 29 вересня 2024 (UTC)
- The problem is that the first test uses seconds, and the second one uses milliseconds, but the output for both shows second (секунду). If I remove the pername from seconds, then the first output would be 10 millimeters per second, and the second will be 10 millimeters per millisecond. --Repakr (обговорення) 06:39, 29 вересня 2024 (UTC)
- It is hard for me to understand what is going on so please spell out exactly what text is wrong. What should it be? I have stared at
- I have tested and think that something like this needs to be added to the line 2934:
- I assume convertPlural has no way of handling that? Therefore special code would be needed? I would like to keep it as generic as possible but if special code for ukwiki is needed, of course that can be done. It would be great if you could work out some examples that demonstrate what is needed. That would preferably be done using dummy names that are easy for me to follow such as "one" for name1 and "two!three!four" for varname. When you have time, the most important work as far as I am concerned would be to check what I did to the sandbox module and decide if it is ok. Then we can work out what needs to be added. Do you want me to ping you each time I comment here? Johnuniq (обговорення) 11:59, 28 вересня 2024 (UTC)
@Repakr: The reason my code chose метра is that 1.0
is a float. Consider:
{{convert/пісочниця|1.2|m2|m2|lk=on|abbr=off}}
→ 1,2 квадратного метра (1,2 квадратного метра){{convert/пісочниця|1.2|e3m2|m2|lk=on|abbr=off}}
→ 1,2 тисячі квадратних метрів (1 200 квадратних метрів){{convert/пісочниця|1.2345|e3m2|m2|lk=on|abbr=off}}
→ 1,2345 тисячі квадратних метрів (1 234,5 квадратного метра)
I need to understand the rules. The above currently shows метра for 1.2 m2 and метрів for 1.2 e3m2 and 1.2345 e3m2. Is that correct? Is there a rule that you can describe? Johnuniq (обговорення) 23:38, 29 вересня 2024 (UTC)
- Firstly, I will call метра (genitive case, singular) as form 1 and метрів (genitive case, plural) as form 2 for this passage of the text.
- As far as I can say, the rule is: If fraction or float are followed right away by units, then units will use form 1. If numerals (like thousand, million, etc.) are used between fractions or float and units, then numerals will use form 1, and units will use form 2. It is similar to tests
{{convert/пісочниця|1|m2|lk=on|abbr=off}}
and{{convert/пісочниця|1|e3m2|m2|lk=on|abbr=off}}
. --Repakr (обговорення) 16:17, 30 вересня 2024 (UTC)- Thanks, that is clear. Please see the "m2, e3m2" tests I added. Are they correct? I have started looking at fixing the pername code to handle SI prefixes (I added
ks
and you hadms
which both don't work at the moment). More in a day or two. Johnuniq (обговорення) 07:18, 2 жовтня 2024 (UTC)- I think I fixed pername. Please check carefully and think of any further tests needed! Johnuniq (обговорення) 09:51, 2 жовтня 2024 (UTC)
- I have tested with normal pername and with pername that has #, and it works as expected. As for m2, e3m2, they are correct. I will check if further tests are needed and, by the end of the week, give my answer. --Repakr (обговорення) 16:13, 3 жовтня 2024 (UTC)
- It seems that all works as expected. There is a small thing with per (According to ДСТУ 3651.1-97 if units in the power of 1, and it describes the speed of process (like miles per hour), then per changes from 'na' to 'za'. I am unsure if it needs to be fixed (because 'na' is perfectly fine to understand, and it only affects automatically formed values), or if it is possible to implement.), but apart from that, all works without problems. --Repakr (обговорення) 13:41, 6 жовтня 2024 (UTC)
- I'm glad it's working. I will eventually put the new Module:Convert at enwiki but first I will see whether it handles what is wanted at slwiki. If you would like to post a couple of examples of converts that could be optimized, please do so and say what the optimum text would be. What does "units in the power of 1" mean? Does that mean the exception applies, for example, to meter but not to square meter? Let me know if another problem is found. Johnuniq (обговорення) 03:12, 7 жовтня 2024 (UTC)
- For now, I am not confident enough to add examples for this because I don't fully understand it either. Therefore, I will ask others about this case and later give my examples. --Repakr (обговорення) 08:10, 7 жовтня 2024 (UTC)
- I'm glad it's working. I will eventually put the new Module:Convert at enwiki but first I will see whether it handles what is wanted at slwiki. If you would like to post a couple of examples of converts that could be optimized, please do so and say what the optimum text would be. What does "units in the power of 1" mean? Does that mean the exception applies, for example, to meter but not to square meter? Let me know if another problem is found. Johnuniq (обговорення) 03:12, 7 жовтня 2024 (UTC)
- It seems that all works as expected. There is a small thing with per (According to ДСТУ 3651.1-97 if units in the power of 1, and it describes the speed of process (like miles per hour), then per changes from 'na' to 'za'. I am unsure if it needs to be fixed (because 'na' is perfectly fine to understand, and it only affects automatically formed values), or if it is possible to implement.), but apart from that, all works without problems. --Repakr (обговорення) 13:41, 6 жовтня 2024 (UTC)
- I have tested with normal pername and with pername that has #, and it works as expected. As for m2, e3m2, they are correct. I will check if further tests are needed and, by the end of the week, give my answer. --Repakr (обговорення) 16:13, 3 жовтня 2024 (UTC)
- I think I fixed pername. Please check carefully and think of any further tests needed! Johnuniq (обговорення) 09:51, 2 жовтня 2024 (UTC)
- Thanks, that is clear. Please see the "m2, e3m2" tests I added. Are they correct? I have started looking at fixing the pername code to handle SI prefixes (I added