[gtranslator] Show msg errors for every message



commit 4dacf7e6d0d8e7a7844c0b51bd23fa0c0b275bd1
Author: Daniel GarcĂ­a Moreno <dani danigm net>
Date:   Sat Sep 14 11:00:35 2019 +0200

    Show msg errors for every message
    
    This patch validates each message after editing and if it's invalid the
    error message is shown in the interface and the background color of the
    invalid msgs is red. This should help to identify errors on invalid po
    files.
    
    Fix https://gitlab.gnome.org/GNOME/gtranslator/issues/60

 src/gtr-message-table.c | 19 +++++++++++++++++--
 src/gtr-msg.c           | 11 +++++++++--
 src/gtr-tab.c           | 13 ++++++++++++-
 3 files changed, 38 insertions(+), 5 deletions(-)
---
diff --git a/src/gtr-message-table.c b/src/gtr-message-table.c
index 6e3e4a5a..86ad5c69 100644
--- a/src/gtr-message-table.c
+++ b/src/gtr-message-table.c
@@ -64,32 +64,47 @@ colorize_cell (GtkTreeViewColumn *tree_column,
                gpointer data)
 {
   GtrMsg *msg;
+  gchar *message_error = NULL;
 
-  GdkRGBA translated, fuzzy, untranslated;
+  GdkRGBA translated, fuzzy, untranslated, bg_color, fg_color;
   GtkStyleContext *style_context;
   style_context = gtk_widget_get_style_context (GTK_WIDGET (data));
   gtk_style_context_lookup_color (style_context, "theme_fg_color", &translated);
   gtk_style_context_lookup_color (style_context, "warning_color", &fuzzy);
   gtk_style_context_lookup_color (style_context, "error_color", &untranslated);
+  gtk_style_context_lookup_color (style_context, "theme_bg_color", &bg_color);
+  gtk_style_context_lookup_color (style_context, "theme_selected_fg_color", &fg_color);
 
   gtk_tree_model_get (tree_model, iter,
                       GTR_MESSAGE_TABLE_MODEL_POINTER_COLUMN, &msg,
                       -1);
 
-  if (gtr_msg_is_fuzzy (msg))
+  message_error = gtr_msg_check (msg);
+  if (message_error)
     {
+      g_free (message_error);
+      g_object_set (cell, "background-rgba", &untranslated, NULL);
+      g_object_set (cell, "foreground-rgba", &fg_color, NULL);
+      g_object_set (cell, "style", PANGO_STYLE_NORMAL, NULL);
+      g_object_set (cell, "weight", PANGO_WEIGHT_BOLD, NULL);
+    }
+  else if (gtr_msg_is_fuzzy (msg))
+    {
+      g_object_set (cell, "background-rgba", &bg_color, NULL);
       g_object_set (cell, "foreground-rgba", &fuzzy, NULL);
       g_object_set (cell, "style", PANGO_STYLE_ITALIC, NULL);
       g_object_set (cell, "weight", PANGO_WEIGHT_NORMAL, NULL);
     }
   else if (gtr_msg_is_translated (msg))
     {
+      g_object_set (cell, "background-rgba", &bg_color, NULL);
       g_object_set (cell, "foreground-rgba", &translated, NULL);
       g_object_set (cell, "style", PANGO_STYLE_NORMAL, NULL);
       g_object_set (cell, "weight", PANGO_WEIGHT_NORMAL, NULL);
     }
   else
     {
+      g_object_set (cell, "background-rgba", &bg_color, NULL);
       g_object_set (cell, "foreground-rgba", &untranslated, NULL);
       g_object_set (cell, "style", PANGO_STYLE_NORMAL, NULL);
       g_object_set (cell, "weight", PANGO_WEIGHT_BOLD, NULL);
diff --git a/src/gtr-msg.c b/src/gtr-msg.c
index 25841107..ad5f380c 100644
--- a/src/gtr-msg.c
+++ b/src/gtr-msg.c
@@ -591,6 +591,7 @@ on_gettext_po_xerror2 (gint severity,
 gchar *
 gtr_msg_check (GtrMsg * msg)
 {
+  gchar *error = NULL;
   GtrMsgPrivate *priv = gtr_msg_get_instance_private (msg);
   struct po_xerror_handler handler;
 
@@ -613,6 +614,12 @@ gtr_msg_check (GtrMsg * msg)
       message_error = NULL;
     }
 
-  /*Are there any other way to do this? */
-  return message_error;
+  if (message_error)
+    {
+      error = g_strdup (message_error);
+      g_free (message_error);
+    }
+  message_error = NULL;
+
+  return error;
 }
diff --git a/src/gtr-tab.c b/src/gtr-tab.c
index 2c823c19..94b65249 100644
--- a/src/gtr-tab.c
+++ b/src/gtr-tab.c
@@ -450,6 +450,7 @@ gtr_tab_show_message (GtrTab * tab, GtrMsg * msg)
   msgid = gtr_msg_get_msgid (msg);
   if (msgid)
     {
+      gchar *msg_error = gtr_msg_check (msg);
       buf = gtk_text_view_get_buffer (GTK_TEXT_VIEW (priv->text_msgid));
       gtk_source_buffer_begin_not_undoable_action (GTK_SOURCE_BUFFER (buf));
       gtk_text_buffer_set_text (buf, (gchar *) msgid, -1);
@@ -457,6 +458,10 @@ gtr_tab_show_message (GtrTab * tab, GtrMsg * msg)
 
       if (gtr_msg_is_fuzzy (msg))
         gtk_label_set_text (GTK_LABEL (priv->msgid_tags), _("fuzzy"));
+      if (msg_error) {
+        gtk_label_set_text (GTK_LABEL (priv->msgid_tags), msg_error);
+        g_free (msg_error);
+      }
     }
   msgid_plural = gtr_msg_get_msgid_plural (msg);
   if (!msgid_plural)
@@ -518,6 +523,7 @@ update_status (GtrTab * tab, GtrMsg * msg, gpointer useless)
   GtrPoState po_state;
   GtrTabPrivate *priv;
   gboolean fuzzy, translated;
+  gchar *msg_error = NULL;
 
   priv = gtr_tab_get_instance_private (tab);
 
@@ -571,7 +577,12 @@ update_status (GtrTab * tab, GtrMsg * msg, gpointer useless)
       g_signal_emit (G_OBJECT (tab), signals[MESSAGE_CHANGED], 0, msg);
     }
 
-  if (gtr_msg_is_fuzzy (msg))
+  msg_error = gtr_msg_check (msg);
+  if (msg_error) {
+    gtk_label_set_text (GTK_LABEL (priv->msgid_tags), msg_error);
+    g_free (msg_error);
+  }
+  else if (gtr_msg_is_fuzzy (msg))
     gtk_label_set_text (GTK_LABEL (priv->msgid_tags), _("fuzzy"));
   else
     gtk_label_set_text (GTK_LABEL (priv->msgid_tags), "");


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