[gtranslator: 1/5] Fixing npluarals inconsistency issue between file and profile . Fixes #152
- From: Daniel Garcia Moreno <danigm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtranslator: 1/5] Fixing npluarals inconsistency issue between file and profile . Fixes #152
- Date: Thu, 2 Jun 2022 15:38:15 +0000 (UTC)
commit 91df49e00a5404a0c934a19a790112348ee5490b
Author: afshan ahmed khan <afshanahmeda2k gmail com>
Date: Fri Apr 22 19:28:32 2022 +0530
Fixing npluarals inconsistency issue between file and profile . Fixes #152
src/gtr-po.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++
src/gtr-po.h | 4 +++
src/gtr-profile-manager.c | 1 -
src/gtr-tab.c | 52 +++++++++++++++++++++++++++++++++-
4 files changed, 126 insertions(+), 2 deletions(-)
---
diff --git a/src/gtr-po.c b/src/gtr-po.c
index 506d2d76..0355c7ea 100644
--- a/src/gtr-po.c
+++ b/src/gtr-po.c
@@ -27,6 +27,7 @@
* Gediminas Paulauskas <menesis kabalak net>
*/
+#include "gtr-header.h"
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -38,6 +39,7 @@
#include "gtr-msg.h"
#include "gtr-enum-types.h"
#include "gtr-profile.h"
+#include "gtr-profile-manager.h"
#include "gtr-utils.h"
#include "gtr-message-container.h"
#include "gtr-preferences-dialog.h"
@@ -129,6 +131,14 @@ enum
PROP_STATE
};
+enum
+{
+ FILE_INCONSISTENT_WITH_PROFILE,
+ NO_OF_SIGNALS
+};
+
+guint signals[NO_OF_SIGNALS];
+
static gchar *message_error = NULL;
static void
@@ -331,6 +341,13 @@ gtr_po_class_init (GtrPoClass * klass)
GTR_TYPE_PO_STATE,
GTR_PO_STATE_SAVED,
G_PARAM_READABLE));
+ /* Signals */
+ signals[FILE_INCONSISTENT_WITH_PROFILE] =
+ g_signal_new ("file-is-inconsistent-with-profile",
+ G_OBJECT_CLASS_TYPE (klass),
+ G_SIGNAL_RUN_LAST,
+ 0,NULL,NULL,g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
}
/*
@@ -1401,6 +1418,54 @@ gtr_po_check_po_file (GtrPo * po)
return message_error;
}
+/**
+ * gtr_po_consistent_with_profile
+ * @po: a #GtrPo
+ *
+ * Tests whether the po file is consistent or not with profile values
+ * Returns: If the po file is not consistent with profile then it returns 0 .
+ **/
+int gtr_po_consistent_with_profile(GtrPo * po){
+ GtrPoPrivate *priv;
+ GtrProfileManager *prof_manager;
+ GtrProfile *profile;
+ gint po_header_nplurals;
+ gint profile_nplurals;
+
+ priv= gtr_po_get_instance_private(po);
+ po_message_iterator_t iter = po_message_iterator (priv->gettext_po_file, NULL);
+ GtrHeader *header = gtr_header_new (iter, po_next_message(iter));
+ po_header_nplurals = gtr_header_get_nplurals(header);
+
+ prof_manager = gtr_profile_manager_get_default ();
+ profile = gtr_profile_manager_get_active_profile (prof_manager);
+ gchar *pointer = g_strrstr (gtr_profile_get_plural_forms(profile), "nplurals");
+ if (pointer != NULL)
+ {
+ while (*pointer != '\0' && *pointer != '=')
+ pointer++;
+
+ if (*pointer != '\0')
+ {
+ pointer++;
+ while (*pointer != '\0' && *pointer == ' ')
+ pointer++;
+
+ if (*pointer == '\0')
+ return 0;
+ }
+ else
+ return 0;
+
+ profile_nplurals = g_ascii_digit_value (*pointer);
+ }
+
+ if (profile_nplurals == po_header_nplurals)
+ return 1;
+ else
+ return 0;
+}
+
const gchar *
gtr_po_get_dl_team (GtrPo *po)
{
@@ -1442,3 +1507,9 @@ gtr_po_can_dl_upload (GtrPo *po)
GtrPoPrivate *priv = gtr_po_get_instance_private (po);
return g_strcmp0 (priv->dl_state, "Translating") == 0;
}
+
+void
+gtr_po_emit_file_not_consistent (GtrPo *po)
+{
+ g_signal_emit (G_OBJECT(po), signals[FILE_INCONSISTENT_WITH_PROFILE], 0);
+}
diff --git a/src/gtr-po.h b/src/gtr-po.h
index 6d3089e1..27828561 100644
--- a/src/gtr-po.h
+++ b/src/gtr-po.h
@@ -152,7 +152,11 @@ gtr_po_get_message_position (GtrPo * po);
gchar *gtr_po_check_po_file (GtrPo * po);
+void
+gtr_po_emit_file_not_consistent (GtrPo * po);
+int
+gtr_po_consistent_with_profile (GtrPo * po);
/* Unexported funcs */
void
_gtr_po_increase_decrease_translated (GtrPo * po, gboolean increase);
diff --git a/src/gtr-profile-manager.c b/src/gtr-profile-manager.c
index 81eb1286..7c7b8399 100644
--- a/src/gtr-profile-manager.c
+++ b/src/gtr-profile-manager.c
@@ -382,7 +382,6 @@ gtr_profile_manager_set_active_profile (GtrProfileManager *manager,
priv->active_profile = profile;
g_signal_emit (G_OBJECT (manager), signals[ACTIVE_PROFILE_CHANGED], 0, profile);
-
save_profiles (manager);
}
diff --git a/src/gtr-tab.c b/src/gtr-tab.c
index 93b9059b..04543c1b 100644
--- a/src/gtr-tab.c
+++ b/src/gtr-tab.c
@@ -28,6 +28,7 @@
* Thomas Ziehmer <thomas kabalak net>
*/
+#include "gtr-profile.h"
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
@@ -48,6 +49,7 @@
#include "gtr-progress.h"
#include "gtr-actions.h"
#include "gtr-utils.h"
+#include "gtr-profile-manager.h"
#include <glib.h>
#include <glib-object.h>
@@ -261,6 +263,40 @@ show_hide_revealer (GtkWidget *widget, GdkEvent *ev, GtrTab *tab)
return TRUE;
}
+static void
+handle_file_is_inconsistent (GtrPo *po, GtrTab *tab)
+{
+ GtrTabPrivate *priv = gtr_tab_get_instance_private (tab);
+ GtrProfileManager *manager = gtr_profile_manager_get_default ();
+ GtrProfile *active_profile = gtr_profile_manager_get_active_profile (manager);
+ const gchar* profile_name = gtr_profile_get_name (active_profile);
+
+ gchar* info_msg_primary = g_strdup_printf ("File is not consistent with profile %s",profile_name);
+ gchar *filename = g_file_get_path (gtr_po_get_location (po));
+ gchar* info_msg_secondary = g_strdup_printf ("Kindly go to preferences and select a profile with
consistent nplurals values as this file %s",filename);
+ gtr_tab_set_info (tab, info_msg_primary, info_msg_secondary);
+
+ GtkWidget *nb = priv->trans_notebook;
+ gtk_widget_set_sensitive (nb, FALSE);
+}
+
+static void
+on_active_profile_changed (GtrProfileManager *manager, GtrProfile *profile, GtrTab *tab)
+{
+ GtrTabPrivate *priv = gtr_tab_get_instance_private (tab);
+ GtkWidget *nb = priv->trans_notebook;
+
+ GtrPo *po = priv->po;
+ if (!gtr_po_consistent_with_profile (po))
+ {
+ gtr_po_emit_file_not_consistent (po);
+ }
+ else
+ {
+ gtk_widget_set_sensitive (nb, TRUE);
+ }
+}
+
static void
install_autosave_timeout (GtrTab * tab)
{
@@ -688,7 +724,7 @@ update_status (GtrTab * tab, GtrMsg * msg, gpointer useless)
else
gtk_label_set_text (GTK_LABEL (priv->msgid_tags), "");
- /* We need to update the tab state too if is neccessary */
+ /* We need to update the tab state too if is necessary */
if (po_state != GTR_PO_STATE_MODIFIED)
gtr_po_set_state (priv->po, GTR_PO_STATE_MODIFIED);
}
@@ -1033,9 +1069,12 @@ gtr_tab_new (GtrPo * po,
{
GtrTab *tab;
GtrTabPrivate *priv;
+ GtrProfileManager *manager;
g_return_val_if_fail (po != NULL, NULL);
+ manager = gtr_profile_manager_get_default();
+
tab = g_object_new (GTR_TYPE_TAB, NULL);
priv = gtr_tab_get_instance_private (tab);
@@ -1052,6 +1091,12 @@ gtr_tab_new (GtrPo * po,
g_signal_connect (po, "notify::state",
G_CALLBACK (on_state_notify), tab);
+ g_signal_connect (po, "file-is-inconsistent-with-profile",
+ G_CALLBACK (handle_file_is_inconsistent), tab);
+
+ g_signal_connect (manager, "active-profile-changed",
+ G_CALLBACK (on_active_profile_changed), tab);
+
install_autosave_timeout_if_needed (tab);
/* Now we have to initialize the number of msgstr tabs */
@@ -1060,6 +1105,11 @@ gtr_tab_new (GtrPo * po,
gtr_message_table_populate (GTR_MESSAGE_TABLE (priv->message_table),
GTR_MESSAGE_CONTAINER (priv->po));
+ if (!gtr_po_consistent_with_profile (po))
+ {
+ gtr_po_emit_file_not_consistent (po);
+ }
+
gtk_widget_show (GTK_WIDGET (tab));
return tab;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]