[json-glib] Mark GError messages for translations



commit 8863766ca4792383dad0e48550f8fb79d4c104e4
Author: Emmanuele Bassi <ebassi linux intel com>
Date:   Wed Jun 1 13:21:32 2011 +0100

    Mark GError messages for translations
    
    These errors might find their way into a UI.

 json-glib/json-gobject.c  |    4 ++--
 json-glib/json-gvariant.c |   40 ++++++++++++++++++----------------------
 json-glib/json-parser.c   |    5 ++++-
 json-glib/json-path.c     |   13 +++++++------
 json-glib/json-reader.c   |   20 ++++++++++----------
 5 files changed, 41 insertions(+), 41 deletions(-)
---
diff --git a/json-glib/json-gobject.c b/json-glib/json-gobject.c
index d6e0045..ccb3007 100644
--- a/json-glib/json-gobject.c
+++ b/json-glib/json-gobject.c
@@ -886,10 +886,10 @@ json_gobject_from_data (GType         gtype,
   root = json_parser_get_root (parser);
   if (root == NULL || JSON_NODE_TYPE (root) != JSON_NODE_OBJECT)
     {
+      /* translators: the %s is the name of the data structure */
       g_set_error (error, JSON_PARSER_ERROR,
                    JSON_PARSER_ERROR_PARSE,
-                   "Expecting a JSON object, but the root node "
-                   "is of type `%s'",
+                   _("Expecting a JSON object, but the root node is of type `%s'"),
                    json_node_type_name (root));
       g_object_unref (parser);
       return NULL;
diff --git a/json-glib/json-gvariant.c b/json-glib/json-gvariant.c
index 6eaaa78..c239457 100644
--- a/json-glib/json-gvariant.c
+++ b/json-glib/json-gvariant.c
@@ -532,10 +532,12 @@ json_node_assert_type (JsonNode       *json_node,
       (type == JSON_NODE_VALUE &&
        (json_node_get_value_type (json_node) != sub_type)))
     {
-      g_set_error_literal (error,
-                           G_IO_ERROR,
-                           G_IO_ERROR_INVALID_DATA,
-                           "Unexpected data-type in JSON node");
+      /* translators: the '%s' is the type name */
+      g_set_error (error,
+                   G_IO_ERROR,
+                   G_IO_ERROR_INVALID_DATA,
+                   _("Unexpected type '%s' in JSON node"),
+                   g_type_name (json_node_get_value_type (json_node)));
       return FALSE;
     }
   else
@@ -604,7 +606,7 @@ json_to_gvariant_tuple (JsonNode     *json_node,
           g_set_error_literal (error,
                                G_IO_ERROR,
                                G_IO_ERROR_INVALID_DATA,
-                               "Missing elements in JSON array to conform tuple");
+                               _("Missing elements in JSON array to conform to a tuple"));
           roll_back = TRUE;
           break;
         }
@@ -632,7 +634,7 @@ json_to_gvariant_tuple (JsonNode     *json_node,
           g_set_error_literal (error,
                                G_IO_ERROR,
                                G_IO_ERROR_INVALID_DATA,
-                               "Missing closing symbol ')' in GVariant tuple type");
+                               _("Missing closing symbol ')' in the GVariant tuple type"));
           roll_back = TRUE;
         }
       else if (json_array_get_length (array) >= i)
@@ -640,7 +642,7 @@ json_to_gvariant_tuple (JsonNode     *json_node,
           g_set_error_literal (error,
                                G_IO_ERROR,
                                G_IO_ERROR_INVALID_DATA,
-                               "Unexpected extra elements in JSON array");
+                               _("Unexpected extra elements in JSON array"));
           roll_back = TRUE;
         }
       else
