[recipes] Add plural api for unit names
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [recipes] Add plural api for unit names
- Date: Tue, 20 Jun 2017 03:01:23 +0000 (UTC)
commit ac6a78fbaa83c701ea4e4c9da921d1ef39d3db24
Author: Paxana Amanda Xander <VeganBikePunk Gmail com>
Date: Mon Jun 19 14:59:42 2017 -0700
Add plural api for unit names
Add translatable plurals of the unit names.
Add a new getter: gr_unit_get_plural().
src/gr-unit.c | 58 ++++++++++++++++++++++++++++++++++++--------------------
src/gr-unit.h | 1 +
2 files changed, 38 insertions(+), 21 deletions(-)
---
diff --git a/src/gr-unit.c b/src/gr-unit.c
index 7adf0a0..2ceb41c 100644
--- a/src/gr-unit.c
+++ b/src/gr-unit.c
@@ -26,7 +26,7 @@
static const char * const unit_names[] = {
"g", "kg", "lb", "oz", "l", "dl", "ml", "fl oz", "pt", "qt", "gal", "cup",
- "tbsp", "tsp", "box", "pkg", "glass",
+ "tbsp", "tsp", "box", "pkg", "glass", "st", "pinch",
NULL
};
@@ -34,29 +34,35 @@ typedef struct {
const char *unit;
const char *abbreviation;
const char *display_name;
+ const char *plural;
} GrUnit;
static GrUnit units[] = {
- { "g", NC_("unit abbreviation", "g"), NC_("unit name", "gram") },
- { "kg", NC_("unit abbreviation", "kg"), NC_("unit name", "kilogram") },
- { "lb", NC_("unit abbreviation", "lb"), NC_("unit name", "pound") },
- { "oz", NC_("unit abbreviation", "oz"), NC_("unit name", "ounce") },
- { "l", NC_("unit abbreviation", "l"), NC_("unit name", "liter") },
- { "dl", NC_("unit abbreviation", "dl"), NC_("unit name", "deciliter") },
- { "ml", NC_("unit abbreviation", "ml"), NC_("unit name", "milliliter") },
- { "fl oz", NC_("unit abbreviation", "fl oz"), NC_("unit name", "fluid ounce") },
- { "pt", NC_("unit abbreviation", "pt"), NC_("unit name", "pint") },
- { "qt", NC_("unit abbreviation", "qt"), NC_("unit name", "quart") },
- { "gal", NC_("unit abbreviation", "gal"), NC_("unit name", "gallon") },
- { "cup", NC_("unit abbreviation", "cup"), NC_("unit name", "cup") },
- { "tbsp", NC_("unit abbreviation", "tbsp"), NC_("unit name", "tablespoon") },
- { "tsp", NC_("unit abbreviation", "tsp"), NC_("unit name", "teaspoon") },
- { "box", NC_("unit abbreviation", "box"), NC_("unit name", "box") },
- { "pkg", NC_("unit abbreviation", "pkg"), NC_("unit name", "package") },
- { "glass", NC_("unit abbreviation", "glass"), NC_("unit name", "glass") },
- { "mm", NC_("unit abbreviation", "mm"), NC_("unit name", "millimeter") },
- { "cm", NC_("unit abbreviation", "cm"), NC_("unit name", "centimeter") },
- { "m", NC_("unit abbreviation", "m"), NC_("unit name", "meter") },
+ { "g", NC_("unit abbreviation", "g"), NC_("unit name", "gram"), NC_("unit plural", "grams")
},
+ { "kg", NC_("unit abbreviation", "kg"), NC_("unit name", "kilogram"), NC_("unit plural",
"kilograms") },
+ { "lb", NC_("unit abbreviation", "lb"), NC_("unit name", "pound"), NC_("unit plural",
"pounds") },
+ { "oz", NC_("unit abbreviation", "oz"), NC_("unit name", "ounce"), NC_("unit plural",
"ounces") },
+ { "l", NC_("unit abbreviation", "l"), NC_("unit name", "liter"), NC_("unit plural",
"liters") },
+ { "dl", NC_("unit abbreviation", "dl"), NC_("unit name", "deciliter"), NC_("unit plural",
"deciliters") },
+ { "ml", NC_("unit abbreviation", "ml"), NC_("unit name", "milliliter"), NC_("unit plural",
"milliliters") },
+ { "fl oz", NC_("unit abbreviation", "fl oz"), NC_("unit name", "fluid ounce"), NC_("unit plural",
"fluid ounces") },
+ { "fl. oz.", NC_("unit abbreviation", "fl oz"), NC_("unit name", "fluid ounce"), NC_("unit plural",
"fluid ounces") },
+ { "pt", NC_("unit abbreviation", "pt"), NC_("unit name", "pint"), NC_("unit plural", "pints")
},
+ { "qt", NC_("unit abbreviation", "qt"), NC_("unit name", "quart"), NC_("unit plural",
"quarts") },
+ { "gal", NC_("unit abbreviation", "gal"), NC_("unit name", "gallon"), NC_("unit plural",
"gallons") },
+ { "cup", NC_("unit abbreviation", "cup"), NC_("unit name", "cup"), NC_("unit plural", "cups") },
+ { "tbsp", NC_("unit abbreviation", "tbsp"), NC_("unit name", "tablespoon"), NC_("unit plural",
"tablespoons") },
+ { "tsp", NC_("unit abbreviation", "tsp"), NC_("unit name", "teaspoon"), NC_("unit plural",
"teaspoons") },
+ { "box", NC_("unit abbreviation", "box"), NC_("unit name", "box"), NC_("unit plural", "boxes") },
+ { "pkg", NC_("unit abbreviation", "pkg"), NC_("unit name", "package"), NC_("unit plural",
"packages") },
+ { "glass", NC_("unit abbreviation", "glass"), NC_("unit name", "glass"), NC_("unit plural",
"glasses") },
+ { "mm", NC_("unit abbreviation", "mm"), NC_("unit name", "millimeter"), NC_("unit plural",
"millimeters") },
+ { "cm", NC_("unit abbreviation", "cm"), NC_("unit name", "centimeter"), NC_("unit plural",
"centimeters") },
+ { "m", NC_("unit abbreviation", "m"), NC_("unit name", "meter"), NC_("unit plural",
"meters") },
+ { "st", NC_("unit abbreviation", "st"), NC_("unit name", "stone"), NC_("unit plural",
"stone") },
+ { "pinch", NC_("unit abbreviation", "pinch"), NC_("unit name", "pinch"), NC_("unit plural",
"pinches") },
+ { "bunch", NC_("unit abbreviation", "bunch"), NC_("unit name", "bunch"), NC_("unit plural",
"bunches") },
+
};
const char **
@@ -86,6 +92,16 @@ gr_unit_get_display_name (const char *name)
}
const char *
+gr_unit_get_plural (const char *name)
+{
+ GrUnit *unit = find_unit (name);
+ if (unit)
+ return g_dpgettext2 (NULL, "unit plural", unit->plural);
+ return NULL;
+
+}
+
+const char *
gr_unit_get_abbreviation (const char *name)
{
GrUnit *unit = find_unit (name);
diff --git a/src/gr-unit.h b/src/gr-unit.h
index bc143eb..46d8278 100644
--- a/src/gr-unit.h
+++ b/src/gr-unit.h
@@ -28,5 +28,6 @@ const char *gr_unit_parse (char **string,
const char **gr_unit_get_names (void);
const char *gr_unit_get_abbreviation (const char *name);
const char *gr_unit_get_display_name (const char *name);
+const char *gr_unit_get_plural (const char *name);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]