[recipes] Make translated string apis explicit



commit 4a456d13765cb0c2913cd167d13055e27c313929
Author: Matthias Clasen <mclasen redhat com>
Date:   Mon Jan 2 06:15:21 2017 -0500

    Make translated string apis explicit
    
    I've decided that I don't like the 'just return translated strings'
    semantics, so add explicit getters for translations.

 src/gr-chef.c   |   11 +++++++++++
 src/gr-chef.h   |    2 ++
 src/gr-recipe.c |   46 ++++++++++++++++++++++------------------------
 src/gr-recipe.h |    4 ++++
 4 files changed, 39 insertions(+), 24 deletions(-)
---
diff --git a/src/gr-chef.c b/src/gr-chef.c
index 3206c2f..cb4c077 100644
--- a/src/gr-chef.c
+++ b/src/gr-chef.c
@@ -25,6 +25,7 @@
 #include <gtk/gtk.h>
 
 #include "gr-chef.h"
+#include "gr-utils.h"
 #include "types.h"
 
 
@@ -38,6 +39,8 @@ struct _GrChef
         char *description;
         char *image_path;
 
+        char *translated_description;
+
         gboolean readonly;
 };
 
@@ -133,6 +136,8 @@ gr_chef_set_property (GObject      *object,
         case PROP_DESCRIPTION:
                 g_free (self->description);
                 self->description = g_value_dup_string (value);
+                g_free (self->translated_description);
+                self->translated_description = translate_multiline_string (self->description);
                 break;
 
         case PROP_IMAGE_PATH:
@@ -231,6 +236,12 @@ gr_chef_get_description (GrChef *chef)
 }
 
 const char *
+gr_chef_get_translated_description (GrChef *chef)
+{
+        return chef->translated_description;
+}
+
+const char *
 gr_chef_get_image (GrChef *chef)
 {
         return chef->image_path;
diff --git a/src/gr-chef.h b/src/gr-chef.h
index e1288c7..4cc1563 100644
--- a/src/gr-chef.h
+++ b/src/gr-chef.h
@@ -36,4 +36,6 @@ const char      *gr_chef_get_description (GrChef *chef);
 const char      *gr_chef_get_image       (GrChef *chef);
 gboolean         gr_chef_is_readonly     (GrChef *chef);
 
+const char      *gr_chef_get_translated_description (GrChef *chef);
+
 G_END_DECLS
diff --git a/src/gr-recipe.c b/src/gr-recipe.c
index 8dd2aeb..7269c84 100644
--- a/src/gr-recipe.c
+++ b/src/gr-recipe.c
@@ -26,6 +26,7 @@
 
 #include "gr-recipe.h"
 #include "gr-images.h"
+#include "gr-utils.h"
 #include "types.h"
 
 struct _GrRecipe
@@ -237,27 +238,6 @@ 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,
@@ -288,7 +268,7 @@ gr_recipe_set_property (GObject      *object,
                 g_free (self->name);
                 g_free (self->cf_name);
                 self->name = g_value_dup_string (value);
-                self->translated_name = translate_string (self->name);
+                self->translated_name = translate_multiline_string (self->name);
                 self->cf_name = g_utf8_casefold (self->translated_name, -1);
                 update_mtime (self);
                 break;
@@ -297,7 +277,7 @@ gr_recipe_set_property (GObject      *object,
                 g_free (self->description);
                 g_free (self->cf_description);
                 self->description = g_value_dup_string (value);
-                self->translated_description = translate_string (self->description);
+                self->translated_description = translate_multiline_string (self->description);
                 self->cf_description = g_utf8_casefold (self->translated_description, -1);
                 update_mtime (self);
                 break;
@@ -365,7 +345,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);
+                self->translated_instructions = translate_multiline_string (self->instructions);
                 update_mtime (self);
                 break;
 
@@ -531,6 +511,12 @@ gr_recipe_get_id (GrRecipe *recipe)
 const char *
 gr_recipe_get_name (GrRecipe *recipe)
 {
+        return recipe->name;
+}
+
+const char *
+gr_recipe_get_translated_name (GrRecipe *recipe)
+{
         return recipe->translated_name;
 }
 
@@ -543,6 +529,12 @@ gr_recipe_get_author (GrRecipe *recipe)
 const char *
 gr_recipe_get_description (GrRecipe *recipe)
 {
+        return recipe->description;
+}
+
+const char *
+gr_recipe_get_translated_description (GrRecipe *recipe)
+{
         return recipe->translated_description;
 }
 
@@ -597,6 +589,12 @@ gr_recipe_get_ingredients (GrRecipe *recipe)
 const char *
 gr_recipe_get_instructions (GrRecipe *recipe)
 {
+        return recipe->instructions;
+}
+
+const char *
+gr_recipe_get_translated_instructions (GrRecipe *recipe)
+{
         return recipe->translated_instructions;
 }
 
diff --git a/src/gr-recipe.h b/src/gr-recipe.h
index b07d3d9..1c5a662 100644
--- a/src/gr-recipe.h
+++ b/src/gr-recipe.h
@@ -54,6 +54,10 @@ GDateTime      *gr_recipe_get_ctime        (GrRecipe   *recipe);
 GDateTime      *gr_recipe_get_mtime        (GrRecipe   *recipe);
 gboolean        gr_recipe_is_readonly      (GrRecipe   *recipe);
 
+const char     *gr_recipe_get_translated_name         (GrRecipe   *recipe);
+const char     *gr_recipe_get_translated_description  (GrRecipe   *recipe);
+const char     *gr_recipe_get_translated_instructions (GrRecipe   *recipe);
+
 gboolean        gr_recipe_matches          (GrRecipe    *recipe,
                                             const char **terms);
 


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