@@ -919,7 +921,7 @@ gvariant_simple_from_string (const gchar    *st,
       g_set_error_literal (error,
                            G_IO_ERROR,
                            G_IO_ERROR_INVALID_DATA,
-                           "Invalid string value converting to GVariant");
+                           _("Invalid string value converting to GVariant"));
       if (variant != NULL)
         {
           g_variant_unref (variant);
@@ -975,7 +977,7 @@ json_to_gvariant_dict_entry (JsonNode     *json_node,
       g_set_error_literal (error,
                            G_IO_ERROR,
                            G_IO_ERROR_INVALID_DATA,
-                           "GVariant dictionary entry expects JSON object with exactly one member");
+                           _("A GVariant dictionary entry expects a JSON object with exactly one member"));
       return NULL;
     }
 
@@ -1194,17 +1196,11 @@ json_to_gvariant_recurse (JsonNode      *json_node,
       break;
 
     default:
-      {
-        gchar *err_msg;
-
-        err_msg = g_strdup_printf ("GVariant class '%c' not supported", class);
-        g_set_error_literal (error,
-                             G_IO_ERROR,
-                             G_IO_ERROR_INVALID_DATA,
-                             err_msg);
-        g_free (err_msg);
-        break;
-      }
+      g_set_error (error,
+                   G_IO_ERROR,
+                   G_IO_ERROR_INVALID_DATA,
+                   _("GVariant class '%c' not supported"), class);
+      break;
     }
 
 out:
@@ -1248,7 +1244,7 @@ json_gvariant_deserialize (JsonNode     *json_node,
       g_set_error_literal (error,
                            G_IO_ERROR,
                            G_IO_ERROR_INVALID_ARGUMENT,
-                           "Invalid GVariant type string");
+                           _("Invalid GVariant signature"));
       return NULL;
     }
 
