gtranslator r3504 - in trunk: . src src/dialogs
- From: psanxiao svn gnome org
- To: svn-commits-list gnome org
- Subject: gtranslator r3504 - in trunk: . src src/dialogs
- Date: Mon, 3 Mar 2008 18:09:58 +0000 (GMT)
Author: psanxiao
Date: Mon Mar 3 18:09:57 2008
New Revision: 3504
URL: http://svn.gnome.org/viewvc/gtranslator?rev=3504&view=rev
Log:
* dialogs/header-dialog.c:
* actions-files.c:
* po.{h,c}:
* header.{h,c}:
Now when you edit the header, the changes are saved and
Po file revision date is updated.
Modified:
trunk/ChangeLog
trunk/src/ChangeLog
trunk/src/actions-file.c
trunk/src/dialogs/header-dialog.c
trunk/src/header.c
trunk/src/header.h
trunk/src/po.c
trunk/src/po.h
Modified: trunk/src/actions-file.c
==============================================================================
--- trunk/src/actions-file.c (original)
+++ trunk/src/actions-file.c Mon Mar 3 18:09:57 2008
@@ -3,6 +3,7 @@
* Fatih Demir <kabalak kabalak net>
* Ross Golder <ross golder org>
* Gediminas Paulauskas <menesis kabalak net>
+ Pablo Sanxiao <psanxiao 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
@@ -95,72 +96,6 @@
return TRUE;
}
-
-gboolean
-gtranslator_save_file(GtranslatorPo *po,
- const gchar *name,
- GError **error)
-{
- po_xerror_handler_t gettext_error_handler;
-
- /*if(g_str_has_suffix(name, ".pot"))
- {
- g_set_error(error,
- GTR_PARSER_ERROR,
- GTR_PARSER_ERROR_FILENAME,
- _("You are saving a file with a .pot extension.\n\
-Pot files are generated by the compilation process.\n\
-Your file should likely be named '%s.po'."),
- gtranslator_translator->language->locale);
- return FALSE;
- }*/
-
- gtranslator_file_dialogs_store_directory(name);
-
- /*
- * Let gettext do the work here
- */
- if(!po_file_write(gtranslator_po_get_po_file(po), name, gettext_error_handler))
- return FALSE;
-
- /*
- * If we do append a suffix to the autogenerated files, then we'd
- * also not disable the file saving entry and we don't also disable
- * the save entry on simple compile testing -- check for filename
- * equality.
- */
- /*if((GtrPreferences.autosave && GtrPreferences.autosave_with_suffix &&
- (po->autosave_timeout > 1)) ||
- !nautilus_strcmp(po->filename, name))
- {
- gtk_widget_set_sensitive(gtranslator_menuitems->save, FALSE);
- gtk_widget_set_sensitive(gtranslator_menuitems->t_save, FALSE);
- }*/
-
- //po->file_changed = FALSE;
-
- /* If user GtrPreferences to, warn it about fuzzy mesages left */
- /*if(GtrPreferences.warn_if_fuzzy && po->fuzzy)
- {
- GtkWidget *dialog;
-
- dialog = gtk_message_dialog_new(
- GTK_WINDOW(window),
- GTK_DIALOG_DESTROY_WITH_PARENT,
- GTK_MESSAGE_WARNING,
- GTK_BUTTONS_OK,
- ngettext("File %s\ncontains %d fuzzy message",
- "File %s\ncontains %d fuzzy messages",
- po->fuzzy),
- po->filename, po->fuzzy);
- gtk_dialog_run(GTK_DIALOG(dialog));
- gtk_widget_destroy(dialog);
- }*/
-
- return TRUE;
-}
-
-
static void
gtranslator_po_parse_file_from_dialog(GtkWidget * dialog,
GtranslatorWindow *window)
@@ -490,7 +425,7 @@
//g_return_if_fail(current_page->po->file_changed);
- if (!gtranslator_save_file(po, gtranslator_po_get_filename(po), &error)) {
+ if (!gtranslator_po_save_file(po, gtranslator_po_get_filename(po), &error)) {
GtkWidget *dialog;
g_assert(error != NULL);
dialog = gtk_message_dialog_new(
Modified: trunk/src/dialogs/header-dialog.c
==============================================================================
--- trunk/src/dialogs/header-dialog.c (original)
+++ trunk/src/dialogs/header-dialog.c Mon Mar 3 18:09:57 2008
@@ -83,6 +83,12 @@
g_return_if_fail(button == GTK_TOGGLE_BUTTON(dlg->priv->take_my_options));
gtranslator_prefs_manager_set_take_my_options(gtk_toggle_button_get_active(button));
+
+ gtk_widget_set_sensitive(dlg->priv->translator, !gtk_toggle_button_get_active(button));
+ gtk_widget_set_sensitive(dlg->priv->tr_email, !gtk_toggle_button_get_active(button));
+ gtk_widget_set_sensitive(dlg->priv->language, !gtk_toggle_button_get_active(button));
+ gtk_widget_set_sensitive(dlg->priv->lg_email, !gtk_toggle_button_get_active(button));
+ gtk_widget_set_sensitive(dlg->priv->encoding, !gtk_toggle_button_get_active(button));
}
static void
@@ -256,6 +262,10 @@
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(dlg->priv->take_my_options),
gtranslator_prefs_manager_get_take_my_options());
+ gtk_widget_set_sensitive(dlg->priv->pot_date, FALSE);
+ gtk_widget_set_sensitive(dlg->priv->po_date, FALSE);
+ gtk_widget_set_sensitive(dlg->priv->charset, FALSE);
+
/*Connect signals*/
g_signal_connect(dlg->priv->take_my_options, "toggled",
G_CALLBACK(take_my_options_checkbutton_toggled),
Modified: trunk/src/header.c
==============================================================================
--- trunk/src/header.c (original)
+++ trunk/src/header.c Mon Mar 3 18:09:57 2008
@@ -58,17 +58,22 @@
gchar *translator;
/*
- * Translator Email;
+ * Translator Email
*/
gchar *tr_email;
-
+
+ /*
+ * Previous Translator Name and Email
+ */
+ gchar *prev_translator;
+
/*
- * Language Name;
+ * Language Name
*/
gchar *language;
/*
- * Traslation group email;
+ * Traslation group email
*/
gchar *lg_email;
@@ -219,6 +224,18 @@
header->priv->tr_email = g_strdup(data);
}
+gchar *gtranslator_header_get_prev_translator (GtranslatorHeader *header)
+{
+ return header->priv->prev_translator;
+}
+
+void gtranslator_header_set_prev_translator (GtranslatorHeader *header, gchar *data)
+{
+ if(header->priv->prev_translator)
+ g_free(header->priv->prev_translator);
+ header->priv->prev_translator = g_strdup(data);
+}
+
gchar *gtranslator_header_get_language (GtranslatorHeader *header)
{
return header->priv->language;
Modified: trunk/src/header.h
==============================================================================
--- trunk/src/header.h (original)
+++ trunk/src/header.h Mon Mar 3 18:09:57 2008
@@ -89,6 +89,9 @@
gchar *gtranslator_header_get_tr_email (GtranslatorHeader *header);
void gtranslator_header_set_tr_email (GtranslatorHeader *header, gchar *data);
+gchar *gtranslator_header_get_prev_translator (GtranslatorHeader *header);
+void gtranslator_header_set_prev_translator (GtranslatorHeader *header, gchar *data);
+
gchar *gtranslator_header_get_language (GtranslatorHeader *header);
void gtranslator_header_set_language (GtranslatorHeader *header, gchar *data);
Modified: trunk/src/po.c
==============================================================================
--- trunk/src/po.c (original)
+++ trunk/src/po.c Mon Mar 3 18:09:57 2008
@@ -392,6 +392,7 @@
gtranslator_header_set_po_date(priv->header, po_date);
gtranslator_header_set_translator(priv->header, translator);
gtranslator_header_set_tr_email(priv->header, tr_email);
+ gtranslator_header_set_prev_translator(priv->header, translator_temp);
gtranslator_header_set_language(priv->header, language);
gtranslator_header_set_lg_email(priv->header, lg_email);
gtranslator_header_set_mime_version(priv->header, mime_version);
@@ -457,6 +458,145 @@
}
/**
+ * gtranslator_po_save_file:
+ * @po: a #GtranslatorPo
+ * @name: filename
+ * @error: a variable to store the errors
+ *
+ *
+ **/
+gboolean
+gtranslator_po_save_file(GtranslatorPo *po,
+ const gchar *name,
+ GError **error)
+{
+ po_xerror_handler_t gettext_error_handler;
+
+ po_message_iterator_t iter;
+ po_message_t message;
+
+ GtranslatorHeader *header;
+
+ const char *msgstr,
+ *header_comment;
+ const char *prev_translator;
+
+ time_t now;
+ struct tm *now_here;
+ char t[22];
+ gchar *year=g_malloc(5);
+
+ /*if(g_str_has_suffix(name, ".pot"))
+ {
+ g_set_error(error,
+ GTR_PARSER_ERROR,
+ GTR_PARSER_ERROR_FILENAME,
+ _("You are saving a file with a .pot extension.\n\
+Pot files are generated by the compilation process.\n\
+Your file should likely be named '%s.po'."),
+ gtranslator_translator->language->locale);
+ return FALSE;
+ }*/
+
+ gtranslator_file_dialogs_store_directory(name);
+
+ /*
+ * Get header's fields
+ */
+ header = gtranslator_po_get_header(po);
+ /*
+ * Save the previous translator to update the header's comment
+ */
+ prev_translator = gtranslator_header_get_prev_translator(header);
+
+ /*
+ * Determinate the message with the header
+ */
+ iter = po_message_iterator(gtranslator_po_get_po_file(po), NULL);
+ message = po_next_message(iter);
+ msgstr = po_message_msgstr(message);
+
+ /*
+ * Update the po date
+ */
+ now = time(NULL);
+ now_here = localtime(&now);
+ strftime(t, 22, "%Y-%m-%d %H:%M%z", now_here);
+ strftime(year, 5, "%Y", now_here);
+ gtranslator_header_set_po_date(header, g_strdup(t));
+
+ /*
+ * Update the header's comment
+ */
+ if (strcmp(prev_translator, g_strconcat(gtranslator_header_get_translator(header), " ", "<",
+ gtranslator_header_get_tr_email(header), ">", NULL)))
+ {
+ header_comment = po_message_comments (message);
+ po_message_set_comments (message,
+ g_strconcat(header_comment, gtranslator_header_get_translator(header), " ", "<",
+ gtranslator_header_get_tr_email(header), ">", ",", " ", year, NULL));
+ }
+
+ /*
+ * Write the header's fields
+ */
+ msgstr = po_header_set_field (msgstr, "Project-Id-Version", gtranslator_header_get_prj_id_version(header));
+ msgstr = po_header_set_field (msgstr, "PO-Revision-Date", gtranslator_header_get_po_date(header));
+ msgstr = po_header_set_field (msgstr, "Last-Translator",
+ g_strconcat(gtranslator_header_get_translator(header), " ", "<",
+ gtranslator_header_get_tr_email(header), ">", NULL));
+ msgstr = po_header_set_field (msgstr, "Language-Team",
+ g_strconcat(gtranslator_header_get_language(header), " ", "<",
+ gtranslator_header_get_lg_email(header), ">", NULL));
+ msgstr = po_header_set_field (msgstr, "Content-Type",
+ g_strconcat(" text/plain;", " charset=", gtranslator_header_get_charset(header),NULL));
+ msgstr = po_header_set_field (msgstr, "Content-Transfer-Encoding", gtranslator_header_get_encoding(header));
+ po_message_set_msgstr (message, msgstr);
+
+ /*
+ * Let gettext do the work here
+ */
+ if(!po_file_write(gtranslator_po_get_po_file(po), name, gettext_error_handler))
+ return FALSE;
+
+ /*
+ * If we do append a suffix to the autogenerated files, then we'd
+ * also not disable the file saving entry and we don't also disable
+ * the save entry on simple compile testing -- check for filename
+ * equality.
+ */
+ /*if((GtrPreferences.autosave && GtrPreferences.autosave_with_suffix &&
+ (po->autosave_timeout > 1)) ||
+ !nautilus_strcmp(po->filename, name))
+ {
+ gtk_widget_set_sensitive(gtranslator_menuitems->save, FALSE);
+ gtk_widget_set_sensitive(gtranslator_menuitems->t_save, FALSE);
+ }*/
+
+ //po->file_changed = FALSE;
+
+ /* If user GtrPreferences to, warn it about fuzzy mesages left */
+ /*if(GtrPreferences.warn_if_fuzzy && po->fuzzy)
+ {
+ GtkWidget *dialog;
+
+ dialog = gtk_message_dialog_new(
+ GTK_WINDOW(window),
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_WARNING,
+ GTK_BUTTONS_OK,
+ ngettext("File %s\ncontains %d fuzzy message",
+ "File %s\ncontains %d fuzzy messages",
+ po->fuzzy),
+ po->filename, po->fuzzy);
+ gtk_dialog_run(GTK_DIALOG(dialog));
+ gtk_widget_destroy(dialog);
+ }*/
+
+ return TRUE;
+}
+
+/**
* gtranslator_po_get_filename:
* @po: a #GtranslatorPo
*
Modified: trunk/src/po.h
==============================================================================
--- trunk/src/po.h (original)
+++ trunk/src/po.h Mon Mar 3 18:09:57 2008
@@ -76,45 +76,50 @@
/*
* Public methods
*/
-GQuark gtranslator_po_error_quark (void);
+GQuark gtranslator_po_error_quark (void);
-GType gtranslator_po_get_type (void) G_GNUC_CONST;
+GType gtranslator_po_get_type (void) G_GNUC_CONST;
-GType gtranslator_po_register_type (GTypeModule * module);
+GType gtranslator_po_register_type (GTypeModule * module);
-GtranslatorPo *gtranslator_po_new (void);
+GtranslatorPo *gtranslator_po_new (void);
-void gtranslator_po_parse (GtranslatorPo *po,
+void gtranslator_po_parse (GtranslatorPo *po,
const gchar *filename,
GError **error);
-gchar *gtranslator_po_get_filename (GtranslatorPo *po);
+gboolean gtranslator_po_save_file (GtranslatorPo *po,
+ const gchar *name,
+ GError **error);
-void gtranslator_po_set_filename (GtranslatorPo *po,
+gchar *gtranslator_po_get_filename (GtranslatorPo *po);
+
+void gtranslator_po_set_filename (GtranslatorPo *po,
gchar *data);
-gboolean gtranslator_po_get_write_perms (GtranslatorPo *po);
+gboolean gtranslator_po_get_write_perms (GtranslatorPo *po);
-GList *gtranslator_po_get_messages (GtranslatorPo *po);
+GList *gtranslator_po_get_messages (GtranslatorPo *po);
void gtranslator_po_set_messages (GtranslatorPo *po,
- GList *messages);
+ GList *messages);
-GList *gtranslator_po_get_current_message (GtranslatorPo *po);
+GList *gtranslator_po_get_current_message (GtranslatorPo *po);
-GList *gtranslator_po_get_domains (GtranslatorPo *po);
+GList *gtranslator_po_get_domains (GtranslatorPo *po);
-po_file_t gtranslator_po_get_po_file (GtranslatorPo *po);
+po_file_t gtranslator_po_get_po_file (GtranslatorPo *po);
-GList *gtranslator_po_get_next_fuzzy (GtranslatorPo *po);
+GList *gtranslator_po_get_next_fuzzy (GtranslatorPo *po);
-GList *gtranslator_po_get_prev_fuzzy (GtranslatorPo *po);
+GList *gtranslator_po_get_prev_fuzzy (GtranslatorPo *po);
-GList *gtranslator_po_get_next_untrans (GtranslatorPo *po);
+GList *gtranslator_po_get_next_untrans (GtranslatorPo *po);
-GList *gtranslator_po_get_prev_untrans (GtranslatorPo *po);
+GList *gtranslator_po_get_prev_untrans (GtranslatorPo *po);
-GtranslatorHeader *gtranslator_po_get_header (GtranslatorPo *po);
+GtranslatorHeader
+ *gtranslator_po_get_header (GtranslatorPo *po);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]