[Spice-devel] [PATCH spice-gtk v2] Make error messages translatable

Pavel Grunt pgrunt at redhat.com
Tue Jul 11 07:21:53 UTC 2017


---
v2:
 - Use ngettext for error messages in plural
 - rebased on top of Victor's patch
---
 po/POTFILES.in                 | 4 ++++
 src/channel-main.c             | 9 +++++++--
 src/channel-port.c             | 4 +++-
 src/channel-usbredir.c         | 2 +-
 src/smartcard-manager.c        | 5 +++--
 src/spice-channel.c            | 2 +-
 src/spice-file-transfer-task.c | 6 ++++--
 src/spice-pulse.c              | 4 +++-
 8 files changed, 26 insertions(+), 10 deletions(-)

diff --git a/po/POTFILES.in b/po/POTFILES.in
index d1033f9..5f438b5 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -1,8 +1,12 @@
 src/channel-main.c
+src/channel-port.c
 src/channel-usbredir.c
 src/desktop-integration.c
+src/smartcard-manager.c
 src/spice-channel.c
+src/spice-file-transfer-task.c
 src/spice-option.c
+src/spice-pulse.c
 src/usb-device-manager.c
 src/usb-device-widget.c
 src/usbutil.c
diff --git a/src/channel-main.c b/src/channel-main.c
index 68ec62e..c035ce1 100644
--- a/src/channel-main.c
+++ b/src/channel-main.c
@@ -17,6 +17,7 @@
 */
 #include "config.h"
 
+#include <libintl.h>
 #include <math.h>
 #include <spice/vd_agent.h>
 #include <glib/gstdio.h>
@@ -2906,12 +2907,16 @@ failed:
 
 static void file_transfer_operation_free(FileTransferOperation *xfer_op)
 {
+    const char *error_summary_fmt;
     g_return_if_fail(xfer_op != NULL);
 
+    error_summary_fmt = ngettext(_("Transferring %u file: %u succeed, %u cancelled, %u failed"),
+                                 _("Transferring %u files: %u succeed, %u cancelled, %u failed"),
+                                 xfer_op->stats.num_files);
     if (xfer_op->stats.failed != 0) {
         GError *error = g_error_new(SPICE_CLIENT_ERROR,
                                     SPICE_CLIENT_ERROR_FAILED,
-                                    _("Transferring %u files: %u succeed, %u cancelled, %u failed"),
+                                    error_summary_fmt,
                                     xfer_op->stats.num_files,
                                     xfer_op->stats.succeed,
                                     xfer_op->stats.cancelled,
@@ -2921,7 +2926,7 @@ static void file_transfer_operation_free(FileTransferOperation *xfer_op)
     } else if (xfer_op->stats.cancelled != 0 && xfer_op->stats.succeed == 0) {
         GError *error = g_error_new(G_IO_ERROR,
                                     G_IO_ERROR_CANCELLED,
-                                    _("Transferring %u files: %u succeed, %u cancelled, %u failed"),
+                                    error_summary_fmt,
                                     xfer_op->stats.num_files,
                                     xfer_op->stats.succeed,
                                     xfer_op->stats.cancelled,
diff --git a/src/channel-port.c b/src/channel-port.c
index d922e4b..9fb7f05 100644
--- a/src/channel-port.c
+++ b/src/channel-port.c
@@ -17,6 +17,8 @@
 */
 #include "config.h"
 
+#include <glib/gi18n-lib.h>
+
 #include "spice-client.h"
 #include "spice-common.h"
 #include "spice-channel-priv.h"
@@ -294,7 +296,7 @@ void spice_port_write_async(SpicePortChannel *self,
         g_task_report_new_error(self, callback,
             user_data, spice_port_write_async,
             SPICE_CLIENT_ERROR, SPICE_CLIENT_ERROR_FAILED,
-            "The port is not opened");
+            _("The port is not opened"));
         return;
     }
 
diff --git a/src/channel-usbredir.c b/src/channel-usbredir.c
index fef62ce..f8a5234 100644
--- a/src/channel-usbredir.c
+++ b/src/channel-usbredir.c
@@ -348,7 +348,7 @@ static void spice_usbredir_channel_open_acl_cb(
     spice_usb_acl_helper_open_acl_finish(acl_helper, acl_res, &err);
     if (!err && priv->state == STATE_DISCONNECTING) {
         err = g_error_new_literal(G_IO_ERROR, G_IO_ERROR_CANCELLED,
-                                  "USB redirection channel connect cancelled");
+                                  _("USB redirection channel connect cancelled"));
     }
     if (!err) {
         spice_usbredir_channel_open_device(channel, &err);
diff --git a/src/smartcard-manager.c b/src/smartcard-manager.c
index 708f976..05e113d 100644
--- a/src/smartcard-manager.c
+++ b/src/smartcard-manager.c
@@ -18,6 +18,7 @@
 #include "config.h"
 
 #include <glib-object.h>
+#include <glib/gi18n-lib.h>
 #include <string.h>
 
 #ifdef USE_SMARTCARD_012
@@ -439,7 +440,7 @@ static gboolean smartcard_manager_init(SmartcardManagerInitArgs *args)
     if (options == NULL) {
         args->err = g_error_new(SPICE_CLIENT_ERROR,
                                 SPICE_CLIENT_ERROR_FAILED,
-                                "vcard_emul_options() failed!");
+                                _("vcard_emul_options() failed!"));
         goto end;
     }
 
@@ -453,7 +454,7 @@ init:
             && (emul_init_status != VCARD_EMUL_INIT_ALREADY_INITED)) {
         args->err = g_error_new(SPICE_CLIENT_ERROR,
                                 SPICE_CLIENT_ERROR_FAILED,
-                                "Failed to initialize smartcard");
+                                _("Failed to initialize smartcard"));
         goto end;
     }
 
diff --git a/src/spice-channel.c b/src/spice-channel.c
index 4c3db9d..9d720ab 100644
--- a/src/spice-channel.c
+++ b/src/spice-channel.c
@@ -3138,7 +3138,7 @@ void spice_channel_flush_async(SpiceChannel *self, GCancellable *cancellable,
         g_task_report_new_error(self, callback, user_data,
             spice_channel_flush_async,
             SPICE_CLIENT_ERROR, SPICE_CLIENT_ERROR_FAILED,
-            "The channel is not ready yet");
+            _("The channel is not ready yet"));
         return;
     }
 
