The discourse-units theme component automatically converts durations, lengths, and masses between various scales. It can be installed from the GitHub repository: https://github.com/udan11/discourse-units. However, users have reported issues with the component’s unit recognition, such as incorrectly identifying words like “invites” as “inches” AntiMetaman.
To address this issue, dan plans to modify the component to recognize whole words. neounix suggests implementing a whitelist of acceptable units and only converting numbers with units, while riking proposes accepting only truncations of full forms. Additionally, mognet recommends allowing users to limit the types of units converted, such as only weight measurements or specific unit conversions like pounds to kilos.
discourse-units is a theme component that automatically detects and converts durations, lengths and masses between various scales to make them easier to comprehend.
I remember this being a bit tricky. I did not check for the “unit” to be a whole word because I wanted to avoid defining all forms (singular and plural) of measurement units (min, minute, mins, minutes). I will have to do it.
Might be a good idea (1) not to convert or display your conversion for any number which does not have units behind it; and (2) to have a white list of acceptable units and only convert those; to save you from having an intractable problem.
One plan of attack would be to have a few “acceptable full forms” and only accept truncations of those - so mins, minutes and ins, inches → in yes, inside no (there are extra letters on the end).
Would be useful if you can limit the type of units you would like to convert, for instance to just limit to convert weight measurements, and if possible be more specific and limit to specifics units like just pounds to kilos and kilos to pounds.