[gcalctool] Mark all units as translatable



commit de6bf04d016ab01baf9fc612f965ad528816b0f3
Author: Robert Ancell <robert ancell canonical com>
Date:   Fri Jan 28 14:28:02 2011 +1000

    Mark all units as translatable

 po/POTFILES.in     |    8 +++-
 src/unit-manager.c |  151 ++++++++++++++++++++++++++++------------------------
 src/unit.c         |   19 +++----
 src/unit.h         |    2 +-
 4 files changed, 96 insertions(+), 84 deletions(-)
---
diff --git a/po/POTFILES.in b/po/POTFILES.in
index b51c0bd..8a957bb 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -9,20 +9,26 @@
 data/gcalctool.desktop.in
 data/org.gnome.gcalctool.gschema.xml.in
 src/currency.c
-src/currency.h
+src/currency-manager.c
 src/financial.c
 src/gcalccmd.c
 src/gcalctool.c
 src/math-buttons.c
 src/math-converter.c
 src/math-display.c
+src/math-enums.c
 src/math-equation.c
 src/math-preferences.c
+src/math-variable-popup.c
 src/math-variables.c
 src/math-window.c
 src/mp-binary.c
 src/mp.c
 src/mp-convert.c
 src/mp-equation.c
+src/mp-serializer.c
 src/mp-trigonometric.c
+src/unit.c
+src/unit-category.c
+src/unit-manager.c
 src/unittest.c
diff --git a/src/unit-manager.c b/src/unit-manager.c
index b8bcf09..31e1aaa 100644
--- a/src/unit-manager.c
+++ b/src/unit-manager.c
@@ -15,20 +15,71 @@ G_DEFINE_TYPE (UnitManager, unit_manager, G_TYPE_OBJECT);
 static UnitManager *default_unit_manager = NULL;
 
 
