[gtranslator: 5/5] Merge branch 'file-inconsistency-profile' into 'master'




commit 4e3d81a7140dc9b86742b7e0f4a3e9bd84ac7a14
Merge: 127ce168 a8a77afc
Author: Daniel Garcia Moreno <dani danigm net>
Date:   Thu Jun 2 15:38:14 2022 +0000

    Merge branch 'file-inconsistency-profile' into 'master'
    
    Fixing npluarals inconsistency issue between file and profile . Fixes #152
    
    Closes #152
    
    See merge request GNOME/gtranslator!120

 src/gtr-header.c          | 27 ++--------------
 src/gtr-po.c              | 52 ++++++++++++++++++++++++++++++
 src/gtr-po.h              |  4 +++
 src/gtr-profile-manager.c |  1 -
 src/gtr-tab.c             | 82 ++++++++++++++++++++++++++++++++++++++++++++++-
 src/gtr-utils.c           | 28 ++++++++++++++++
 src/gtr-utils.h           |  2 ++
 7 files changed, 169 insertions(+), 27 deletions(-)
---
diff --cc src/gtr-tab.c
index 988d342a,1547300c..69e27be7
--- a/src/gtr-tab.c
+++ b/src/gtr-tab.c
@@@ -262,15 -263,67 +264,76 @@@ show_hide_revealer (GtkWidget *widget, 
    return TRUE;
  }
  
 +static gboolean
 +msg_grab_focus (GtrTab *tab)
 +{
 +  GtrTabPrivate *priv;
 +  priv = gtr_tab_get_instance_private (tab);
 +  gtk_widget_grab_focus (priv->trans_msgstr[0]);
 +  return FALSE;
 +}
 +
+ 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 char *profile_name = gtr_profile_get_name (active_profile);
+   int profile_nplurals = -1;
+   int po_nplurals = -1;
+ 
+   g_autofree char *info_msg_primary = NULL;
+   g_autofree char *info_msg_secondary = NULL;
+   g_autofree char *filename = NULL;
+   g_autoptr (GFile) po_file = gtr_po_get_location (po);
+ 
+   filename = g_file_get_path (po_file);
+   po_nplurals = gtr_header_get_nplurals (gtr_po_get_header (po));
+   profile_nplurals = parse_nplurals_header (gtr_profile_get_plural_forms (active_profile));
+ 
+   info_msg_primary = g_strdup_printf ("File is not consistent with profile %s", profile_name);
+   info_msg_secondary = g_strdup_printf (
+     "File nplurals: %d, is different from profile nplurals %d.\n"
+     "Kindly go to preferences and select a profile with consistent nplurals "
+     "values as this file %s.",
+     po_nplurals, profile_nplurals, filename
+   );
+   gtr_tab_set_info (tab, info_msg_primary, info_msg_secondary);
+ 
+   GtkWidget *nb = priv->trans_notebook;
+   gtk_widget_set_sensitive (nb, FALSE);
+ 
+   g_object_unref (manager);
+ }
+ 
+ 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
+ on_profile_modified (GtrProfileManager *manager,
+                      GtrProfile *old_profile,
+                      GtrProfile *new_profile,
+                      GtrTab *tab)
+ {
+   on_active_profile_changed (manager, new_profile, tab);
+ }
+ 
+ 
  static void
  install_autosave_timeout (GtrTab * tab)
  {


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