[PATCH glib 2/2] Add framework for i18n of error message strings

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: "Daniel P. Berrange" <berrange@xxxxxxxxxx>

Signed-off-by: Daniel P. Berrange <berrange@xxxxxxxxxx>
---
 .gitignore                                   |  7 +++++
 Makefile.am                                  |  2 +-
 autogen.sh                                   | 28 ++++++------------
 configure.ac                                 |  7 +++++
 libvirt-gconfig/libvirt-gconfig-helpers.c    |  7 +++--
 libvirt-gconfig/libvirt-gconfig-object.c     | 11 +++----
 libvirt-gobject/libvirt-gobject-connection.c | 44 +++++++++++++++-------------
 libvirt-gobject/libvirt-gobject-stream.c     | 14 +++++----
 po/POTFILES.in                               |  4 +++
 9 files changed, 69 insertions(+), 55 deletions(-)
 create mode 100644 po/POTFILES.in

diff --git a/.gitignore b/.gitignore
index 8101dec..df520a1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -72,4 +72,11 @@ docs/*/*.types
 *.pc
 libvirt-gconfig/tests/test-domain-create
 libvirt-gconfig/tests/test-domain-parse
+.tx/
+po/Makefile
+po/Makefile.in
+po/Makefile.in.in
+po/POTFILES
+po/libvirt-glib.pot
+po/stamp-it
 vapi/*.vapi
diff --git a/Makefile.am b/Makefile.am
index 37d1a09..9add74e 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,5 +1,5 @@
 
-SUBDIRS = libvirt-glib libvirt-gconfig libvirt-gobject python vapi examples docs
+SUBDIRS = libvirt-glib libvirt-gconfig libvirt-gobject python vapi examples docs po
 
 ACLOCAL_AMFLAGS = -I m4
 
diff --git a/autogen.sh b/autogen.sh
index 553c3ef..bcec826 100755
--- a/autogen.sh
+++ b/autogen.sh
@@ -10,38 +10,28 @@ cd $srcdir
 
 DIE=0
 
-(autoconf --version) < /dev/null > /dev/null 2>&1 || {
+for prog in intltoolize autoreconf automake autoconf libtool
+do
+    ($prog --version) < /dev/null > /dev/null 2>&1 || {
         echo
-        echo "You must have autoconf installed to compile virt-viewer."
-        echo "Download the appropriate package for your distribution,"
-        echo "or see http://www.gnu.org/software/autoconf";
+        echo "You must have $prog installed to compile libvirt-glib."
         DIE=1
-}
-
-(automake --version) < /dev/null > /dev/null 2>&1 || {
-        echo
-        DIE=1
-        echo "You must have automake installed to compile virt-viewer."
-        echo "Download the appropriate package for your distribution,"
-        echo "or see http://www.gnu.org/software/automake";
-}
+    }
+done
 
 if test "$DIE" -eq 1; then
         exit 1
 fi
 
 if test -z "$*"; then
-        echo "I am going to run ./configure with --enable-warnings - if you "
+        echo "I am going to run ./configure with no args - if you "
         echo "wish to pass any extra arguments to it, please specify them on "
         echo "the $0 command line."
 fi
 
 mkdir -p build-aux
-libtoolize --copy --force
-aclocal -I m4
-autoheader
-automake --add-missing
-autoconf
+intltoolize --force
+autoreconf -if
 
 cd $THEDIR
 
diff --git a/configure.ac b/configure.ac
index 7b5a092..6314a7b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -60,6 +60,12 @@ PKG_CHECK_MODULES(GOBJECT2, gobject-2.0 >= $GLIB2_REQUIRED)
 PKG_CHECK_MODULES(GIO2, gio-2.0 >= $GLIB2_REQUIRED)
 PKG_CHECK_MODULES(LIBXML2, libxml-2.0 >= $LIBXML2_REQUIRED)
 
+LIBVIRT_GLIB_GETTEXT
+dnl Should be in m4/virt-gettext.m4 but intltoolize is too
+dnl dumb to find it there
+IT_PROG_INTLTOOL([0.35.0])
+
+
 GTK_DOC_CHECK([1.10],[--flavour no-tmpl])
 
 # Setup GLIB_MKENUMS to use glib-mkenums even if GLib is uninstalled.
@@ -262,6 +268,7 @@ AC_OUTPUT(Makefile
           docs/libvirt-glib/version.xml
           docs/libvirt-gobject/Makefile
           docs/libvirt-gconfig/Makefile
+          po/Makefile.in
           libvirt-glib-1.0.pc
           libvirt-gconfig-1.0.pc
           libvirt-gobject-1.0.pc
diff --git a/libvirt-gconfig/libvirt-gconfig-helpers.c b/libvirt-gconfig/libvirt-gconfig-helpers.c
index 9726dd4..4dfd246 100644
--- a/libvirt-gconfig/libvirt-gconfig-helpers.c
+++ b/libvirt-gconfig/libvirt-gconfig-helpers.c
@@ -26,6 +26,7 @@
 #include <string.h>
 
 #include <libxml/xmlerror.h>
+#include <glib/gi18n.h>
 
 #include "libvirt-gconfig/libvirt-gconfig.h"
 #include "libvirt-gconfig/libvirt-gconfig-helpers-private.h"
@@ -137,7 +138,7 @@ gvir_config_xml_parse(const char *xml, const char *root_node, GError **err)
         *err = g_error_new(GVIR_CONFIG_OBJECT_ERROR,
                            0,
                            "%s",
-                           "No XML document to parse");
+                           _("No XML document to parse"));
         return NULL;
     }
 
@@ -145,7 +146,7 @@ gvir_config_xml_parse(const char *xml, const char *root_node, GError **err)
     if (!doc) {
         gvir_config_set_error_literal(err, GVIR_CONFIG_OBJECT_ERROR,
                                       0,
-                                      "Unable to parse configuration");
+                                      _("Unable to parse configuration"));
         return NULL;
     }
     if ((!doc->children) ||
@@ -153,7 +154,7 @@ gvir_config_xml_parse(const char *xml, const char *root_node, GError **err)
         g_set_error(err,
                     GVIR_CONFIG_OBJECT_ERROR,
                     0,
-                    "XML data has no '%s' node",
+                    _("XML data has no '%s' node"),
                     root_node);
         xmlFreeDoc(doc);
         return NULL;
diff --git a/libvirt-gconfig/libvirt-gconfig-object.c b/libvirt-gconfig/libvirt-gconfig-object.c
index c3228c8..d8ca520 100644
--- a/libvirt-gconfig/libvirt-gconfig-object.c
+++ b/libvirt-gconfig/libvirt-gconfig-object.c
@@ -26,6 +26,7 @@
 #include <string.h>
 
 #include <libxml/relaxng.h>
+#include <glib/gi18n.h>
 
 #include "libvirt-gconfig/libvirt-gconfig.h"
 #include "libvirt-gconfig/libvirt-gconfig-private.h"
@@ -208,7 +209,7 @@ void gvir_config_object_validate(GVirConfigObject *config,
         gvir_config_set_error_literal(err,
                                       GVIR_CONFIG_OBJECT_ERROR,
                                       0,
-                                      "No XML document associated with this config object");
+                                      _("No XML document associated with this config object"));
         return;
     }
 
@@ -217,7 +218,7 @@ void gvir_config_object_validate(GVirConfigObject *config,
         gvir_config_set_error(err,
                               GVIR_CONFIG_OBJECT_ERROR,
                               0,
-                              "Unable to create RNG parser for %s",
+                              _("Unable to create RNG parser for %s"),
                               priv->schema);
         return;
     }
@@ -227,7 +228,7 @@ void gvir_config_object_validate(GVirConfigObject *config,
         gvir_config_set_error(err,
                               GVIR_CONFIG_OBJECT_ERROR,
                               0,
-                              "Unable to parse RNG %s",
+                              _("Unable to parse RNG %s"),
                               priv->schema);
         xmlRelaxNGFreeParserCtxt(rngParser);
         return;
@@ -239,7 +240,7 @@ void gvir_config_object_validate(GVirConfigObject *config,
         gvir_config_set_error(err,
                               GVIR_CONFIG_OBJECT_ERROR,
                               0,
-                              "Unable to create RNG validation context %s",
+                              _("Unable to create RNG validation context %s"),
                               priv->schema);
         xmlRelaxNGFree(rng);
         return;
@@ -249,7 +250,7 @@ void gvir_config_object_validate(GVirConfigObject *config,
         gvir_config_set_error_literal(err,
                                       GVIR_CONFIG_OBJECT_ERROR,
                                       0,
-                                      "Unable to validate doc");
+                                      _("Unable to validate doc"));
         xmlRelaxNGFreeValidCtxt(rngValid);
         xmlRelaxNGFree(rng);
         return;
diff --git a/libvirt-gobject/libvirt-gobject-connection.c b/libvirt-gobject/libvirt-gobject-connection.c
index ecf7cb2..a05b5a0 100644
--- a/libvirt-gobject/libvirt-gobject-connection.c
+++ b/libvirt-gobject/libvirt-gobject-connection.c
@@ -26,6 +26,8 @@
 #include <libvirt/libvirt.h>
 #include <string.h>
 
+#include <glib/gi18n.h>
+
 #include "libvirt-glib/libvirt-glib.h"
 #include "libvirt-gobject/libvirt-gobject.h"
 #include "libvirt-gobject-compat.h"
@@ -429,7 +431,7 @@ static gboolean _gvir_connection_open(GVirConnection *conn,
     if (priv->conn) {
         g_set_error(err, GVIR_CONNECTION_ERROR,
                     0,
-                    "Connection %s is already open",
+                    _("Connection %s is already open"),
                     priv->uri);
         g_mutex_unlock(priv->lock);
         return FALSE;
@@ -444,7 +446,7 @@ static gboolean _gvir_connection_open(GVirConnection *conn,
     if (!priv->conn) {
         gvir_set_error(err, GVIR_CONNECTION_ERROR,
                        0,
-                       "Unable to open %s",
+                       _("Unable to open %s"),
                        priv->uri);
         g_mutex_unlock(priv->lock);
         return FALSE;
@@ -454,8 +456,8 @@ static gboolean _gvir_connection_open(GVirConnection *conn,
         char *uri = virConnectGetURI(priv->conn);
         if (!uri) {
             gvir_set_error_literal(err, GVIR_CONNECTION_ERROR,
-                           0,
-                           "Unable to get connection URI");
+                                   0,
+                                   _("Unable to get connection URI"));
             virConnectClose(priv->conn);
             priv->conn = NULL;
             g_mutex_unlock(priv->lock);
@@ -696,7 +698,7 @@ static gchar ** fetch_list(virConnectPtr vconn,
     if ((n = count_func(vconn)) < 0) {
         gvir_set_error(err, GVIR_CONNECTION_ERROR,
                        0,
-                       "Unable to count %s", name);
+                       _("Unable to count %s"), name);
         goto error;
     }
 
@@ -708,7 +710,7 @@ static gchar ** fetch_list(virConnectPtr vconn,
         if ((n = list_func(vconn, lst, n)) < 0) {
             gvir_set_error(err, GVIR_CONNECTION_ERROR,
                            0,
-                           "Unable to list %s %d", name, n);
+                           _("Unable to list %s %d"), name, n);
             goto error;
         }
     }
@@ -755,7 +757,7 @@ gboolean gvir_connection_fetch_domains(GVirConnection *conn,
     if (!priv->conn) {
         g_set_error_literal(err, GVIR_CONNECTION_ERROR,
                             0,
-                            "Connection is not open");
+                            _("Connection is not open"));
         g_mutex_unlock(priv->lock);
         goto cleanup;
     }
@@ -770,7 +772,7 @@ gboolean gvir_connection_fetch_domains(GVirConnection *conn,
     if ((nactive = virConnectNumOfDomains(vconn)) < 0) {
         gvir_set_error_literal(err, GVIR_CONNECTION_ERROR,
                                0,
-                               "Unable to count domains");
+                               _("Unable to count domains"));
         goto cleanup;
     }
     if (nactive) {
@@ -781,7 +783,7 @@ gboolean gvir_connection_fetch_domains(GVirConnection *conn,
         if ((nactive = virConnectListDomains(vconn, active, nactive)) < 0) {
             gvir_set_error_literal(err, GVIR_CONNECTION_ERROR,
                                    0,
-                                   "Unable to list domains");
+                                   _("Unable to list domains"));
             goto cleanup;
         }
     }
@@ -892,7 +894,7 @@ gboolean gvir_connection_fetch_storage_pools(GVirConnection *conn,
     if (!priv->conn) {
         g_set_error_literal(err, GVIR_CONNECTION_ERROR,
                             0,
-                            "Connection is not open");
+                            _("Connection is not open"));
         g_mutex_unlock(priv->lock);
         goto cleanup;
     }
@@ -1155,14 +1157,14 @@ gvir_connection_get_hypervisor_name(GVirConnection *conn,
     priv = conn->priv;
     if (!priv->conn) {
         g_set_error_literal(err, GVIR_CONNECTION_ERROR, 0,
-                            "Connection is not opened");
+                            _("Connection is not opened"));
         goto cleanup;
     }
 
     type = virConnectGetType(priv->conn);
     if (!type) {
         gvir_set_error_literal(err, GVIR_CONNECTION_ERROR, 0,
-                               "Unable to get hypervisor name");
+                               _("Unable to get hypervisor name"));
         goto cleanup;
     }
 
@@ -1194,13 +1196,13 @@ gvir_connection_get_version(GVirConnection *conn,
     priv = conn->priv;
     if (!priv->conn) {
         g_set_error_literal(err, GVIR_CONNECTION_ERROR, 0,
-                            "Connection is not opened");
+                            _("Connection is not opened"));
         goto cleanup;
     }
 
     if (virConnectGetVersion(priv->conn, &ret) < 0) {
         gvir_set_error_literal(err, GVIR_CONNECTION_ERROR, 0,
-                               "Unable to get hypervisor version");
+                               _("Unable to get hypervisor version"));
     }
 
 cleanup:
@@ -1515,7 +1517,7 @@ GVirDomain *gvir_connection_create_domain(GVirConnection *conn,
     if (!handle) {
         gvir_set_error_literal(err, GVIR_CONNECTION_ERROR,
                                0,
-                               "Failed to create domain");
+                               _("Failed to create domain"));
         return NULL;
     }
 
@@ -1570,7 +1572,7 @@ GVirDomain *gvir_connection_start_domain(GVirConnection *conn,
     if (!handle) {
         gvir_set_error_literal(err, GVIR_CONNECTION_ERROR,
                                0,
-                               "Failed to create domain");
+                               _("Failed to create domain"));
         return NULL;
     }
 
@@ -1622,7 +1624,7 @@ GVirStoragePool *gvir_connection_create_storage_pool
     if (!(handle = virStoragePoolDefineXML(priv->conn, xml, flags))) {
         gvir_set_error_literal(err, GVIR_CONNECTION_ERROR,
                                flags,
-                               "Failed to create storage pool");
+                               _("Failed to create storage pool"));
         return NULL;
     }
 
@@ -1665,7 +1667,7 @@ GVirNodeInfo *gvir_connection_get_node_info(GVirConnection *conn,
     if (virNodeGetInfo(priv->conn, &info) < 0) {
         gvir_set_error_literal(err, GVIR_CONNECTION_ERROR,
                                0,
-                               "Unable to get node info");
+                               _("Unable to get node info"));
         return NULL;
     }
 
@@ -1705,7 +1707,7 @@ GVirConfigCapabilities *gvir_connection_get_capabilities(GVirConnection *conn,
     if (caps_xml == NULL) {
         gvir_set_error_literal(err, GVIR_CONNECTION_ERROR,
                                0,
-                               "Unable to get capabilities");
+                               _("Unable to get capabilities"));
         return NULL;
     }
 
@@ -1832,8 +1834,8 @@ gboolean gvir_connection_restore_domain_from_file(GVirConnection *conn,
 
     if (ret < 0) {
         gvir_set_error_literal(err, GVIR_CONNECTION_ERROR,
-                              0,
-                              "Unable to restore domain");
+                               0,
+                               _("Unable to restore domain"));
 
        return FALSE;
     }
diff --git a/libvirt-gobject/libvirt-gobject-stream.c b/libvirt-gobject/libvirt-gobject-stream.c
index a75769e..af9b8a0 100644
--- a/libvirt-gobject/libvirt-gobject-stream.c
+++ b/libvirt-gobject/libvirt-gobject-stream.c
@@ -27,6 +27,8 @@
 #include <libvirt/virterror.h>
 #include <string.h>
 
+#include <glib/gi18n.h>
+
 #include "libvirt-glib/libvirt-glib.h"
 #include "libvirt-gobject/libvirt-gobject.h"
 #include "libvirt-gobject-compat.h"
@@ -320,10 +322,10 @@ gssize gvir_stream_receive(GVirStream *self,
 
     if (got == -2) {  /* blocking */
         g_set_error_literal(error, G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK,
-                            "virStreamRecv call would block");
+                            _("virStreamRecv call would block"));
     } else if (got < 0) {
         g_set_error(error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT,
-                    "Got virStreamRecv error in %s", G_STRFUNC);
+                    _("Got virStreamRecv error in %s"), G_STRFUNC);
     }
 
     return got;
