Metrication Browser Add-On

Convert and replace Imperial and US units of measure with metric (SI) units directly within a web page. The new metric values contain a hotspot that will popup with the original value, conversion workings and potential ambiguities .




Metrication is an add-on for Firefox that identifies Imperial/US units and converts them to appropriate metric units.

When an Imperial/US unit is identified, Metrication removes it totally from the document and replaces it with the appropriate metric value and unit so that the document reads as if it were 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 ""; 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" in 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.



The British unit of measurement plus modifications applied by the USA.


A "Unit" is an Imperial unit of measurement such as "foot", "pound", "gallon", etc. Each unit is normally associated with a numerical value describing the magnitude.


A "Value" is the quantity associated with a unit. Measurements are normally expressed as a value/unit pair. For example, with "20 Miles", "20" is the value and "Miles" is the unit.

Compound Unit

A "Compound Unit" is a unit of measure comprised of 2 or more sub-units. For example: "miles per gallon". Both "miles" and "gallons" are individual units and converting either of these individually would be non-sensical.

Compound Value

A "Compound Value" exists where 2 or more independent value/unit pairs are used to express a quantity. For example: "5 feet 7 inches" or "4 pounds 8 ounces". Instead of converting these individually, the individual conversion results are summed and presented as a single conversion.

Implied Units

An "Implied Unit" is a compound value where the name of one of the units (normally the last) is omitted because it can be implied from the name of the previous unit. For example: "5 feet 7" where the unit "inches" is implied for the value "7" because it immediately follows the unit "feet".

Range Value

"Range values" occur where a single unit is provided with two values separated by a range indicator. Examples of range values are as follows: "from 4 to 9 feet" and "between 7 and 8 miles".

List Value

List values are similar to range values, however, more than 2 values may be present and they can be separated by punctuation such as commas, semi colons, etc. For example: "The product is available in lengths of 10, 15, 20 & 50 feet".

Value Follows Unit

As well as writing "20 miles", it is also grammatically permissible to write "mile 20" under certain circumstances. For example: "We had 50 miles to cover today and we stopped at mile 30 for lunch". Where the singular form of the unit is used, in this case "mile" and the value is not 1, the output unit name will also use the singular form. For example: "We had 80.5 kilometres to cover today and we stopped at kilometre 48.3 for lunch".

Ambiguity / Variant

An "Ambiguity" occurs when the unit used may result in multiple conversion results. There are two types of ambiguity: 1) Ambiguities that arise from cultural difference (sometimes referred to as "variants"), for example "Imperial Gallon" and "US Gallon" both being referred to as "gallon"; and 2) Ambiguities that arise from context, for example "Add 2 ounces of sugar to 20 ounces of lemon juice" where "20 ounces" can be inferred by a human reader to mean "20 fluid ounces".

Conversion Rules JSON Documentation

'detection' Section

Entries in the detection section define the regular expression used to detect an imperial character string, what metric value to convert to and render as.


"input": "<regular expression>",
"convert": "conversion_rule",
"convertCompound": ["conversion_rule_1","conversion_rule_2"],
"variants": true,
"excludeAmbiguities": true,
"scaledBelow": null,
"render": "rendering_rule",
"compound": true,
"priority": 100,
"singularForm": "word",
"concatenateUnits": true,
"impliedFinalUnit": true,
"splitter": "splitting_rule",
"abbreviate": false

inputThis mandatory property contains the regular expression to be matched in order to detect that a conversion is required. For example, to match "20 miles" a grossly simplified regular expression could look something like "(\\d){1,}(\\s)*miles". Note, backslashes need to be 'escaped'.
convertThis mandatory property points to the conversion rule defined in the 'conversion' section.
convertCompoundThis optional property contains an array of conversion rules to be applied if the input values are 'compound values'.
variantsThis optional property indicates if variants (cultural ambiguities) should be used in the conversion process. For example, 'gallon' could mean 'imperial gallon' or 'US gallon', the 'convert' property will be prepended to the variant names to determine the final conversion rules to apply. The default value if this property if omitted is 'false'.
excludeAmbiguitiesThis optional property indicates if ambiguities defined in the 'conversion' section should be used in the conversion process. For example, 'ounce' could mean 'ounce' or 'fluid ounce' depending on the context. The default value if this property is omitted is 'false'.
scaleBelowThis mandatory property determines how scaling will be applied to the output value. If the input value is lower than the property value, then the output value will be scaled, however, if the input value is equal to or exceeds the property value, the unscaled output value will be used. This can be used where the convention is to use a smaller unit where a larger unit exists. For example, an altitude may be expressed as '35,000 feet' and should be converted to '10,668 metres' not '10.7 kilometres'.
renderThis mandatory property determines which rendering rule to use. Rendering rules control unit selection and scaling.
compoundThis mandatory property determines if the detected expression should be converted as a compound value. The default value if this property if omitted is 'false'.
priorityThis mandatory property determines which matched 'detection' rule should be processed when multiple rules are matched to the same text. For example, '20 Miles Per Gallon' will match both 'Miles' and 'Miles Per Gallon', however, if 'Miles Per Gallon' has a higher 'priority' then 'Miles' will be ignored.
singularFormThis optional property determines the singular form of a matched unit. This is used where 'unit before value' matches have been made. For example 'Mile 20'.
concatenateUnitsThis optional property determines if the output unit and value are replaced individually or as a single block of text.
impliedFinalUnitThis optional property determines if the final unit in a 'compound value' can be skipped. For example, '5 feet 7 inches' can be expressed as '5 feet 7' and the 'inches' implied.
splitterThis optional property determines which regular expression should be used to split values from units. If omitted, the 'default' splitter will be used.
abbreviateThis optional property determines if the output unit should be abbreviated. For example, 'm' instead of 'metres'.

'splitters' Section

Entries in the splitters section define the regular expressions used to separate the values from the units in a detected imperial phrase.


"string": "<regular expression>",
"unitAtFront": false

stringThis mandatory property contains the regular expression used to split values from units.
unitAtFrontThis mandatory property determines if the values follow the units or the units follow the value. For example "20 miles" amd "mile 20".
Metrication Webextension Workflow

Make a free website with Yola