[gtranslator: 1/2] Remove obsolete entries on save
- From: Daniel Garcia Moreno <danigm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtranslator: 1/2] Remove obsolete entries on save
- Date: Wed, 30 Mar 2022 06:22:40 +0000 (UTC)
commit 4a52feb365545ebe345d07475de84713f17b0dff
Author: redoC-A2k <afshanahmeda2k gmail com>
Date: Wed Mar 30 06:22:39 2022 +0000
Remove obsolete entries on save
Fixes https://gitlab.gnome.org/GNOME/gtranslator/-/issues/113
data/org.gnome.Gtranslator.gschema.xml.in | 7 +++++++
src/gtr-po.c | 25 ++++++++++++++++++++++++
src/gtr-preferences-dialog.c | 16 +++++++++++++++-
src/gtr-preferences-dialog.h | 1 +
src/gtr-preferences-dialog.ui | 32 +++++++++++++++++++++++++++----
src/gtr-settings.h | 1 +
6 files changed, 77 insertions(+), 5 deletions(-)
---
diff --git a/data/org.gnome.Gtranslator.gschema.xml.in b/data/org.gnome.Gtranslator.gschema.xml.in
index 8c9b110e..de82d967 100644
--- a/data/org.gnome.Gtranslator.gschema.xml.in
+++ b/data/org.gnome.Gtranslator.gschema.xml.in
@@ -27,6 +27,13 @@
fuzzy strings.
</description>
</key>
+ <key name="remove-obsolete-entries" type="b">
+ <default>false</default>
+ <summary>Whether the obsolete entries be removed upon saving</summary>
+ <description>
+ If true, the obsolete entries will be removed from the file after saving
+ </description>
+ </key>
<key name="auto-save" type="b">
<default>false</default>
<summary>Auto save files</summary>
diff --git a/src/gtr-po.c b/src/gtr-po.c
index a1ef77f6..4cc09ee5 100644
--- a/src/gtr-po.c
+++ b/src/gtr-po.c
@@ -40,6 +40,7 @@
#include "gtr-profile.h"
#include "gtr-utils.h"
#include "gtr-message-container.h"
+#include "gtr-preferences-dialog.h"
#include <string.h>
#include <errno.h>
@@ -76,6 +77,9 @@ typedef struct
/* The obsolete messages are stored within this gchar. */
gchar *obsolete;
+ /* Whether po file contains obsolete entries or not */
+ gboolean po_contains_obsolete_entries;
+
/* Is the file write-permitted? (read-only) */
gboolean no_write_perms;
@@ -214,6 +218,7 @@ gtr_po_init (GtrPo * po)
{
GtrPoPrivate *priv = gtr_po_get_instance_private (po);
+ priv->po_contains_obsolete_entries = FALSE;
priv->location = NULL;
priv->gettext_po_file = NULL;
priv->dl_team = NULL;
@@ -734,6 +739,8 @@ gtr_po_parse (GtrPo * po, GFile * location, GError ** error)
/* Build up messages */
priv->messages = g_list_prepend (priv->messages, msg);
}
+ else
+ priv->po_contains_obsolete_entries = TRUE;
}
if (priv->messages == NULL)
@@ -778,6 +785,9 @@ gtr_po_save_file (GtrPo * po, GError ** error)
gchar *msg_error;
GtrHeader *header;
GtrPoPrivate *priv = gtr_po_get_instance_private (po);
+ /* can't use priv->iter as its already exhausted*/
+ po_message_iterator_t iter = po_message_iterator (priv->gettext_po_file, NULL);
+ po_message_t message;
/*
* Initialice the handler error.
@@ -801,6 +811,21 @@ gtr_po_save_file (GtrPo * po, GError ** error)
return;
}
+ /*
+ * Removes obsolete entries from file if user opt for it
+ */
+ if (priv->po_contains_obsolete_entries && gtr_prefs_get_remove_obsolete ())
+ {
+ while ((message = po_next_message (iter)))
+ {
+ if(po_message_is_obsolete (message))
+ {
+ po_message_set_msgstr (message,"");
+ po_message_set_msgid (message, "");
+ }
+ }
+ }
+
if (is_read_only (filename))
{
diff --git a/src/gtr-preferences-dialog.c b/src/gtr-preferences-dialog.c
index 584b1b34..3c206e70 100644
--- a/src/gtr-preferences-dialog.c
+++ b/src/gtr-preferences-dialog.c
@@ -55,6 +55,7 @@ typedef struct
/* Files->General */
GtkWidget *warn_if_contains_fuzzy_checkbutton;
+ GtkCheckButton *remove_obsolete_entries;
/* Files->Autosave */
GtkWidget *autosave_checkbutton;
@@ -100,6 +101,11 @@ setup_files_general_page (GtrPreferencesDialog * dlg)
priv->warn_if_contains_fuzzy_checkbutton,
"active",
G_SETTINGS_BIND_GET | G_SETTINGS_BIND_SET);
+ g_settings_bind (priv->files_settings,
+ GTR_SETTINGS_REMOVE_OBSOLETE_ENTRIES,
+ priv->remove_obsolete_entries,
+ "active",
+ G_SETTINGS_BIND_GET | G_SETTINGS_BIND_SET);
}
static void
@@ -143,6 +149,14 @@ setup_files_autosave_page (GtrPreferencesDialog * dlg)
G_SETTINGS_BIND_GET | G_SETTINGS_BIND_SET);
}
+int
+gtr_prefs_get_remove_obsolete ()
+{
+ GSettings *files_settings = g_settings_new ("org.gnome.gtranslator.preferences.files");
+ gboolean remove_obsolete_entries_bool = g_settings_get_boolean (files_settings,
GTR_SETTINGS_REMOVE_OBSOLETE_ENTRIES);
+ return remove_obsolete_entries_bool;
+}
+
static void
setup_files_pages (GtrPreferencesDialog * dlg)
{
@@ -671,6 +685,7 @@ gtr_preferences_dialog_init (GtrPreferencesDialog * dlg)
priv->notebook = GTK_WIDGET (gtk_builder_get_object (builder, "notebook"));
g_object_ref (priv->notebook);
priv->warn_if_contains_fuzzy_checkbutton = GTK_WIDGET (gtk_builder_get_object (builder,
"warn_if_fuzzy_checkbutton"));
+ priv->remove_obsolete_entries = GTK_CHECK_BUTTON (gtk_builder_get_object (builder,
"remove_obsolete_entries"));
priv->autosave_checkbutton = GTK_WIDGET (gtk_builder_get_object (builder, "autosave_checkbutton"));
priv->autosave_interval_spinbutton = GTK_WIDGET (gtk_builder_get_object (builder,
"autosave_interval_spinbutton"));
priv->autosave_grid = GTK_WIDGET (gtk_builder_get_object (builder, "autosave_grid"));
@@ -757,4 +772,3 @@ gtr_show_preferences_dialog (GtrWindow * window)
gtk_window_present (GTK_WINDOW (dlg));
}
-
diff --git a/src/gtr-preferences-dialog.h b/src/gtr-preferences-dialog.h
index 1440e2de..ec9cd35e 100644
--- a/src/gtr-preferences-dialog.h
+++ b/src/gtr-preferences-dialog.h
@@ -55,6 +55,7 @@ struct _GtrPreferencesDialogClass
GType gtr_preferences_dialog_get_type (void)G_GNUC_CONST;
void gtr_show_preferences_dialog (GtrWindow *window);
+int gtr_prefs_get_remove_obsolete (void);
G_END_DECLS
diff --git a/src/gtr-preferences-dialog.ui b/src/gtr-preferences-dialog.ui
index d5de0369..d7bf1343 100644
--- a/src/gtr-preferences-dialog.ui
+++ b/src/gtr-preferences-dialog.ui
@@ -158,6 +158,30 @@
<property name="height">1</property>
</packing>
</child>
+ <child>
+ <object class="GtkAlignment" id="alignment3">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="left_padding">12</property>
+ <child>
+ <object class="GtkCheckButton" id="remove_obsolete_entries">
+ <property name="label" translatable="yes">_Remove obsolete entries on save</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="use_underline">True</property>
+ <property name="xalign">0</property>
+ <property name="draw_indicator">True</property>
+ </object>
+ </child>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">2</property>
+ <property name="width">1</property>
+ <property name="height">1</property>
+ </packing>
+ </child>
<child>
<object class="GtkLabel" id="label8">
<property name="visible">True</property>
@@ -170,13 +194,13 @@
</object>
<packing>
<property name="left_attach">0</property>
- <property name="top_attach">2</property>
+ <property name="top_attach">3</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
</child>
<child>
- <object class="GtkAlignment" id="alignment3">
+ <object class="GtkAlignment" id="alignment4">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="left_padding">12</property>
@@ -280,7 +304,7 @@
</object>
<packing>
<property name="left_attach">0</property>
- <property name="top_attach">3</property>
+ <property name="top_attach">4</property>
<property name="width">1</property>
<property name="height">1</property>
</packing>
@@ -330,7 +354,7 @@
</packing>
</child>
<child>
- <object class="GtkAlignment" id="alignment4">
+ <object class="GtkAlignment" id="alignment6">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="left_padding">12</property>
diff --git a/src/gtr-settings.h b/src/gtr-settings.h
index 1b3d559d..fb9405be 100644
--- a/src/gtr-settings.h
+++ b/src/gtr-settings.h
@@ -57,6 +57,7 @@ GSettings *gtr_settings_new (void);
/* key constants: IMPORTANT: keep them in the same order as the schema */
#define GTR_SETTINGS_WARN_IF_CONTAINS_FUZZY "warn-if-contains-fuzzy"
+#define GTR_SETTINGS_REMOVE_OBSOLETE_ENTRIES "remove-obsolete-entries"
#define GTR_SETTINGS_AUTO_SAVE "auto-save"
#define GTR_SETTINGS_AUTO_SAVE_INTERVAL "auto-save-interval"
#define GTR_SETTINGS_CREATE_BACKUP "create-backup"
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]