@@ -388,7 +390,7 @@ gvir_stream_receive_all(GVirStream *self,
     if (r < 0) {
         gvir_set_error_literal(error, GVIR_STREAM_ERROR,
                                0,
-                               "Unable to perform RecvAll");
+                               _("Unable to perform RecvAll"));
     }
 
     return r;
@@ -436,10 +438,10 @@ gssize gvir_stream_send(GVirStream *self,
 
     if (got == -2) {  /* blocking */
         g_set_error_literal(error, G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK,
-                            "virStreamSend call would block");
+                            _("virStreamSend call would block"));
     } else if (got < 0) {
         g_set_error(error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT,
-                    "Got virStreamRecv error in %s", G_STRFUNC);
+                    _("Got virStreamRecv error in %s"), G_STRFUNC);
     }
 
     return got;
@@ -504,7 +506,7 @@ gvir_stream_send_all(GVirStream *self,
     if (r < 0) {
         gvir_set_error_literal(error, GVIR_STREAM_ERROR,
                                0,
-                               "Unable to perform SendAll");
+                               _("Unable to perform SendAll"));
     }
 
     return r;
diff --git a/po/POTFILES.in b/po/POTFILES.in
new file mode 100644
index 0000000..335ec67
--- /dev/null
+++ b/po/POTFILES.in
@@ -0,0 +1,4 @@
+libvirt-gconfig/libvirt-gconfig-helpers.c
+libvirt-gconfig/libvirt-gconfig-object.c
+libvirt-gobject/libvirt-gobject-connection.c
+libvirt-gobject/libvirt-gobject-stream.c
-- 
1.8.1.4

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]