X-Git-Url: http://git.maemo.org/git/?p=gonvert;a=blobdiff_plain;f=src%2Funit_data.py;h=649f52f2dedbc4cdca51bac344e5e47d658af97b;hp=a5ce83157e5f79deda1658581ac4c16e77d40113;hb=39a38e609c3a9509c05e195aef62e361299349d6;hpb=f2c6bb106a57a43861584b290a950194754e3d34 diff --git a/src/unit_data.py b/src/unit_data.py index a5ce831..649f52f 100644 --- a/src/unit_data.py +++ b/src/unit_data.py @@ -1,9 +1,14 @@ import math -import gettext import converters -_ = gettext.gettext +try: + raise ImportError() + import gettext +except ImportError: + _ = lambda x: x +else: + _ = gettext.gettext @@ -100,13 +105,13 @@ UNIT_DESCRIPTIONS = { _(u"Area"): { ".base_unit": _(u"square meter"), _(u"meter diameter circle"): - [(converters.f, ('pi*(x/2.0)**2', '2.0*(x/pi)**(0.5)')), "m dia.", _(u"Type the diameter of the circle in meters to find its area displayed in other fields.")], + [(converters.f, ('math.pi*(x/2.0)**2', '2.0*(x/math.pi)**(0.5)')), "m dia.", _(u"Type the diameter of the circle in meters to find its area displayed in other fields.")], _(u"centimeter diameter circle"): - [(converters.f, ('pi*(x/200.0)**2', '200.0*(x/pi)**(0.5)')), "cm dia.", _(u"Type the diameter of the circle in centimeters to find its area displayed in other fields.")], + [(converters.f, ('math.pi*(x/200.0)**2', '200.0*(x/math.pi)**(0.5)')), "cm dia.", _(u"Type the diameter of the circle in centimeters to find its area displayed in other fields.")], _(u"inch diameter circle"): - [(converters.f, ('pi*(((x*(25.4/1000))/2.0) )**2', '1000/25.4 * 2.0*(x/pi)**(0.5)')), "in dia.", _(u"Type the diameter of the circle in inches to find its area displayed in other fields.")], + [(converters.f, ('math.pi*(((x*(25.4/1000))/2.0) )**2', '1000/25.4 * 2.0*(x/math.pi)**(0.5)')), "in dia.", _(u"Type the diameter of the circle in inches to find its area displayed in other fields.")], _(u"foot diameter circle"): - [(converters.f, ('pi*(((x*((12*25.4)/1000))/2.0) )**2', '1000/(12*25.4) * 2.0*(x/pi)**(0.5)')), "ft dia.", _(u"Type the diameter of the circle in feet to find its area displayed in other fields.")], + [(converters.f, ('math.pi*(((x*((12*25.4)/1000))/2.0) )**2', '1000/(12*25.4) * 2.0*(x/math.pi)**(0.5)')), "ft dia.", _(u"Type the diameter of the circle in feet to find its area displayed in other fields.")], _(u"are"): [(converters.m, 100.0), '', _(u"The unit of superficial measure, being a square of which each side is ten meters in length; 100 square meters, or about 119.6 square yards.")], _(u"acre"): @@ -422,7 +427,7 @@ UNIT_DESCRIPTIONS = { [(converters.m, 1.0e-6), u"\xb5A", ''], _(u"nanoampere"): [(converters.m, 1.0e-9), "nA", ''], - _(u"picoampere"): + _(u"math.picoampere"): [(converters.m, 1.0e-12), "pA", ''], _(u"abampere"): [(converters.m, 10.0), "abA", _(u"The CGS electromagnetic unit of current.")], @@ -1968,6 +1973,8 @@ _(u"Electrical Voltage"): {".base_unit": _(u"volt"), [(converters.m, 10*10*1.0), "dl", ''], _(u"mil"): [(converters.m, 1.0), '', _(u"Equal to one thousandth of a liter syn: milliliter, millilitre, ml, cubic centimeter, cubic centimeter, cc")], + _(u"fluid dram"): + [(converters.m, 2*3*4.92892159375/8), '', _(u"Used in Pharmaceutical")], _(u"minim"): [(converters.m, 2*3*4.92892159375/480), '', _(u"Used in Pharmaceutical to represent one drop. 1/60 fluid dram or 1/480 fluid ounce. A U.S. minim is about 0.003760 in\xb3 or 61.610 \xb5l. The British minim is about 0.003612 in\xb3 or 59.194 \xb5l. Origin of the word is from the Latin minimus, or small.")], }, @@ -2184,14 +2191,40 @@ _(u"Electrical Voltage"): {".base_unit": _(u"volt"), _(u"pony"): [(converters.m, 25.0), "", """Equal to twenty five pounds sterling"""], }, + + _(u"Radioactivity"): { + ".base_unit": "becquerel", + _(u"becquerel"): + [(converters.m, 1.0), u"Bq", 'The SI derived unit of radioactivity.'], + _(u"curie"): + [(converters.m, 3.7e10), u"Ci", 'Roughly the activity of 1 gram of the radium isotope 226 Ra.'], + _(u"pico curie"): + [(converters.m, 3.7e-2), u"pCi", ''], + }, + + _(u"Radiation dose"): { + ".base_unit": "Sievert", + _(u"Sievert"): + [(converters.m, 1.0), u"Sv", ''], + _(u"milli Sievert"): + [(converters.m, 1.0e-3), u"mSv", ''], + _(u"micro Sievert"): + [(converters.m, 1.0e-6), u"\xb5Sv", ''], + _(u"rem"): + [(converters.m, 0.01), u"rem", ''], + _(u"milli rem"): + [(converters.m, 1.0e-5), u"mrem", ''], + _(u"roentgen"): + [(converters.m, 1/1.07185e2), u"R", ''], + }, } UNIT_CATEGORIES = sorted(UNIT_DESCRIPTIONS.iterkeys()) -def get_units(category): - units = sorted(UNIT_DESCRIPTIONS[category].iterkeys()) +def get_units(categoryName): + units = sorted(UNIT_DESCRIPTIONS[categoryName].iterkeys()) # do not display .base_unit description key del units[0] @@ -2199,6 +2232,23 @@ def get_units(category): return units +def get_units_from_category(category): + units = sorted(category.iterkeys()) + + # do not display .base_unit description key + del units[0] + + return units + + +def get_base_unit(categoryName): + return UNIT_DESCRIPTIONS[categoryName][".base_unit"] + + +def get_base_unit_from_category(category): + return category[".base_unit"] + + future_dic = { _(u"Wire Gauge"): { ".base_unit": "circular mils",