[gtranslator] extend API of translation memory.
- From: Ignacio Casal Quinteiro <icq src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtranslator] extend API of translation memory.
- Date: Sun, 25 Apr 2010 20:03:47 +0000 (UTC)
commit 54a617afef5bd703586e1a305c8a38e06d251d89
Author: Andrey Kutejko <andy128k gmail com>
Date: Sun Apr 25 15:05:14 2010 +0300
extend API of translation memory.
src/dialogs/gtr-assistant.c | 12 +----
src/dialogs/gtr-preferences-dialog.c | 11 +---
src/gtr-tab.c | 4 +-
src/translation-memory/berkeley/gtr-berkeley.c | 14 +++--
src/translation-memory/gtr-translation-memory-ui.c | 2 +-
src/translation-memory/gtr-translation-memory.c | 60 +++++++++++++++-----
src/translation-memory/gtr-translation-memory.h | 29 +++++----
7 files changed, 75 insertions(+), 57 deletions(-)
---
diff --git a/src/dialogs/gtr-assistant.c b/src/dialogs/gtr-assistant.c
index 8f9120a..0f9866a 100644
--- a/src/dialogs/gtr-assistant.c
+++ b/src/dialogs/gtr-assistant.c
@@ -95,7 +95,6 @@ G_DEFINE_TYPE (GtrAssistant, gtr_assistant, GTK_TYPE_ASSISTANT)
if (l)
{
GList *msg_list = NULL;
- GList *l2 = NULL;
GFile *location;
GError *error = NULL;
GtrPo *po;
@@ -109,16 +108,7 @@ G_DEFINE_TYPE (GtrAssistant, gtr_assistant, GTK_TYPE_ASSISTANT)
msg_list = gtr_po_get_messages (po);
- for (l2 = msg_list; l2; l2 = g_list_next (l2))
- {
- GtrMsg *msg;
-
- msg = GTR_MSG (l2->data);
- if (gtr_msg_is_translated (msg))
- gtr_translation_memory_store (data->tm,
- gtr_msg_get_msgid
- (msg), gtr_msg_get_msgstr (msg));
- }
+ gtr_translation_memory_store_list (data->tm, msg_list);
g_object_unref (po);
}
diff --git a/src/dialogs/gtr-preferences-dialog.c b/src/dialogs/gtr-preferences-dialog.c
index 7adcdd1..aa154b4 100644
--- a/src/dialogs/gtr-preferences-dialog.c
+++ b/src/dialogs/gtr-preferences-dialog.c
@@ -903,7 +903,6 @@ add_to_database (gpointer data_pointer)
if (l)
{
GList *msg_list = NULL;
- GList *l2 = NULL;
GFile *location;
GError *error = NULL;
GtrPo *po;
@@ -917,15 +916,7 @@ add_to_database (gpointer data_pointer)
msg_list = gtr_po_get_messages (po);
- for (l2 = msg_list; l2; l2 = l2->next)
- {
- GtrMsg *msg;
- msg = GTR_MSG (l2->data);
- if (gtr_msg_is_translated (msg))
- gtr_translation_memory_store (data->tm,
- gtr_msg_get_msgid
- (msg), gtr_msg_get_msgstr (msg));
- }
+ gtr_translation_memory_store_list (data->tm, msg_list);
g_object_unref (po);
}
diff --git a/src/gtr-tab.c b/src/gtr-tab.c
index d5e53e1..2b818e4 100644
--- a/src/gtr-tab.c
+++ b/src/gtr-tab.c
@@ -195,9 +195,7 @@ gtr_tab_edition_finished (GtrTab * tab, GtrMsg * msg)
GTR_TRANSLATION_MEMORY (gtr_application_get_translation_memory (GTR_APP));
if (gtr_msg_is_translated (msg) && !gtr_msg_is_fuzzy (msg))
- gtr_translation_memory_store (tm,
- gtr_msg_get_msgid (msg),
- gtr_msg_get_msgstr (msg));
+ gtr_translation_memory_store (tm, msg);
/*
* Checking message
diff --git a/src/translation-memory/berkeley/gtr-berkeley.c b/src/translation-memory/berkeley/gtr-berkeley.c
index 1194eff..9b0a207 100644
--- a/src/translation-memory/berkeley/gtr-berkeley.c
+++ b/src/translation-memory/berkeley/gtr-berkeley.c
@@ -60,16 +60,20 @@ G_DEFINE_TYPE_WITH_CODE (GtrBerkeley,
gint max_items;
};
- static gboolean
- gtr_berkeley_store (GtrTranslationMemory * tm,
- const gchar * original, const gchar * translation)
+static gboolean
+gtr_berkeley_store (GtrTranslationMemory * tm, GtrMsg * msg)
{
GtrBerkeley *ber = GTR_BERKELEY (tm);
gboolean ok;
db_recno_t key;
-
+ const gchar * original;
+ const gchar * translation;
+
g_return_val_if_fail (GTR_IS_BERKELEY (ber), FALSE);
+ original = gtr_msg_get_msgid (msg);
+ translation = gtr_msg_get_msgstr (msg);
+
key = gtr_db_orig_read (ber->priv->orig, original);
if (key == 0)
{
@@ -517,7 +521,7 @@ gtr_berkeley_lookup (GtrTranslationMemory * tm, const gchar * phrase)
list:g_hash_table_iter_init (&iter, hash);
while (g_hash_table_iter_next (&iter, &hkey, &value))
{
- GtrTranslationMemoryMatch *match = g_new (GtrTranslationMemoryMatch, 1);
+ GtrTranslationMemoryMatch *match = g_slice_new (GtrTranslationMemoryMatch);
match->match = g_strdup (hkey);
match->level = GPOINTER_TO_INT (value);
diff --git a/src/translation-memory/gtr-translation-memory-ui.c b/src/translation-memory/gtr-translation-memory-ui.c
index 93b288b..8083d02 100644
--- a/src/translation-memory/gtr-translation-memory-ui.c
+++ b/src/translation-memory/gtr-translation-memory-ui.c
@@ -107,7 +107,7 @@ free_list (gpointer data, gpointer useless)
GtrTranslationMemoryMatch *match = (GtrTranslationMemoryMatch *) data;
g_free (match->match);
- g_free (match);
+ g_slice_free (GtrTranslationMemoryMatch, match);
}
static void
diff --git a/src/translation-memory/gtr-translation-memory.c b/src/translation-memory/gtr-translation-memory.c
index 9154809..0c9b363 100644
--- a/src/translation-memory/gtr-translation-memory.c
+++ b/src/translation-memory/gtr-translation-memory.c
@@ -1,16 +1,16 @@
/*
* Copyright (C) 2008 Ignacio Casal Quinteiro <nacho resa gmail com>
- *
+ *
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
- *
+ *
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
@@ -20,31 +20,62 @@
/**
* gtr_translation_memory_store:
* @obj: a #GtrTranslationMemory
- * @original: the untranslated text
- * @translation: the @original text translated
+ * @msg: message
*
- * Stores the @original and @translation strings in the database.
+ * Stores the @msg in the database.
*/
gboolean
-gtr_translation_memory_store (GtrTranslationMemory * obj,
- const gchar * original,
- const gchar * translation)
+gtr_translation_memory_store (GtrTranslationMemory * obj, GtrMsg * msg)
{
g_return_val_if_fail (GTR_IS_TRANSLATION_MEMORY (obj), FALSE);
- return GTR_TRANSLATION_MEMORY_GET_IFACE (obj)->store (obj, original,
- translation);
+ return GTR_TRANSLATION_MEMORY_GET_IFACE (obj)->store (obj, msg);
}
/* Default implementation */
static gboolean
-gtr_translation_memory_store_default (GtrTranslationMemory *
- obj, const gchar * original,
- const gchar * translation)
+gtr_translation_memory_store_default (GtrTranslationMemory * obj, GtrMsg * msg)
{
g_return_val_if_reached (FALSE);
}
/**
+ * gtr_translation_memory_store_list:
+ * @obj: a #GtrTranslationMemory
+ * @msgs: list of messages (#GtrMsg)
+ *
+ * Stores the messages from @msgs in the database.
+ */
+gboolean
+gtr_translation_memory_store_list (GtrTranslationMemory * obj, GList * msgs)
+{
+ g_return_val_if_fail (GTR_IS_TRANSLATION_MEMORY (obj), FALSE);
+ return GTR_TRANSLATION_MEMORY_GET_IFACE (obj)->store_list (obj, msgs);
+}
+
+/* Default implementation */
+static gboolean
+gtr_translation_memory_store_list_default (GtrTranslationMemory * obj,
+ GList * msgs)
+{
+ GList * l;
+
+ for (l = msgs; l; l = g_list_next (l))
+ {
+ GtrMsg *msg = GTR_MSG (l->data);
+ gboolean result;
+
+ if (!gtr_msg_is_translated (msg))
+ continue;
+
+ result = gtr_translation_memory_store (obj, msg);
+ if (!result)
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+/**
* gtr_translation_memory_lookup:
* @obj: a #GtrTranslationMemory
* @phrase: the unstranslated text to search for translations.
@@ -138,6 +169,7 @@ gtr_translation_memory_base_init (GtrTranslationMemoryIface * klass)
static gboolean initialized = FALSE;
klass->store = gtr_translation_memory_store_default;
+ klass->store_list = gtr_translation_memory_store_list_default;
klass->lookup = gtr_translation_memory_lookup_default;
klass->set_max_omits = gtr_translation_memory_set_max_omits_default;
klass->set_max_delta = gtr_translation_memory_set_max_delta_default;
diff --git a/src/translation-memory/gtr-translation-memory.h b/src/translation-memory/gtr-translation-memory.h
index a99328e..9cc063c 100644
--- a/src/translation-memory/gtr-translation-memory.h
+++ b/src/translation-memory/gtr-translation-memory.h
@@ -19,6 +19,7 @@
#define _GTR_TRANSLATION_MEMORY_H_
#include <glib-object.h>
+#include "gtr-msg.h"
G_BEGIN_DECLS
#define GTR_TYPE_TRANSLATION_MEMORY (gtr_translation_memory_get_type ())
@@ -31,10 +32,10 @@ typedef struct _GtrTranslationMemoryIface GtrTranslationMemoryIface;
struct _GtrTranslationMemoryIface
{
GTypeInterface g_iface;
+
+ gboolean (*store) (GtrTranslationMemory * obj, GtrMsg * msg);
+ gboolean (*store_list) (GtrTranslationMemory * obj, GList * msgs);
-
- gboolean (*store) (GtrTranslationMemory * obj,
- const gchar * original, const gchar * translation);
GList *(*lookup) (GtrTranslationMemory * obj, const gchar * phrase);
void (*set_max_omits) (GtrTranslationMemory * obj, gsize omits);
void (*set_max_delta) (GtrTranslationMemory * obj, gsize delta);
@@ -48,22 +49,24 @@ struct _GtrTranslationMemoryMatch
gint level;
};
-GType gtr_translation_memory_get_type (void);
+GType
+gtr_translation_memory_get_type (void);
+
+gboolean
+gtr_translation_memory_store (GtrTranslationMemory * obj, GtrMsg * msg);
-gboolean gtr_translation_memory_store (GtrTranslationMemory *
- obj, const gchar * original,
- const gchar * translation);
+gboolean
+gtr_translation_memory_store_list (GtrTranslationMemory * obj, GList * msg);
-GList *gtr_translation_memory_lookup (GtrTranslationMemory *
- obj, const gchar * phrase);
+GList *
+gtr_translation_memory_lookup (GtrTranslationMemory * obj,
+ const gchar * phrase);
void
-gtr_translation_memory_set_max_omits (GtrTranslationMemory *
- obj, gsize omits);
+gtr_translation_memory_set_max_omits (GtrTranslationMemory * obj, gsize omits);
void
-gtr_translation_memory_set_max_delta (GtrTranslationMemory *
- obj, gsize delta);
+gtr_translation_memory_set_max_delta (GtrTranslationMemory * obj, gsize delta);
void
gtr_translation_memory_set_max_items (GtrTranslationMemory * obj, gint items);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]