@@ -1293,7 +1289,7 @@ json_gvariant_deserialize_data (const gchar  *json,
       g_set_error_literal (error,
                            G_IO_ERROR,
                            G_IO_ERROR_INVALID_DATA,
-                           "JSON data is empty");
+                           _("JSON data is empty"));
     }
   else
     {
diff --git a/json-glib/json-parser.c b/json-glib/json-parser.c
index 4a05d62..526e2de 100644
--- a/json-glib/json-parser.c
+++ b/json-glib/json-parser.c
@@ -810,9 +810,12 @@ json_scanner_msg_handler (JsonScanner *scanner,
     {
       GError *error = NULL;
 
+      /* translators: %s: is the file name, %d is the line number
+       * and %s is the error message
+       */
       g_set_error (&error, JSON_PARSER_ERROR,
                    priv->error_code,
-                   "%s:%d: Parse error: %s",
+                   _("%s:%d: Parse error: %s"),
                    priv->is_filename ? priv->filename : "<none>",
                    scanner->line,
                    message);
diff --git a/json-glib/json-path.c b/json-glib/json-path.c
index 4ed232f..4be1909 100644
--- a/json-glib/json-path.c
+++ b/json-glib/json-path.c
@@ -372,15 +372,16 @@ json_path_compile (JsonPath    *path,
               {
                 g_set_error_literal (error, JSON_PATH_ERROR,
                                      JSON_PATH_ERROR_INVALID_QUERY,
-                                     "Multiple roots");
+                                     _("Only one root node is allowed in a JSONPath expression"));
                 return FALSE;
               }
 
             if (!(*(p + 1) == '.' || *(p + 1) == '['))
               {
+                /* translators: the %c is the invalid character */
                 g_set_error (error, JSON_PATH_ERROR,
                              JSON_PATH_ERROR_INVALID_QUERY,
-                             "Root node followed by '%c'",
+                             _("Root node followed by invalid character '%c'"),
                              *(p + 1));
                 return FALSE;
               }
@@ -486,7 +487,7 @@ json_path_compile (JsonPath    *path,
                           {
                             g_set_error (error, JSON_PATH_ERROR,
                                          JSON_PATH_ERROR_INVALID_QUERY,
-                                         "Malformed slice '%*s'",
+                                         _("Malformed slice expression '%*s'"),
                                          end_p - p,
                                          p + 1);
                             goto fail;
@@ -530,7 +531,7 @@ json_path_compile (JsonPath    *path,
                             g_array_unref (indices);
                             g_set_error (error, JSON_PATH_ERROR,
                                          JSON_PATH_ERROR_INVALID_QUERY,
-                                         "Invalid set definition '%*s'",
+                                         _("Invalid set definition '%*s'"),
                                          end_p - p,
                                          p + 1);
                             goto fail;
@@ -583,7 +584,7 @@ json_path_compile (JsonPath    *path,
                       {
                         g_set_error (error, JSON_PATH_ERROR,
                                      JSON_PATH_ERROR_INVALID_QUERY,
-                                     "Invalid slice definition '%*s'",
+                                     _("Invalid slice definition '%*s'"),
                                      end_p - p,
                                      p + 1);
                         goto fail;
@@ -611,7 +612,7 @@ json_path_compile (JsonPath    *path,
                   {
                     g_set_error (error, JSON_PATH_ERROR,
                                  JSON_PATH_ERROR_INVALID_QUERY,
-                                 "Invalid array index '%*s'",
+                                 _("Invalid array index definition '%*s'"),
                                  end_p - p,
                                  p + 1);
                     goto fail;
diff --git a/json-glib/json-reader.c b/json-glib/json-reader.c
index fd0a521..8da7e5e 100644
--- a/json-glib/json-reader.c
+++ b/json-glib/json-reader.c
@@ -460,8 +460,8 @@ json_reader_read_element (JsonReader *reader,
   if (!(JSON_NODE_HOLDS_ARRAY (priv->current_node) ||
         JSON_NODE_HOLDS_OBJECT (priv->current_node)))
     return json_reader_set_error (reader, JSON_READER_ERROR_NO_ARRAY,
-                                  "The current node is of type '%s', but "
-                                  "an array or an object was expected.",
+                                  _("The current node is of type '%s', but "
+                                    "an array or an object was expected."),
                                   json_node_type_name (priv->current_node));
 
   switch (json_node_get_node_type (priv->current_node))
@@ -472,8 +472,8 @@ json_reader_read_element (JsonReader *reader,
 
         if (index_ >= json_array_get_length (array))
           return json_reader_set_error (reader, JSON_READER_ERROR_INVALID_INDEX,
-                                        "The index '%d' is greater than the size "
-                                        "of the array at the current position.",
+                                        _("The index '%d' is greater than the size "
+                                          "of the array at the current position."),
                                         index_);
 
         priv->previous_node = priv->current_node;
@@ -489,8 +489,8 @@ json_reader_read_element (JsonReader *reader,
 
         if (index_ >= json_object_get_size (object))
           return json_reader_set_error (reader, JSON_READER_ERROR_INVALID_INDEX,
-                                        "The index '%d' is greater than the size "
-                                        "of the object at the current position.",
+                                        _("The index '%d' is greater than the size "
+                                          "of the object at the current position."),
                                         index_);
 
         priv->previous_node = priv->current_node;
@@ -634,15 +634,15 @@ json_reader_read_member (JsonReader  *reader,
 
   if (!JSON_NODE_HOLDS_OBJECT (priv->current_node))
     return json_reader_set_error (reader, JSON_READER_ERROR_NO_OBJECT,
-                                  "The current node is of type '%s', but "
-                                  "an object was expected.",
+                                  _("The current node is of type '%s', but "
+                                    "an object was expected."),
                                   json_node_type_name (priv->current_node));
 
   object = json_node_get_object (priv->current_node);
   if (!json_object_has_member (object, member_name))
     return json_reader_set_error (reader, JSON_READER_ERROR_INVALID_MEMBER,
-                                  "The member '%s' is not defined in the "
-                                  "object at the current position.",
+                                  _("The member '%s' is not defined in the "
+                                    "object at the current position."),
                                   member_name);
 
   g_free (priv->current_member);



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