|
|
| Line 1: |
Line 1: |
| -- TODO: Need to see what units are missing and add them
| |
|
| |
|
| local units_tbl = {}--[=[ { | | local units_tbl = mw.loadData('Module:Convert/data').all_units |
| -- No space before unit
| | function get_unit(_u) |
| arcminute = { abbr='′', link='minute of arc', nospace=true },
| | local c_unit = units_tbl[_u] |
| arcmin = { abbr='′', link='minute of arc', nospace=true },
| | if c_unit then |
| ["'"] = { abbr='′', link='minute of arc', nospace=true },
| | if c_unit.target then |
| ['′'] = { abbr='′', link='minute of arc', nospace=true },
| | c_unit = convert_data[c_unit.target] |
| arcsecond = { abbr='″', link='second of arc', nospace=true },
| | end |
| arcsec = { abbr='″', link='second of arc', nospace=true },
| | return {abbr=c_unit.symbol or _u, link=c_unit.link or c_unit.name1 or _u, symlink=c_unit.symlink} |
| ['"'] = { abbr='″', link='second of arc', nospace=true },
| | else |
| ['″'] = { abbr='″', link='second of arc', nospace=true },
| | return {abbr=u, link=u} |
| ['deg'] = { abbr='°', link='degree (angle)', nospace=true },
| | end |
| ['°'] = { abbr='°', link='degree (angle)', nospace=true },
| | end |
| percent = { abbr='%', link='percent', nospace=true },
| |
| ['per cent'] = { abbr='%', link='percent', nospace=true },
| |
| ['%'] = { abbr='%', link='percent', nospace=true },
| |
| permil = { abbr='‰', link='per mil', nospace=true },
| |
| permill = { abbr='‰', link='per mil', nospace=true },
| |
| permille = { abbr='‰', link='per mil', nospace=true },
| |
| ['per mil'] = { abbr='‰', link='per mil', nospace=true },
| |
| ['per mill'] = { abbr='‰', link='per mil', nospace=true },
| |
| ['per mille'] = { abbr='‰', link='per mil', nospace=true },
| |
| ['‰'] = { abbr='‰', link='per mil', nospace=true },
| |
| -- Space before unit
| |
| A = { abbr='A', link='ampere' },
| |
| aA = { abbr='aA', link='attoampere' },
| |
| AD = { abbr='AD', link='Anno Domini' },
| |
| aG = { abbr='aG', link='attogauss' },
| |
| ag = { abbr='ag', link='attogram' },
| |
| aHz = { abbr='aHz', link='attohertz' },
| |
| aK = { abbr='aK', link='attokelvin' },
| |
| am = { abbr='am', link='attometre' },
| |
| aT = { abbr='aT', link='attotesla' },
| |
| BC = { abbr='BC', link='Before Christ' },
| |
| BCE = { abbr='BCE', link='Before the Common Era' },
| |
| ['bit/s'] = { abbr='bit/s', link='bit per second' },
| |
| bps = { abbr='bit/s', link='bit per second' },
| |
| BP = { abbr='BP', link='Before present' },
| |
| bya = { abbr='bya', link='billion years ago' },
| |
| byr = { abbr='byr', link='billion years' },
| |
| C = { abbr='C', link='coulomb' },
| |
| c = { abbr='<i>c</i>', link='speed of light' },
| |
| cA = { abbr='cA', link='centiampere' },
| |
| CE = { abbr='CE', link='Common Era' },
| |
| cG = { abbr='cG', link='centigauss' },
| |
| cg = { abbr='cg', link='centigram' },
| |
| cHz = { abbr='cHz', link='centihertz' },
| |
| cK = { abbr='cK', link='centikelvin' },
| |
| ['cm-1'] = { abbr='cm<sup>−1</sup>', link='wavenumber' },
| |
| cT = { abbr='cT', link='centitesla' },
| |
| cV = { abbr='cV', link='volt' },
| |
| dA = { abbr='dA', link='ampere' },
| |
| daA = { abbr='daA', link='decaampere' },
| |
| daG = { abbr='daG', link='decagauss' },
| |
| dag = { abbr='dag', link='decagram' },
| |
| daHz = { abbr='daHz', link='decahertz' },
| |
| daK = { abbr='daK', link='decakelvin' },
| |
| daT = { abbr='daT', link='decatesla' },
| |
| daV = { abbr='daV', link='volt' },
| |
| degC = { abbr='°C', link='degree Celsius' },
| |
| degF = { abbr='°F', link='Fahrenheit' },
| |
| degR = { abbr='°R', link='Rankine scale' },
| |
| dG = { abbr='dG', link='decigauss' },
| |
| dg = { abbr='dg', link='decigram' },
| |
| dHz = { abbr='dHz', link='hertz' },
| |
| dK = { abbr='dK', link='decikelvin' },
| |
| dT = { abbr='dT', link='decitesla' },
| |
| dV = { abbr='dV', link='volt' },
| |
| e = { abbr='<i>e</i>', link='Elementary charge' },
| |
| EA = { abbr='EA', link='ampere' },
| |
| ['Earth mass'] = { abbr='<i>M</i><sub>⊕</sub>', link='Earth mass' },
| |
| ['Earth radius'] = { abbr='<i>R</i><sub>⊕</sub>', link='Earth radius' },
| |
| EG = { abbr='EG', link='exagauss' },
| |
| Eg = { abbr='Eg', link='exagram' },
| |
| EHz = { abbr='EHz', link='exahertz' },
| |
| EK = { abbr='EK', link='exakelvin' },
| |
| ET = { abbr='ET', link='exatesla' },
| |
| EV = { abbr='EV', link='volt' },
| |
| ['eV/c2'] = { abbr='eV/<i>c</i><sup>2</sup>', link='electronvolt#Mass' },
| |
| F = { abbr='F', link='farad' },
| |
| fA = { abbr='fA', link='femtoampere' },
| |
| ['fb-1'] = { abbr='fb<sup>−1</sup>', link='Barn (unit)' },
| |
| fG = { abbr='fG', link='femtogauss' },
| |
| fg = { abbr='fg', link='femtogram' },
| |
| fHz = { abbr='fHz', link='femtohertz' },
| |
| fK = { abbr='fK', link='femtokelvin' },
| |
| fT = { abbr='fT', link='femtotesla' },
| |
| fV = { abbr='fV', link='femtovolt' },
| |
| gal = { abbr='gal', link='gallon' },
| |
| ['g/cm3'] = { abbr='g/cm<sup>3</sup>', link='gram per cubic centimetre' },
| |
| ['g/l'] = { abbr='g/l', link='gram per litre' },
| |
| ['g/L'] = { abbr='g/L', link='gram per litre' },
| |
| ['g*mol-1'] = { abbr='g⋅mol<sup>−1</sup>', link='molar mass' },
| |
| ['g/mol'] = { abbr='g⋅mol<sup>−1</sup>', link='molar mass' },
| |
| GA = { abbr='GA', link='gigaampere' },
| |
| Ga = { abbr='Ga', link='gigaannum' },
| |
| ['Gbit/s'] = { abbr='Gbit/s', link='gigabit per second' },
| |
| ['GeV/c2'] = { abbr='GeV/<i>c</i><sup>2</sup>', link='electronvolt#Mass' },
| |
| GG = { abbr='GG', link='gigagauss' },
| |
| Gg = { abbr='Gg', link='gigagram' },
| |
| GHz = { abbr='GHz', link='gigahertz' },
| |
| ['GJ*mol-1'] = { abbr='GJ⋅mol<sup>−1</sup>', link='joule per mole' },
| |
| ['GJ/mol'] = { abbr='GJ/mol', link='joule per mole' },
| |
| GK = { abbr='GK', link='gigakelvin' },
| |
| GPa = { abbr='GPa', link='gigapascal' },
| |
| Gpc = { abbr='Gpc', link='megaparsec#Megaparsecs_and_gigaparsecs' },
| |
| ['Gpc2'] = { abbr='Gpc<sup>2</sup>', link='megaparsec#Megaparsecs_and_gigaparsecs' },
| |
| ['Gpc3'] = { abbr='Gpc<sup>3</sup>', link='megaparsec#Megaparsecs_and_gigaparsecs' },
| |
| GT = { abbr='GT', link='gigatesla' },
| |
| GV = { abbr='GV', link='gigavolt' },
| |
| Gyr = { abbr='Ga', link='gigaannum' },
| |
| H = { abbr='H', link='Henry (unit)' },
| |
| ['H*m-1'] = { abbr='H', link='Henry (unit)' },
| |
| hA = { abbr='hA', link='hectoampere' },
| |
| hG = { abbr='hG', link='hectogauss' },
| |
| hg = { abbr='hg', link='hectogram' },
| |
| hHz = { abbr='hHz', link='hectohertz' },
| |
| hK = { abbr='hK', link='hectokelvin' },
| |
| hT = { abbr='hT', link='hectotesla' },
| |
| hV = { abbr='hV', link='volt' }, | |
| Hz = { abbr='Hz', link='hertz' },
| |
| ['Jupiter mass'] = { abbr='<i>M</i><sub>J</sub>', link='Jupiter mass' },
| |
| ['Jupiter radius'] = { abbr='<i>R</i><sub>J</sub>', link='Jupiter radius' }, | |
| ['J/kg'] = { abbr='J/kg', link='joule' },
| |
| ['J*mol-1'] = { abbr='J⋅mol<sup>−1</sup>', link='joule per mole' },
| |
| ['J/mol'] = { abbr='J/mol', link='joule per mole' },
| |
| Js = { abbr='J⋅s', link='joule-second' },
| |
| ['J*s'] = { abbr='J⋅s', link='joule-second' },
| |
| kA = { abbr='kA', link='kiloampere' },
| |
| ka = { abbr='ka', link='kiloannum' },
| |
| ['kbit/s'] = { abbr='kbit/s', link='kilobit per second' },
| |
| ['keV/c2'] = { abbr='keV/<i>c</i><sup>2</sup>', link='electronvolt#Mass' },
| |
| kG = { abbr='kG', link='kilogauss' },
| |
| ['kg/cm3'] = { abbr='kg/cm<sup>3</sup>', link='density#Formula_and_common_units' },
| |
| ['kg/m3'] = { abbr='kg/m<sup>3</sup>', link='kilogram per cubic metre' },
| |
| ['kg/mol'] = { abbr='kg⋅mol<sup>−1</sup>', link='molar mass' },
| |
| kHz = { abbr='kHz', link='Kilohertz' },
| |
| kpc = { abbr='kpc', link='kiloparsec' },
| |
| ['kpc2'] = { abbr='kpc<sup>2</sup>', link='kiloparsec' },
| |
| ['kpc3'] = { abbr='kpc<sup>3</sup>', link='kiloparsec' },
| |
| ['kJ*mol-1'] = { abbr='kJ⋅mol<sup>−1</sup>', link='joule per mole' },
| |
| ['kJ/mol'] = { abbr='kJ/mol', link='joule per mole' },
| |
| kK = { abbr='kK', link='kilokelvin' },
| |
| KPa = { abbr='kPa', link='pascal (unit)' },
| |
| kT = { abbr='kT', link='kilotesla' },
| |
| kV = { abbr='kV', link='kilovolt' },
| |
| ['kW·h'] = { abbr='kW⋅h', link='kilowatt hour' },
| |
| ['kW.h'] = { abbr='kW⋅h', link='kilowatt hour' },
| |
| kWh = { abbr='kWh', link='kilowatt hour' }, | |
| kya = { abbr='kya', link='kyr' },
| |
| kyr = { abbr='kyr', link='kyr' },
| |
| lbf = { abbr='{{lbf}}', link='Pound (force)' },
| |
| lbm = { abbr='{{lbm}}', link='Pound (mass)' },
| |
| ly = { abbr='ly', link='light-year' },
| |
| ['L_solar'] = { abbr='<i>L</i><sub>☉</sub>', link='solar luminosity' },
| |
| ['m-3'] = { abbr='m<sup>−3</sup>', link='cubic metre' },
| |
| ['m-2'] = { abbr='m<sup>−2</sup>', link='square metre' },
| |
| ['m-1'] = { abbr='m<sup>−1</sup>', link='metre' },
| |
| m = { abbr='m', link='metre' },
| |
| ['m2'] = { abbr='m<sup>2</sup>', link='Square metre' },
| |
| ['m3'] = { abbr='m<sup>3</sup>', link='Cubic metre' },
| |
| metre = { abbr='m', link='metre' },
| |
| meter = { abbr='m', link='metre' },
| |
| ['m*s-1'] = { abbr='m⋅s<sup>−1</sup>', link='metre per second' },
| |
| ['m*s-2'] = { abbr='m⋅s<sup>−2</sup>', link='metre per second squared' },
| |
| ['M_Earth'] = { abbr='<i>M</i><sub>⊕</sub>', link='Earth mass' },
| |
| ['M_Jupiter'] = { abbr='<i>M</i><sub>J</sub>', link='Jupiter mass' },
| |
| ['M_Solar'] = { abbr='<i>M</i><sub>☉</sub>', link='solar mass' },
| |
| ['M_solar'] = { abbr='<i>M</i><sub>☉</sub>', link='solar mass' },
| |
| mA = { abbr='mA', link='milliampere' },
| |
| MA = { abbr='MA', link='megaampere' },
| |
| Ma = { abbr='Ma', link='megaannum' },
| |
| ['Mbit/s'] = { abbr='Mbit/s', link='megabit per second' },
| |
| mcg = { abbr='µg', link='microgram' },
| |
| ['mcg/dL'] = { abbr='µg/dL', link='gram per' },
| |
| ['mcg/dl'] = { abbr='µg/dl', link='gram per' },
| |
| ['MeV/c2'] = { abbr='MeV/<i>c</i><sup>2</sup>', link='electronvolt#Mass' },
| |
| MG = { abbr='MG', link='megagauss' },
| |
| Mg = { abbr='Mg', link='megagram' },
| |
| mG = { abbr='mG', link='milligauss' },
| |
| ['mg/mL'] = { abbr='mg/mL', link='gram per litre' },
| |
| ['mg/ml'] = { abbr='mg/mL', link='gram per litre' },
| |
| MHz = { abbr='MHz', link='megahertz' },
| |
| mHz = { abbr='mHz', link='hertz' },
| |
| ['MJ*mol-1'] = { abbr='MJ⋅mol<sup>−1</sup>', link='joule per mole' },
| |
| ['MJ/mol'] = { abbr='MJ/mol', link='joule per mole' },
| |
| MK = { abbr='MK', link='megakelvin' },
| |
| mK = { abbr='mK', link='millikelvin' },
| |
| Mpc = { abbr='Mpc', link='parsec#Megaparsecs_and_gigaparsecs' },
| |
| ['Mpc2'] = { abbr='Mpc<sup>2</sup>', link='parsec#Megaparsecs_and_gigaparsecs' },
| |
| ['Mpc3'] = { abbr='Mpc<sup>3</sup>', link='parsec#Megaparsecs_and_gigaparsecs' },
| |
| MT = { abbr='MT', link='megatesla' },
| |
| mT = { abbr='mT', link='millitesla' },
| |
| muA = { abbr='µA', link='ampere' },
| |
| muG = { abbr='µG', link='microgauss' },
| |
| mug = { abbr='µg', link='microgram' },
| |
| muGal = { abbr='µGal', link='Gal (unit)' },
| |
| muHz = { abbr='µHz', link='hertz' },
| |
| muJ = { abbr='µJ', link='joule' },
| |
| muK = { abbr='µK', link='microkelvin' },
| |
| mum = { abbr='µm', link='micrometre' },
| |
| mus = { abbr='µs', link='microsecond' },
| |
| muT = { abbr='µT', link='microtesla' },
| |
| muV = { abbr='µV', link='volt' },
| |
| MV = { abbr='MV', link='volt' },
| |
| mV = { abbr='mV', link='volt' },
| |
| mya = { abbr='mya', link='million years ago' },
| |
| myr = { abbr='myr', link='million years' },
| |
| nA = { abbr='nA', link='ampere' },
| |
| ['N*A-2'] = { abbr='N⋅A<sup>−2</sup>', link='permeability (electromagnetism)' },
| |
| nG = { abbr='nG', link='nanogauss' },
| |
| ng = { abbr='ng', link='nanogram' },
| |
| nHz = { abbr='nHz', link='hertz' },
| |
| nK = { abbr='nK', link='nanokelvin' },
| |
| ['N*m-1'] = { abbr='N⋅m<sup>−1</sup>', link='joule (unit)' },
| |
| nT = { abbr='nT', link='nanotesla' },
| |
| nV = { abbr='nV', link='volt' },
| |
| PA = { abbr='PA', link='ampere' },
| |
| pA = { abbr='pA', link='ampere' },
| |
| ['pc2'] = { abbr='pc<sup>2</sup>', link='Parsec' },
| |
| ['pc3'] = { abbr='pc<sup>3</sup>', link='Parsec' },
| |
| PG = { abbr='PG', link='petagauss' },
| |
| Pg = { abbr='Pg', link='petagram' },
| |
| pG = { abbr='pG', link='picogauss' },
| |
| pg = { abbr='pg', link='picogram' },
| |
| PHz = { abbr='PHz', link='petahertz' },
| |
| pHz = { abbr='pHz', link='hertz' },
| |
| PK = { abbr='PK', link='petakelvin' },
| |
| pK = { abbr='pK', link='picokelvin' },
| |
| ppb = { abbr='ppb', link='parts per billion' },
| |
| ppm = { abbr='ppm', link='parts per million' },
| |
| PT = { abbr='PT', link='petatesla' },
| |
| pT = { abbr='pT', link='picotesla' },
| |
| PV = { abbr='PV', link='volt' },
| |
| pV = { abbr='pV', link='volt' },
| |
| R = { abbr='R', link='rayleigh (unit)' },
| |
| ['R_Earth'] = { abbr='<i>R</i><sub>⊕</sub>', link='Earth radius' },
| |
| ['R_Jupiter'] = { abbr='<i>R</i><sub>J</sub>', link='Jupiter radius' },
| |
| ['R_Solar'] = { abbr='<i>R</i><sub>☉</sub>', link='solar radius' },
| |
| ['R_solar'] = { abbr='<i>R</i><sub>☉</sub>', link='solar radius' },
| |
| s = { abbr='s', link='second' },
| |
| second = { abbr='s', link='second' },
| |
| seconds = { abbr='s', link='second' },
| |
| ['s-1'] = { abbr='s<sup>−1</sup>', link='second' },
| |
| ['s-2'] = { abbr='s<sup>−2</sup>', link='second' },
| |
| ['s2'] = { abbr='s<sup>2</sup>', link='second' },
| |
| ['Solar luminosity'] = { abbr='<i>L</i><sub>☉</sub>', link='solar luminosity' },
| |
| ['solar luminosity'] = { abbr='<i>L</i><sub>☉</sub>', link='solar luminosity' },
| |
| ['Solar mass'] = { abbr='<i>M</i><sub>☉</sub>', link='solar mass' },
| |
| ['solar mass'] = { abbr='<i>M</i><sub>☉</sub>', link='solar mass' },
| |
| ['Solar radius'] = { abbr='<i>R</i><sub>☉</sub>', link='solar radius' },
| |
| ['solar radius'] = { abbr='<i>R</i><sub>☉</sub>', link='solar radius' },
| |
| TA = { abbr='TA', link='ampere' },
| |
| ['Tbit/s'] = { abbr='Tbit/s', link='terabit per second' },
| |
| ['TeV/c2'] = { abbr='TeV/<i>c</i><sup>2</sup>', link='electronvolt#Mass' },
| |
| TG = { abbr='TG', link='teragauss' },
| |
| Tg = { abbr='Tg', link='teragram' },
| |
| THz = { abbr='THz', link='terahertz' },
| |
| ['TJ*mol-1'] = { abbr='TJ⋅mol<sup>−1</sup>', link='joule per mole' },
| |
| ['TJ/mol'] = { abbr='TJ/mol', link='joule per mole' },
| |
| TK = { abbr='TK', link='terakelvin' },
| |
| Torr = { abbr='Torr', link='Torr' },
| |
| torr = { abbr='Torr', link='Torr' },
| |
| TT = { abbr='TT', link='teratesla' },
| |
| TV = { abbr='TV', link='volt' },
| |
| u = { abbr='u', link='atomic mass unit' },
| |
| uBP = { abbr='<sup>14</sup>C yr BP', link='Radiocarbon dating#Calibration' },
| |
| USgal = { abbr='US gal', link='US gallon' },
| |
| V = { abbr='V', link='volt' },
| |
| VV = { abbr='VV', link='volt' },
| |
| ['V/m'] = { abbr='V/m', link='electric field' },
| |
| ['Vm-1'] = { abbr='V⋅m<sup>−1</sup>', link='electric field' },
| |
| ['V*m-1'] = { abbr='V⋅m<sup>−1</sup>', link='electric field' },
| |
| W = { abbr='W', link='Watt' },
| |
| Wb = { abbr='Wb', link='Weber (unit)' },
| |
| y = { abbr='y', link='year' },
| |
| yA = { abbr='yA', link='ampere' },
| |
| YA = { abbr='YA', link='ampere' },
| |
| year = { abbr='year', link='year' },
| |
| years = { abbr='years', link='year' },
| |
| YG = { abbr='YG', link='yottagauss' },
| |
| Yg = { abbr='Yg', link='yottagram' },
| |
| yG = { abbr='yG', link='yoctogauss' },
| |
| yg = { abbr='yg', link='yoctogram' },
| |
| YHz = { abbr='YHz', link='yottahertz' },
| |
| yHz = { abbr='yHz', link='hertz' },
| |
| YK = { abbr='YK', link='yottakelvin' },
| |
| yK = { abbr='yK', link='yoctokelvin' },
| |
| ym = { abbr='ym', link='yoctometre' },
| |
| yr = { abbr='yr', link='year#Symbols_y_and_yr' },
| |
| YT = { abbr='YT', link='Yottatesla' },
| |
| yT = { abbr='yT', link='yoctotesla' },
| |
| YV = { abbr='YV', link='volt' },
| |
| yV = { abbr='yV', link='volt' },
| |
| ZA = { abbr='ZA', link='ampere' },
| |
| zA = { abbr='zA', link='ampere' },
| |
| ZG = { abbr='ZG', link='zettagauss' },
| |
| Zg = { abbr='Zg', link='zettagram' },
| |
| zG = { abbr='zG', link='zeptogauss' },
| |
| zg = { abbr='zg', link='zeptogram' },
| |
| ZHz = { abbr='ZHz', link='hertz' },
| |
| zHz = { abbr='zHz', link='hertz' },
| |
| ZK = { abbr='ZK', link='zettakelvin' },
| |
| zK = { abbr='zK', link='zeptokelvin' },
| |
| zm = { abbr='zm', link='zeptometre' },
| |
| ZT = { abbr='ZT', link='zettatesla' },
| |
| zT = { abbr='zT', link='zeptotesla' },
| |
| ZV = { abbr='ZV', link='volt' },
| |
| zV = { abbr='zV', link='volt' },
| |
| ['µA'] = { abbr='µA', link='microampere' },
| |
| ['µB'] = { abbr='µ<sub>B</sub>', link='Bohr magneton' },
| |
| ['µG'] = { abbr='µG', link='microgauss' },
| |
| ['µGal'] = { abbr='µGal', link='Gal (unit)' },
| |
| ['μg/dl'] = { abbr='μg/dL', link='gram per litre' },
| |
| ['μg/dL'] = { abbr='μg/dL', link='gram per litre' },
| |
| ['µHz'] = { abbr='µHz', link='hertz' },
| |
| ['µK'] = { abbr='µK', link='microkelvin' },
| |
| ['µN'] = { abbr='µ<sub>N</sub>', link='nuclear magneton' },
| |
| ['μN'] = { abbr='µ<sub>N</sub>', link='nuclear magneton' },
| |
| ['µT'] = { abbr='µT', link='microtesla' },
| |
| ['µV'] = { abbr='µV', link='microvolt' } | |
| }--]=]
| |
|
| |
|
| return function (u, tbl) | | return function (u, tbl) |
| Line 330: |
Line 20: |
| local link = tbl.link | | local link = tbl.link |
| local perl = tbl.per_link | | local perl = tbl.per_link |
|
| |
| function get_unit(_u)
| |
| if units_tbl[_u] then
| |
| return units_tbl[_u]
| |
| else
| |
| -- load convert module data
| |
| local convert_data = mw.loadData('Module:Convert/data').all_units
| |
| local c_unit = convert_data[_u]
| |
| if c_unit then
| |
| if c_unit.target then
| |
| c_unit = convert_data[c_unit.target]
| |
| end
| |
| return {abbr=c_unit.symbol or _u, link=c_unit.link or c_unit.name1 or _u, symlink=c_unit.symlink}
| |
| else
| |
| return {abbr=u, link=u}
| |
| end
| |
| end
| |
| end
| |
|
| |
|
| local unit = get_unit(u) | | local unit = get_unit(u) |