[recipes] Return translated strings from recipe getters
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [recipes] Return translated strings from recipe getters
- Date: Sat, 31 Dec 2016 02:06:42 +0000 (UTC)
commit 684ed9d18a3b1925e8c0712b014ab42d55d12d6d
Author: Matthias Clasen <mclasen redhat com>
Date: Fri Dec 30 15:59:44 2016 -0500
Return translated strings from recipe getters
Note that this makes gr_recipe_get_description do something else
than g_object_get (..., "description", ...). Just something to
be aware of.
We are doing the same for name, description, instructions, cook
time and preparation time.
src/gr-recipe.c | 42 +++++++++++++++++++++++++++++++++++++-----
1 files changed, 37 insertions(+), 5 deletions(-)
---
diff --git a/src/gr-recipe.c b/src/gr-recipe.c
index bc3fab1..7346356 100644
--- a/src/gr-recipe.c
+++ b/src/gr-recipe.c
@@ -59,6 +59,10 @@ struct _GrRecipe
int spiciness;
gboolean readonly;
+
+ char *translated_name;
+ char *translated_description;
+ char *translated_instructions;
};
G_DEFINE_TYPE (GrRecipe, gr_recipe, G_TYPE_OBJECT)
@@ -112,6 +116,10 @@ gr_recipe_finalize (GObject *object)
g_date_time_unref (self->mtime);
g_date_time_unref (self->ctime);
+ g_free (self->translated_name);
+ g_free (self->translated_description);
+ g_free (self->translated_instructions);
+
G_OBJECT_CLASS (gr_recipe_parent_class)->finalize (object);
}
@@ -229,6 +237,27 @@ set_images (GrRecipe *self,
g_object_notify (G_OBJECT (self), "images");
}
+static char *
+translate_string (const char *s)
+{
+ g_auto(GStrv) strv = NULL;
+ int i;
+ GString *out;
+
+ out = g_string_new ("");
+
+ strv = g_strsplit (s, "\n", -1);
+
+ for (i = 0; strv[i]; i++) {
+ if (i > 0)
+ g_string_append (out, "\n");
+ if (strv[i][0] != 0)
+ g_string_append (out, _(strv[i]));
+ }
+
+ return g_string_free (out, FALSE);
+}
+
static void
gr_recipe_set_property (GObject *object,
guint prop_id,
@@ -260,6 +289,7 @@ gr_recipe_set_property (GObject *object,
g_free (self->cf_name);
self->name = g_value_dup_string (value);
self->cf_name = g_utf8_casefold (self->name, -1);
+ self->translated_name = translate_string (self->name);
update_mtime (self);
break;
@@ -268,6 +298,7 @@ gr_recipe_set_property (GObject *object,
g_free (self->cf_description);
self->description = g_value_dup_string (value);
self->cf_description = g_utf8_casefold (self->description, -1);
+ self->translated_description = translate_string (self->description);
update_mtime (self);
break;
@@ -334,6 +365,7 @@ gr_recipe_set_property (GObject *object,
case PROP_INSTRUCTIONS:
g_free (self->instructions);
self->instructions = g_value_dup_string (value);
+ self->translated_instructions = translate_string (self->instructions);
update_mtime (self);
break;
@@ -499,7 +531,7 @@ gr_recipe_get_id (GrRecipe *recipe)
const char *
gr_recipe_get_name (GrRecipe *recipe)
{
- return recipe->name;
+ return recipe->translated_name;
}
const char *
@@ -511,7 +543,7 @@ gr_recipe_get_author (GrRecipe *recipe)
const char *
gr_recipe_get_description (GrRecipe *recipe)
{
- return recipe->description;
+ return recipe->translated_description;
}
int
@@ -541,13 +573,13 @@ gr_recipe_get_category (GrRecipe *recipe)
const char *
gr_recipe_get_prep_time (GrRecipe *recipe)
{
- return recipe->prep_time;
+ return _(recipe->prep_time);
}
const char *
gr_recipe_get_cook_time (GrRecipe *recipe)
{
- return recipe->cook_time;
+ return _(recipe->cook_time);
}
GrDiets
@@ -565,7 +597,7 @@ gr_recipe_get_ingredients (GrRecipe *recipe)
const char *
gr_recipe_get_instructions (GrRecipe *recipe)
{
- return recipe->instructions;
+ return recipe->translated_instructions;
}
const char *
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]