-static MPNumber *
-get_value(const gchar *value, MPNumber *t)
-{
-    mp_set_from_string(value, 10, t);
-    return t;
-}
-
-
 UnitManager *
 unit_manager_get_default(void)
 {
-    UnitCategory *category;
-    MPNumber t;
+    UnitCategory *category = NULL;
     const GList *iter;
+    int i;
+    const struct
+    {
+        gchar *category;
+        gchar *name;
+        gchar *display_name;
+        gchar *format;
+        gchar *value;
+        gchar *symbols;
+    } units[] =
+    {
+        {"angle",    "degree",              N_("Degrees"),           NC_("unit-format", "%s degrees"),  "0.002777778",       NC_("unit-symbols", "degree,degrees,deg")},
+        {NULL,       "radian",              N_("Radians"),           NC_("unit-format", "%s radians"),  "0.159154943",       NC_("unit-symbols", "radian,radians,rad")},
+        {NULL,       "gradian",             N_("Gradians"),          NC_("unit-format", "%s gradians"), "0.0025",            NC_("unit-symbols", "gradian,gradians,grad")},
+        {"length",   "parsec",              N_("Parsecs"),           NC_("unit-format", "%s pc"),       "30857000000000000", NC_("unit-symbols", "parsec,parsecs,pc")},
+        {NULL,       "lightyear",           N_("Light Years"),       NC_("unit-format", "%s ly"),       "9460730472580800",  NC_("unit-symbols", "lightyear,lightyears,ly")},
+        {NULL,       "astronomical-unit",   N_("Austronomical Units"), NC_("unit-format", "%s au"),     "149597870691",      NC_("unit-symbols", "au")},
+        {NULL,       "nautical-mile",       N_("Nautical Miles"),    NC_("unit-format", "%s nm"),       "1852000",           NC_("unit-symbols", "nm")},
+        {NULL,       "mile",                N_("Miles"),             NC_("unit-format", "%s mi"),       "1609.344",          NC_("unit-symbols", "mile,miles,mi")},
+        {NULL,       "kilometer",           N_("Kilometers"),        NC_("unit-format", "%s km"),       "1000",              NC_("unit-symbols", "kilometer,kilometers,km,kms")},
+        {NULL,       "cable",               N_("Cables"),            NC_("unit-format", "%s cb"),       "219.456",           NC_("unit-symbols", "cable,cables,cb")},
+        {NULL,       "fathom",              N_("Fathoms"),           NC_("unit-format", "%s ftm"),      "1.8288",            NC_("unit-symbols", "fathom,fathoms,ftm")},
+        {NULL,       "meter",               N_("Meters"),            NC_("unit-format", "%s m"),        "1",                 NC_("unit-symbols", "meter,meters,m")},
+        {NULL,       "yard",                N_("Yards"),             NC_("unit-format", "%s yd"),       "0.9144",            NC_("unit-symbols", "yard,yards,yd")},
+        {NULL,       "foot",                N_("Feet"),              NC_("unit-format", "%s ft"),       "0.3048",            NC_("unit-symbols", "foot,feet,ft")},
+        {NULL,       "inch",                N_("Inches"),            NC_("unit-format", "%s in"),       "0.0254",            NC_("unit-symbols", "inch,inches,in")},
+        {NULL,       "centimeter",          N_("Centimeters"),       NC_("unit-format", "%s cm"),       "0.01",              NC_("unit-symbols", "centimeter,centimeters,cm,cms")},
+        {NULL,       "millimeter",          N_("Millimeters"),       NC_("unit-format", "%s mm"),       "0.001",             NC_("unit-symbols", "millimeter,millimeters,mm")},
+        {NULL,       "micrometer",          N_("Micrometers"),       NC_("unit-format", "%s μm"),       "0.000001",          NC_("unit-symbols", "micrometer,micrometers,um")},
+        {NULL,       "nanometer",           N_("Nanometers"),        NC_("unit-format", "%s nm"),       "0.000000001",       NC_("unit-symbols", "nanometer,nanometers")},
+        {"area",     "hectare",             N_("Hectares"),          NC_("unit-format", "%s ha"),       "10000",             NC_("unit-symbols", "hectare,hectares,ha")},
+        {NULL,       "acre",                N_("Acres"),             NC_("unit-format", "%s acres"),    "4046.8564224",      NC_("unit-symbols", "acre,acres")},
+        {NULL,       "square-meter",        N_("Square Meter"),      NC_("unit-format", "%s m²"),       "1",                 NC_("unit-symbols", "m²")},
+        {NULL,       "square-centimeter",   N_("Square Centimeter"), NC_("unit-format", "%s cm²"),      "0.001",             NC_("unit-symbols", "cm²")},
+        {NULL,       "square-millimeter",   N_("Square Millimeter"), NC_("unit-format", "%s mm²"),      "0.000001",          NC_("unit-symbols", "mm²")},
+        {"volume",   "cubic-meter",         N_("Cubic Meters"),      NC_("unit-format", "%s m³"),       "1000",              NC_("unit-symbols", "m³")},
+        {NULL,       "gallon",              N_("Gallons"),           NC_("unit-format", "%s gal"),      "3.785412",          NC_("unit-symbols", "gallon,gallons,gal")},
+        {NULL,       "litre",               N_("Litres"),            NC_("unit-format", "%s L"),        "1",                 NC_("unit-symbols", "litre,litres,liter,liters,L")},
+        {NULL,       "quart",               N_("Quarts"),            NC_("unit-format", "%s qt"),       "0.9463529",         NC_("unit-symbols", "quart,quarts,qt")},
+        {NULL,       "pint",                N_("Pints"),             NC_("unit-format", "%s pt"),       "0.4731765",         NC_("unit-symbols", "pint,pints,pt")},
+        {NULL,       "millilitre",          N_("Millilitres"),       NC_("unit-format", "%s mL"),       "0.001",             NC_("unit-symbols", "millilitre,millilitres,milliliter,milliliters,mL,cm³")},
+        {NULL,       "microlitre",          N_("Microlitre"),        NC_("unit-format", "%s μL"),       "0.000001",          NC_("unit-symbols", "mm³,μL,uL")},
+        {"weight",   "tonne",               N_("Tonnes"),            NC_("unit-format", "%s T"),        "1000",              NC_("unit-symbols", "tonne,tonnes")},
+        {NULL,       "kilograms",           N_("Kilograms"),         NC_("unit-format", "%s kg"),       "1s",                NC_("unit-symbols", "kilogram,kilograms,kilogramme,kilogrammes,kg,kgs")},
+        {NULL,       "pound",               N_("Pounds"),            NC_("unit-format", "%s lb"),       "0.45359237",        NC_("unit-symbols", "pound,pounds,lb")},
+        {NULL,       "ounce",               N_("Ounces"),            NC_("unit-format", "%s oz"),       "0.02834952",        NC_("unit-symbols", "ounce,ounces,oz")},
+        {NULL,       "gram",                N_("Grams"),             NC_("unit-format", "%s g"),        "0.001",             NC_("unit-symbols", "gram,grams,gramme,grammes,g")},
+        {"duration", "year",                N_("Years"),             NC_("unit-format", "%s years"),    "31557600",          NC_("unit-symbols", "year,years")},
+        {NULL,       "day",                 N_("Days"),              NC_("unit-format", "%s days"),     "86400",             NC_("unit-symbols", "day,days")},
+        {NULL,       "hour",                N_("Hours"),             NC_("unit-format", "%s hours"),    "3600",              NC_("unit-symbols", "hour,hours")},
+        {NULL,       "minute",              N_("Minutes"),           NC_("unit-format", "%s minutes"),  "60",                NC_("unit-symbols", "minute,minutes")},
+        {NULL,       "second",              N_("Seconds"),           NC_("unit-format", "%s s"),        "1",                 NC_("unit-symbols", "second,seconds,s")},
+        {NULL,       "millisecond",         N_("Milliseconds"),      NC_("unit-format", "%s ms"),       "0.001",             NC_("unit-symbols", "millisecond,milliseconds,ms")},
+        {NULL,       "microsecond",         N_("Microseconds"),      NC_("unit-format", "%s μs"),       "0.000001",          NC_("unit-symbols", "microsecond,microseconds,us")},
+        // FIXME: Need offset
+        //{"temperature", "degree-celcius",   N_("Celcius"),           NC_("unit-format", "%sË?C"),        "1",                 "Ë?C"},
+        //{NULL,          "degree-farenheit", N_("Farenheit"),         NC_("unit-format", "%sË?F"),        "",                  "Ë?F"},
+        //{NULL,          "degree-kelvin",    N_("Kelvin"),            NC_("unit-format", "%sË?K"),        "",                  "Ë?K"},
+        { NULL, NULL, NULL, NULL, NULL, NULL }
+    };
 
     if (default_unit_manager)
         return default_unit_manager;
@@ -36,66 +87,26 @@ unit_manager_get_default(void)
     default_unit_manager = g_object_new(unit_manager_get_type(), NULL);
 
     /* FIXME: Approximations of 1/(units in a circle), therefore, 360 deg != 400 grads */
-    category = unit_manager_add_category(default_unit_manager, "angle", _("Angle"));
-    unit_category_add_unit(category, unit_new("degree", _("Degrees"), "%s degrees", get_value("0.002777778", &t), "degrees", "degree", "deg", NULL));
-    unit_category_add_unit(category, unit_new("radian", _("Radians"), "%s radians", get_value("0.159154943", &t), "radians", "radian", "rad", NULL));
-    unit_category_add_unit(category, unit_new("gradian", _("Gradians"), "%s gradians", get_value("0.0025", &t), "gradians", "gradian", "grad", NULL));
-
-    category = unit_manager_add_category(default_unit_manager, "length", _("Length"));
-    unit_category_add_unit(category, unit_new("parsec", _("Parsecs"), "%s pc", get_value("30857000000000000", &t), "parsecs", "parsec", "pc", NULL));
-    unit_category_add_unit(category, unit_new("lightyear", _("Light Years"), "%s ly", get_value("9460730472580800", &t), "lightyears", "lightyear", "ly", NULL));
-    unit_category_add_unit(category, unit_new("astronomical-unit", _("Austronomical Units"), "%s au", get_value("149597870691", &t), "au", NULL));
-    unit_category_add_unit(category, unit_new("nautical-mile", _("Nautical Miles"), "%s nm", get_value("1852000", &t), "nm", NULL));
-    unit_category_add_unit(category, unit_new("mile", _("Miles"), "%s mi", get_value("1609.344", &t), "miles", "mile", "mi", NULL));
-    unit_category_add_unit(category, unit_new("kilometer", _("Kilometers"), "%s km", get_value("1000", &t), "kilometers", "kilometer", "km", "kms", NULL));
-    unit_category_add_unit(category, unit_new("cable", _("Cables"), "%s cable", get_value("219.456", &t), "cables", "cable", "cb", NULL));
-    unit_category_add_unit(category, unit_new("fathom", _("Fathoms"), "%s ftm", get_value("1.8288", &t), "fathoms", "fathom", "ftm", NULL));
-    unit_category_add_unit(category, unit_new("meter", _("Meters"), "%s m", get_value("1", &t), "meters", "meter", "m", NULL));
-    unit_category_add_unit(category, unit_new("yard", _("Yards"), "%s yd", get_value("0.9144", &t), "yards", "yard", "yd", NULL));
-    unit_category_add_unit(category, unit_new("foot", _("Feet"), "%s ft", get_value("0.3048", &t), "feet", "foot", "ft", NULL));
-    unit_category_add_unit(category, unit_new("inch", _("Inches"), "%s in", get_value("0.0254", &t), "inches", "inch", "in", NULL));
-    unit_category_add_unit(category, unit_new("centimeter", _("Centimeters"), "%s cm", get_value("0.01", &t), "centimeters", "centimeter", "cm", "cms", NULL));
-    unit_category_add_unit(category, unit_new("millimeter", _("Millimeters"), "%s mm", get_value("0.001", &t), "millimeters", "millimeter", "mm", NULL));
-    unit_category_add_unit(category, unit_new("micrometer", _("Micrometers"), "%s μm", get_value("0.000001", &t), "micrometers", "micrometer", "um", NULL));
-    unit_category_add_unit(category, unit_new("nanometer", _("Nanometers"), "%s nm", get_value("0.000000001", &t), "nanometers", "nanometer", NULL));
-
-    category = unit_manager_add_category(default_unit_manager, "area", _("Area"));
-    unit_category_add_unit(category, unit_new("hectare", _("Hectares"), "%s ha", get_value("10000", &t), "hectares", "hectare", "ha", NULL));
-    unit_category_add_unit(category, unit_new("acre", _("Acres"), "%s acres", get_value("4046.8564224", &t), "acres", "acre", NULL));
-    unit_category_add_unit(category, unit_new("square-meter", _("Square Meter"), "%s m²", get_value("1", &t), "m²", NULL));
-    unit_category_add_unit(category, unit_new("square-centimeter", _("Square Centimeter"), "%s cm²", get_value("0.001", &t), "cm²", NULL));
-    unit_category_add_unit(category, unit_new("square-millimeter", _("Square Millimeter"), "%s mm²", get_value("0.000001", &t), "mm²", NULL));
-
-    category = unit_manager_add_category(default_unit_manager, "volume", _("Volume"));
-    unit_category_add_unit(category, unit_new("cubic-meter", _("Cubic Meters"), "%s m³", get_value("1000", &t), "m³", NULL));
-    unit_category_add_unit(category, unit_new("gallon", _("Gallons"), "%s gallons", get_value("3.785412", &t), "gallons", "gallon", "gal", NULL));
-    unit_category_add_unit(category, unit_new("litre", _("Litres"), "%s L", get_value("1", &t), "litres", "litre", "liter", "liters", "L", NULL));
-    unit_category_add_unit(category, unit_new("quart", _("Quarts"), "%s quarts", get_value("0.9463529", &t), "quarts", "quart", "qt", NULL));
-    unit_category_add_unit(category, unit_new("pint", _("Pints"), "%s pt", get_value("0.4731765", &t), "pints", "pint", "pt", NULL));
-    unit_category_add_unit(category, unit_new("millilitre", _("Millilitres"), "%s mL", get_value("0.001", &t), "millilitres", "millilitre", "milliliter", "milliliters", "mL", "cm³", NULL));
-    unit_category_add_unit(category, unit_new("microlitre", _("Microlitre"), "%s μL", get_value("0.000001", &t), "", "mm³", "μL", "uL", NULL));
-
-    category = unit_manager_add_category(default_unit_manager, "weight", _("Weight"));
-    unit_category_add_unit(category, unit_new("tonne", _("Tonnes"), "%s T", get_value("1000", &t), "tonnes", "tonne", NULL));
-    unit_category_add_unit(category, unit_new("kilograms", _("Kilograms"), "%s kg", get_value("1s", &t), "kilogram", "kilogramme", "kilogrammes", "kg", "kgs", NULL));
-    unit_category_add_unit(category, unit_new("pound", _("Pounds"), "%s lb", get_value("0.45359237", &t), "pounds", "pound", "lb", NULL));
-    unit_category_add_unit(category, unit_new("ounce", _("Ounces"), "%s oz", get_value("0.02834952", &t), "ounces", "ounce", "oz", NULL));
-    unit_category_add_unit(category, unit_new("gram", _("Grams"), "%s g", get_value("0.001", &t), "grams", "gram", "gramme", "grammes", "g", NULL));
-
-    category = unit_manager_add_category(default_unit_manager, "duration", _("Duration"));
-    unit_category_add_unit(category, unit_new("year", _("Years"), "%s years", get_value("31557600", &t), "years", "year", NULL));
-    unit_category_add_unit(category, unit_new("day", _("Days"), "%s days", get_value("86400", &t), "days", "day", NULL));
-    unit_category_add_unit(category, unit_new("hour", _("Hours"), "%s hours", get_value("3600", &t), "hours", "hour", NULL));
-    unit_category_add_unit(category, unit_new("minute", _("Minutes"), "%s minutes", get_value("60", &t), "minutes", "minute", NULL));
-    unit_category_add_unit(category, unit_new("second", _("Seconds"), "%s s", get_value("1", &t), "seconds", "second", "s", NULL));
-    unit_category_add_unit(category, unit_new("millisecond", _("Milliseconds"), "%s milliseconds", get_value("0.001", &t), "milliseconds", "millisecond", "ms", NULL));
-    unit_category_add_unit(category, unit_new("microsecond", _("Microseconds"), "%s microseconds", get_value("0.000001", &t), "microseconds", "microsecond", "us", NULL));
-
+    unit_manager_add_category(default_unit_manager, "angle",    _("Angle"));
+    unit_manager_add_category(default_unit_manager, "length",   _("Length"));
+    unit_manager_add_category(default_unit_manager, "area",     _("Area"));
+    unit_manager_add_category(default_unit_manager, "volume",   _("Volume"));
+    unit_manager_add_category(default_unit_manager, "weight",   _("Weight"));
+    unit_manager_add_category(default_unit_manager, "duration", _("Duration"));
     // FIXME: Need offset
-    //category = unit_manager_add_category(default_unit_manager, "temperature", _("Temperature"));
-    //unit_category_add_unit(category, unit_new("degree-celcius", _("Celcius"), "%sË?C", get_value("1", &t), "Ë?C", NULL));
-    //unit_category_add_unit(category, unit_new("degree-farenheit", _("Farenheit"), "%sË?F", get_value("", &t), "Ë?F", NULL));
-    //unit_category_add_unit(category, unit_new("degree-kelvin", _("Kelvin"), "%s days", get_value("86400", &t), "days", "day", NULL));
+    //unit_manager_add_category(default_unit_manager, "temperature", _("Temperature"));
+
+    for (i = 0; units[i].name; i++) {
+        MPNumber t;
+        if (units[i].category)
+            category = unit_manager_get_category(default_unit_manager, units[i].category);
+        mp_set_from_string(units[i].value, 10, &t);
+        unit_category_add_unit(category, unit_new(units[i].name,
+                                                  _(units[i].display_name),
+                                                  g_dpgettext2(NULL, "unit-format", units[i].format),
+                                                  &t,
+                                                  g_dpgettext2(NULL, "unit-symbols", units[i].symbols)));
+    }
 
     category = unit_manager_add_category(default_unit_manager, "currency", _("Currency"));
     for (iter = currency_manager_get_currencies(currency_manager_get_default()); iter; iter = iter->next)
@@ -105,7 +116,7 @@ unit_manager_get_default(void)
         Unit *unit;
 
         format = g_strdup_printf("%s%%s", currency_get_symbol(currency));
-        unit = unit_new(currency_get_name(currency), currency_get_name(currency), format, NULL, currency_get_name(currency), NULL);
+        unit = unit_new(currency_get_name(currency), currency_get_name(currency), format, NULL, currency_get_name(currency));
         g_free(format);
 
         unit_category_add_unit(category, unit);
diff --git a/src/unit.c b/src/unit.c
index 762b572..319b7ae 100644
--- a/src/unit.c
+++ b/src/unit.c
@@ -1,5 +1,4 @@
 #include <string.h>
-#include <stdarg.h>
 
 #include "unit.h"
 #include "mp-serializer.h"
@@ -20,10 +19,11 @@ G_DEFINE_TYPE (Unit, unit, G_TYPE_OBJECT);
 
 
 Unit *
-unit_new(const gchar *name, const gchar *display_name, const gchar *format, MPNumber *value, const gchar *symbol, ...)
+unit_new(const gchar *name, const gchar *display_name, const gchar *format, MPNumber *value, const gchar *symbols)
 {
     Unit *unit = g_object_new(unit_get_type(), NULL);
-    va_list ap;
+    gchar **symbol_names;
+    int i;
 
     unit->priv->name = g_strdup(name);
     unit->priv->display_name = g_strdup(display_name);
@@ -36,15 +36,10 @@ unit_new(const gchar *name, const gchar *display_name, const gchar *format, MPNu
     else
         unit->priv->has_value = FALSE;
 
-    unit->priv->symbols = g_list_append(unit->priv->symbols, g_strdup(symbol));
-    va_start(ap, symbol);
-    while(TRUE) {
-        const gchar *s = va_arg(ap, char *);
-        if (s == NULL)
-            break;
-        unit->priv->symbols = g_list_append(unit->priv->symbols, g_strdup(s));        
-    }
-    va_end(ap);
+    symbol_names = g_strsplit(symbols, ",", 0);
+    for (i = 0; symbol_names[i]; i++)
+        unit->priv->symbols = g_list_append(unit->priv->symbols, g_strdup(symbol_names[i]));
+    g_free(symbol_names);
 
     return unit;
 }
diff --git a/src/unit.h b/src/unit.h
index b01bde0..eb646ed 100644
--- a/src/unit.h
+++ b/src/unit.h
@@ -23,7 +23,7 @@ typedef struct
 
 GType unit_get_type(void);
 
-Unit *unit_new(const gchar *name, const gchar *display_name, const gchar *format, MPNumber *value, const gchar *symbol, ...);
+Unit *unit_new(const gchar *name, const gchar *display_name, const gchar *format, MPNumber *value, const gchar *symbols);
 
 const gchar *unit_get_name(Unit *unit);
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]