Metrication v0.0.7
Metrication is an add-on for Firefox that identifies Imperial/US customary units and converts them to appropriate metric units.
When an Imperial/US unit is identified, Metrication hides it and inserts an appropriate metric value and unit so that the document reads as if it were originally written for a metric audience.
The replacement metric value and unit are embedded within a hotspot that will popup a small window containing: 1) the original text; 2) the working involved in the conversion to a higher number of decimal places; and 3) any other conversions that may have been possible due to cultural or other ambiguities.
If the user deems the default conversion to be inappropriate, a popup menu will also allow the selection of an alternate conversion or reversion to the original text.
The Metrication add-on attempts to provide "appropriate metric units" by varying the output unit on the scale of the output value and not be fixed to the input unit. For example, "40 miles" will be represented as "64.4 kilometres" whereas "⅛ miles" will be represented as "201 metres". This scaling can also be limited so that values like "30,000 feet" will be represented as "9,144 metres" in line with convention.
Scaling is also applied to decimal places as output values increase. As previously stated, "40 miles" will be represented as "64.4 kilometres" however, "200 miles" will be represented as "322 kilometres" and not as "321.868 kilometres".
The Metrication add-on will detect both full unit names like "feet" and abbreviated unit names like "ft". The add-on will use full names or abbreviated names in its output depending upon which is detected in the input. For example: "40 mi." will be converted to "64.4 km.". This can lead to some false positives: for example, the abbreviation for "font point size" is "pt" however, this could also be seen as an attempt to abbreviate "pint". The popup will explain the conversion used and hopefully the context will reveal that there is no such text size as "5.7 l" (litres).
The Metrication add-on recognises fractions in two distinct ways: 1) Unicode characters expressing fractions, for example "⅘" is Unicode character 8536 (decimal, 2158 in hexadecimal); and 2) textual representation of fractions using numerals, spaces and slashes, for example "4 1/2". There are also Unicode representations of superscript and subscript numerals, for example "⁶" (Unicode 8310 decimal) and "₆" (Unicode 8326 decimal) that are interpreted as numerators and denominators accordingly when separated by a slash.
Ambiguity may arise as the unit "Gallon" may actually refer the traditional gallon used within the United Kingdom (and formerly some commonwealth nations), sometimes referred to as the "Imperial Gallon" or the "U.S. Gallon" as used in the United States. The Metrication add-on attempts to resolve cultural ambiguity by detecting the language of the webpage in 3 ways: 1) the explicit language defined in the web page, for example "<html lang="en-GB">"; 2) the implied language derived from the domain name, for example "domain.co.uk"; and 3) the presence of English/US spelling variants such as "neighbour" and "neighbor" on the web page. As none of these methods are 100% reliable, the Metrication add-on will assume "U.S." variants where none of the above methods are definitive.
Ambiguity may also arise as the unit "ounce" may actually refer to the unit of mass or as shorthand for "fluid ounce" where context could be used to determine which one was meant. Consider the sentence "add 2 ounces of sugar to 20 ounces of lemon juice": from the context, a human reader would understand that as "lemon juice" is a liquid, "fluid ounces" is the most likely unit to apply. When encountering "ounces" the Metrication add-on will always convert based on mass, however, it will provide an alternate volume conversion in the popup. When encountering "fluid ounces", however, the Metrication add-on will always convert to volume only.
The Metrication add-on can also cater for what it refers to as "compound values". A "compound value" is a value such as "5 feet 11¾ inches" containing 2 sub-values of independent sub-units. Both feet and inches are valid individual units that could be converted to metres and centimetres independently, but would make little sense in a metric context. Instead, the above example is taken as a single value that is converted to "1.8 metres". The Metrication add-on will show its working as " (5 feet = 1.524 metres) + (11.75 inches = 0.29845 metres) = 1.82245 metres".
The Metrication add-on also caters for what it refers to as "compound units". A "compound unit" is a single value that references multiple sub-units, for example "21 miles per gallon". There is a single value "21" but the unit that it refers to is comprised of 2 sub-units, "miles" and "gallons". A simple conversion would yield a non-sensical phrase like "33.8 kilometres per gallon". The Metrication add on can recognise compound units and provide a more appropriate "11.2 litres/100 kilometres" as the output value.