gtranslator r3518 - trunk/src
- From: icq svn gnome org
- To: svn-commits-list gnome org
- Subject: gtranslator r3518 - trunk/src
- Date: Thu, 13 Mar 2008 21:42:07 +0000 (GMT)
Author: icq
Date: Thu Mar 13 21:42:07 2008
New Revision: 3518
URL: http://svn.gnome.org/viewvc/gtranslator?rev=3518&view=rev
Log:
2008-03-13 Ignacio Casal Quinteiro <nacho resa gmail com>
* src/tab.c:
* src/po.c:
* src/prefs-manager.c:
* src/header.c:
* src/prefs-manager.h:
* src/header.h:
Added better support for plural forms. This already needs
work but i think i'll get it acomplished once Pablo finish
the profiles stuff.
Modified:
trunk/src/ChangeLog
trunk/src/header.c
trunk/src/header.h
trunk/src/po.c
trunk/src/prefs-manager.c
trunk/src/prefs-manager.h
trunk/src/tab.c
Modified: trunk/src/header.c
==============================================================================
--- trunk/src/header.c (original)
+++ trunk/src/header.c Thu Mar 13 21:42:07 2008
@@ -1,5 +1,6 @@
/*
* (C) 2007 Pablo Sanxiao <psanxiao gmail com>
+ * Ignacio Casal Quinteiro <nacho resa gmail com>
*
* gtranslator is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -17,6 +18,7 @@
*/
#include "header.h"
+#include "prefs-manager.h"
#include <glib.h>
#include <glib-object.h>
@@ -89,9 +91,36 @@
*/
gchar *encoding;
+ /*
+ * Plural forms and number of plurals
+ */
gchar *plural_forms;
+ gint nplurals;
};
+/*
+ * Set nplurals variable
+ */
+static void
+parse_nplurals (GtranslatorHeader *header)
+{
+ gchar *pointer;
+
+ g_return_if_fail (header->priv->plural_forms != NULL);
+
+ pointer = header->priv->plural_forms;
+
+ while (*pointer != '=')
+ pointer++;
+ pointer++;
+
+ //if there are any space between '=' and nplural number pointer++
+ while(*pointer == ' ')
+ pointer++;
+
+ header->priv->nplurals = g_ascii_digit_value(*pointer);
+}
+
static void gtranslator_header_init (GtranslatorHeader *header)
{
header->priv = GTR_HEADER_GET_PRIVATE (header);
@@ -296,17 +325,78 @@
header->priv->encoding = g_strdup(data);
}
-gchar *gtranslator_header_get_plural_forms (GtranslatorHeader *header)
+/**
+ * gtranslator_header_get_plural_forms:
+ * @header: a #GtranslatorHeader.
+ *
+ * Return value: the plural form of the po file.
+ */
+const gchar *
+gtranslator_header_get_plural_forms (GtranslatorHeader *header)
{
- return header->priv->plural_forms;
+ g_return_val_if_fail (GTR_IS_HEADER (header), NULL);
+
+ return (const gchar *)header->priv->plural_forms;
}
-void gtranslator_header_set_plural_forms (GtranslatorHeader *header, gchar *data)
+/**
+ * gtranslator_header_set_plural_forms:
+ * @header: a #GtranslatorHeader
+ * @plural_forms: the plural forms string.
+ *
+ * Sets the plural form string in the @header and it sets the number of plurals.
+ */
+void
+gtranslator_header_set_plural_forms (GtranslatorHeader *header,
+ const gchar *plural_forms)
{
- if(header->priv->plural_forms)
- g_free(header->priv->plural_forms);
- header->priv->plural_forms;
+ g_return_if_fail (GTR_IS_HEADER (header));
+
+ if (header->priv->plural_forms)
+ g_free (header->priv->plural_forms);
+
+ if (!plural_forms)
+ {
+ header->priv->plural_forms = NULL;
+ return;
+ }
+
+ header->priv->plural_forms = g_strdup (plural_forms);
+
+ /*Now we parse the plural forms to know the number of plurals*/
+ parse_nplurals (header);
}
-
-
+/**
+ * gtranslator_header_get_plural:
+ * @header: a #GtranslatorHeader
+ *
+ * Return value: The number of plurals of the po file, if there is not a plural
+ * form in the po file it returns the predefined by user number of plurals
+ * or 0 if there is not a plural form string stored.
+ */
+gint
+gtranslator_header_get_nplurals (GtranslatorHeader *header)
+{
+ const gchar *plural_form;
+
+ g_return_val_if_fail (GTR_IS_HEADER (header), -1);
+
+ /*
+ * If the priv->plural_forms exists that means that there is a plural
+ * form in our po file, If not we have to use the predefined plural form
+ * by the user.
+ */
+ if (header->priv->plural_forms)
+ return header->priv->nplurals;
+ else if (plural_form = gtranslator_prefs_manager_get_plural_form ())
+ {
+ gtranslator_header_set_plural_forms (header, plural_form);
+ /*
+ * FIXME: To don't produce a gettext error maybe we have to set the
+ * plural form in the gettext header field too.
+ */
+ return header->priv->nplurals;
+ }
+ else return 1;
+}
Modified: trunk/src/header.h
==============================================================================
--- trunk/src/header.h (original)
+++ trunk/src/header.h Thu Mar 13 21:42:07 2008
@@ -107,7 +107,10 @@
gchar *gtranslator_header_get_encoding (GtranslatorHeader *header);
void gtranslator_header_set_encoding (GtranslatorHeader *header, gchar *data);
-gchar *gtranslator_header_get_plural_forms (GtranslatorHeader *header);
-void gtranslator_header_set_plural_forms (GtranslatorHeader *header, gchar *data);
+const gchar *gtranslator_header_get_plural_forms (GtranslatorHeader *header);
+void gtranslator_header_set_plural_forms (GtranslatorHeader *header,
+ const gchar *plural_forms);
+
+gint gtranslator_header_get_nplurals (GtranslatorHeader *header);
#endif /* __HEADER_H__ */
Modified: trunk/src/po.c
==============================================================================
--- trunk/src/po.c (original)
+++ trunk/src/po.c Thu Mar 13 21:42:07 2008
@@ -158,7 +158,10 @@
g_list_free (po->priv->messages);
}
if (po->priv->domains)
+ {
+ g_list_foreach (po->priv->domains, (GFunc)g_free, NULL);
g_list_free (po->priv->domains);
+ }
g_free (po->priv->filename);
g_free (po->priv->obsolete);
@@ -336,16 +339,16 @@
gchar *comment, *prj_id_version, *rmbt, *pot_date, *po_date,
*translator, *tr_email, *language, *lg_email, *mime_version,
- *charset, *encoding;
+ *charset, *encoding, *plural_forms;
gchar *space1, *space2, *space3;
comment = g_strdup(po_message_comments(message));
prj_id_version = po_header_field(msgstr, "Project-Id-Version");
- rmbt = g_strdup(po_header_field(msgstr, "Report-Msgid-Bugs-To"));
- pot_date = g_strdup(po_header_field(msgstr, "POT-Creation-Date"));
- po_date = g_strdup(po_header_field(msgstr, "PO-Revision-Date"));
+ rmbt = po_header_field(msgstr, "Report-Msgid-Bugs-To");
+ pot_date = po_header_field(msgstr, "POT-Creation-Date");
+ po_date = po_header_field(msgstr, "PO-Revision-Date");
gchar *translator_temp = po_header_field(msgstr, "Last-Translator");
space1 = g_strrstr(translator_temp, " <");
@@ -371,9 +374,9 @@
lg_email = g_strndup(space2 + 2, strlen(space2)-3);
}
- mime_version = g_strdup(po_header_field(msgstr, "MIME-Version"));
+ mime_version = po_header_field(msgstr, "MIME-Version");
- gchar *charset_temp = g_strdup(po_header_field(msgstr, "Content-Type"));
+ gchar *charset_temp = po_header_field(msgstr, "Content-Type");
space3 = g_strrstr(charset_temp, "=");
if (!space3)
@@ -383,7 +386,12 @@
charset = g_strdup(space3 +1);
}
- encoding = g_strdup(po_header_field(msgstr, "Content-Transfer-Encoding"));
+ encoding = po_header_field(msgstr, "Content-Transfer-Encoding");
+
+ /*
+ * Plural forms:
+ */
+ plural_forms = po_header_field (msgstr, "Plural-Forms");
gtranslator_header_set_comment(priv->header, comment);
gtranslator_header_set_prj_id_version(priv->header, prj_id_version);
@@ -398,6 +406,8 @@
gtranslator_header_set_mime_version(priv->header, mime_version);
gtranslator_header_set_charset(priv->header, charset);
gtranslator_header_set_encoding(priv->header, encoding);
+ gtranslator_header_set_plural_forms (priv->header,
+ plural_forms);
g_free (translator_temp);
g_free (language_temp);
@@ -414,6 +424,7 @@
g_free (mime_version);
g_free (charset);
g_free (encoding);
+ g_free (plural_forms);
}
else {
/* Reset our pointer */
@@ -530,6 +541,11 @@
*/
iter = po_message_iterator(gtranslator_po_get_po_file(po), NULL);
message = po_next_message(iter);
+ /*
+ * FIXME: We have to use our msg class to manage this kind of things,
+ * and we have to encapsulate the funcs like po_header_set_field in
+ * our header class.
+ */
msgstr = po_message_msgstr(message);
/*
Modified: trunk/src/prefs-manager.c
==============================================================================
--- trunk/src/prefs-manager.c (original)
+++ trunk/src/prefs-manager.c Thu Mar 13 21:42:07 2008
@@ -324,14 +324,9 @@
GPM_EMAIL,
GPM_DEFAULT_EMAIL)
-DEFINE_INT_PREF(number_plurals,
- GPM_NUMBER_PLURALS,
- GPM_DEFAULT_NUMBER_PLURALS)
-
-
-DEFINE_STRING_PREF(plurals,
- GPM_PLURALS,
- GPM_DEFAULT_PLURALS)
+DEFINE_STRING_PREF(plural_form,
+ GPM_PLURAL_FORM,
+ GPM_DEFAULT_PLURAL_FORM)
/* Interface */
DEFINE_INT_PREF (gdl_style,
Modified: trunk/src/prefs-manager.h
==============================================================================
--- trunk/src/prefs-manager.h (original)
+++ trunk/src/prefs-manager.h Thu Mar 13 21:42:07 2008
@@ -69,8 +69,9 @@
#define GPM_CHARSET GPM_LANGUAGE_SETTINGS_DIR "/charset"
#define GPM_TRANSFER_ENCODING GPM_LANGUAGE_SETTINGS_DIR "/transfer_encoding"
#define GPM_TEAM_EMAIL GPM_LANGUAGE_SETTINGS_DIR "/team_email"
-#define GPM_NUMBER_PLURALS GPM_LANGUAGE_SETTINGS_DIR "/number_plurals"
-#define GPM_PLURALS GPM_LANGUAGE_SETTINGS_DIR "/plurals"
+
+/*FIXME: With profiles i think that this has to change*/
+#define GPM_PLURAL_FORM GPM_LANGUAGE_SETTINGS_DIR "/plural_form"
/* Interface */
#define GPM_INTERFACE_DIR GPM_PREFS_DIR "/interface"
@@ -109,8 +110,7 @@
#define GPM_MIME_TYPE GPM_LANGUAGE_SETTINGS_DIR "/mime_type"
#define GPM_ENCODING GPM_LANGUAGE_SETTINGS_DIR "/encoding"
#define GPM_LG_EMAIL GPM_LANGUAGE_SETTINGS_DIR "/lg_email"*/
-#define GPM_DEFAULT_NUMBER_PLURALS 2
-#define GPM_DEFAULT_PLURALS (const gchar*) ""
+#define GPM_DEFAULT_PLURAL_FORM (const gchar*) ""
/* Interface */
#define GPM_DEFAULT_GDL_STYLE 2 //Both icons and text
@@ -189,11 +189,11 @@
void gtranslator_prefs_manager_set_email (const gchar *email);
const gchar * gtranslator_prefs_manager_get_email (void);
-/*number plurals*/
-void gtranslator_prefs_manager_set_number_plurals (gint plurals);
-gint gtranslator_prefs_manager_get_number_plurals (void);
+/*Plural form*/
+void gtranslator_prefs_manager_set_plural_form (const gchar *plural_form);
+const gchar * gtranslator_prefs_manager_get_plural_form (void);
-/*gdl style*/
+/*Gdl style*/
void gtranslator_prefs_manager_set_gdl_style (gint style);
gint gtranslator_prefs_manager_get_gdl_style (void);
Modified: trunk/src/tab.c
==============================================================================
--- trunk/src/tab.c (original)
+++ trunk/src/tab.c Thu Mar 13 21:42:07 2008
@@ -125,6 +125,7 @@
gtranslator_message_translation_update(GtkTextBuffer *textbuffer,
GtranslatorTab *tab)
{
+ GtranslatorHeader *header;
GtkTextIter start, end;
GtkTextBuffer *buf;
GList *msg_aux;
@@ -135,6 +136,8 @@
/* Work out which message this is associated with */
+ header = gtranslator_po_get_header (tab->priv->po);
+
msg_aux = gtranslator_po_get_current_message(tab->priv->po);
msg = msg_aux->data;
buf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(tab->priv->trans_msgstr[0]));
@@ -162,7 +165,8 @@
return;
}
i=1;
- while(i < gtranslator_prefs_manager_get_number_plurals()) {
+ while(i < gtranslator_header_get_nplurals (header))
+ {
/* Know when to break out of the loop */
if(!tab->priv->trans_msgstr[i]) {
break;
@@ -184,7 +188,6 @@
/* Write back to PO file in memory */
gtranslator_msg_set_msgstr_plural(msg, i, translation);
return;
-
}
/* Shouldn't get here */
@@ -227,27 +230,28 @@
}
static void
-gtranslator_message_plural_forms(GtranslatorTab *tab,
- GtranslatorMsg *msg)
+gtranslator_message_plural_forms (GtranslatorTab *tab,
+ GtranslatorMsg *msg)
{
+ GtranslatorHeader *header;
GtkTextBuffer *buf;
const gchar *msgstr_plural;
gint i;
- g_return_if_fail(tab != NULL);
- g_return_if_fail(msg != NULL);
- /*
- * Should show the number of plural forms defined in header
- */
- for(i = 0; i < gtranslator_prefs_manager_get_number_plurals(); i++)
+ g_return_if_fail (tab != NULL);
+ g_return_if_fail (msg != NULL);
+
+ header = gtranslator_po_get_header (tab->priv->po);
+
+ for (i = 0; i < gtranslator_header_get_nplurals (header); i++)
{
- msgstr_plural = gtranslator_msg_get_msgstr_plural(msg, i);
- if(msgstr_plural)
+ msgstr_plural = gtranslator_msg_get_msgstr_plural (msg, i);
+ if (msgstr_plural)
{
- buf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(tab->priv->trans_msgstr[i]));
- gtk_source_buffer_begin_not_undoable_action(GTK_SOURCE_BUFFER(buf));
- gtk_text_buffer_set_text(buf, (gchar*)msgstr_plural, -1);
- gtk_source_buffer_end_not_undoable_action(GTK_SOURCE_BUFFER(buf));
+ buf = gtk_text_view_get_buffer (GTK_TEXT_VIEW (tab->priv->trans_msgstr[i]));
+ gtk_source_buffer_begin_not_undoable_action (GTK_SOURCE_BUFFER (buf));
+ gtk_text_buffer_set_text (buf, (gchar*)msgstr_plural, -1);
+ gtk_source_buffer_end_not_undoable_action (GTK_SOURCE_BUFFER (buf));
}
}
}
@@ -416,14 +420,43 @@
}
static void
+gtranslator_tab_add_msgstr_tabs (GtranslatorTab *tab)
+{
+ GtranslatorHeader *header;
+ GtranslatorTabPrivate *priv = tab->priv;
+ gchar *label;
+ GtkTextBuffer *buf;
+ gint i = 0;
+
+ /*
+ * We get the header of the po file
+ */
+ header = gtranslator_po_get_header (tab->priv->po);
+
+ do{
+ label = g_strdup_printf (_("Plural %d"), i+1);
+ priv->trans_msgstr[i] = gtranslator_tab_append_page (label,
+ priv->trans_notebook,
+ TRUE);
+ buf = gtk_text_view_get_buffer (GTK_TEXT_VIEW (priv->trans_msgstr[i]));
+ g_signal_connect (buf, "end-user-action",
+ G_CALLBACK (gtranslator_message_translation_update),
+ tab);
+
+ g_signal_connect_after (buf, "end_user_action",
+ G_CALLBACK (emit_message_changed_signal),
+ tab);
+ i++;
+ g_free (label);
+ }while (i < gtranslator_header_get_nplurals (header));
+}
+
+static void
gtranslator_tab_draw (GtranslatorTab *tab)
{
GtkWidget *image;
GtkWidget *vertical_box;
- GtkTextBuffer *buf;
- gchar *label;
GtkWidget *label_widget;
- gint i = 0;
GtranslatorTabPrivate *priv = tab->priv;
@@ -508,22 +541,6 @@
priv->trans_notebook = gtk_notebook_new();
gtk_notebook_set_show_border(GTK_NOTEBOOK(priv->trans_notebook), FALSE);
gtk_widget_show (priv->trans_notebook);
- do{
- label = g_strdup_printf(_("Plural %d"), i+1);
- priv->trans_msgstr[i] = gtranslator_tab_append_page(label,
- priv->trans_notebook,
- TRUE);
- buf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(priv->trans_msgstr[i]));
- g_signal_connect(buf, "end-user-action",
- G_CALLBACK(gtranslator_message_translation_update),
- tab);
-
- g_signal_connect_after(buf, "end_user_action",
- G_CALLBACK(emit_message_changed_signal),
- tab);
- i++;
- g_free(label);
- }while(i < gtranslator_prefs_manager_get_number_plurals());
gtk_box_pack_start(GTK_BOX(vertical_box), priv->trans_notebook, TRUE, TRUE, 0);
@@ -618,6 +635,12 @@
tab = g_object_new (GTR_TYPE_TAB, NULL);
tab->priv->po = po;
+
+ /*
+ * Now we have to initialize the number of msgstr tabs
+ */
+ gtranslator_tab_add_msgstr_tabs (tab);
+
gtranslator_message_table_populate(GTR_MESSAGE_TABLE(tab->priv->message_table),
gtranslator_po_get_messages(tab->priv->po));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]