diff --git a/src/spice-file-transfer-task.c b/src/spice-file-transfer-task.c
index d0170da..46165f7 100644
--- a/src/spice-file-transfer-task.c
+++ b/src/spice-file-transfer-task.c
@@ -17,6 +17,8 @@
 
 #include "config.h"
 
+#include <glib/gi18n-lib.h>
+
 #include "spice-file-transfer-task-priv.h"
 
 /**
@@ -310,7 +312,7 @@ void spice_file_transfer_task_completed(SpiceFileTransferTask *self,
         if (self->error == NULL) {
             self->error = g_error_new(SPICE_CLIENT_ERROR,
                                       SPICE_CLIENT_ERROR_FAILED,
-                                      "Cannot complete task in pending state");
+                                      _("Cannot complete task in pending state"));
         }
         return;
     }
@@ -426,7 +428,7 @@ void spice_file_transfer_task_read_async(SpiceFileTransferTask *self,
                                 spice_file_transfer_task_read_async,
                                 SPICE_CLIENT_ERROR,
                                 SPICE_CLIENT_ERROR_FAILED,
-                                "Cannot read data in pending state");
+                                _("Cannot read data in pending state"));
         return;
     }
 
diff --git a/src/spice-pulse.c b/src/spice-pulse.c
index 5248bc3..f213f5f 100644
--- a/src/spice-pulse.c
+++ b/src/spice-pulse.c
@@ -17,6 +17,8 @@
 */
 #include "config.h"
 
+#include <glib/gi18n-lib.h>
+
 #include "spice-pulse.h"
 #include "spice-common.h"
 #include "spice-session-priv.h"
@@ -1216,7 +1218,7 @@ fail:
                                 pulse_stream_restore_info_async,
                                 SPICE_CLIENT_ERROR,
                                 SPICE_CLIENT_ERROR_FAILED,
-                                "Volume-Info failed: %s",
+                                _("Volume-Info failed: %s"),
                                 pa_strerror(pa_context_errno(p->context)));
         free_async_task(task);
     }
-- 
2.13.0



More information about the Spice-devel mailing list