Set locale in C programs so l10n works (RHBZ#559962).
authorRichard Jones <rjones@redhat.com>
Fri, 29 Jan 2010 14:56:13 +0000 (14:56 +0000)
committerRichard Jones <rjones@redhat.com>
Fri, 29 Jan 2010 15:11:59 +0000 (15:11 +0000)
This commit adds the calls to setlocale &c to all of the current
C programs.

It also adds l10n support to hivexget and hivexml which lacked them
previously.

To test this, try:

LANG=pa_IN.UTF-8 guestfish --cmd-help

(You can only do this test after installing the package, or at
least the 'pa.mo' mo-file in the correct place).

fish/Makefile.am
fish/fish.c
fuse/Makefile.am
fuse/guestmount.c
hivex/Makefile.am
hivex/hivexget.c
hivex/hivexml.c
test-tool/Makefile.am
test-tool/test-tool.c

index d817e6c..43dce00 100644 (file)
@@ -59,6 +59,7 @@ guestfish_CFLAGS = \
        -I$(top_srcdir)/src -I$(top_builddir)/src \
        -I$(top_srcdir)/fish -I$(top_builddir)/fish \
        -DGUESTFS_DEFAULT_PATH='"$(libdir)/guestfs"' \
+       -DLOCALEBASEDIR=\""$(datadir)/locale"\" \
        -I$(srcdir)/../gnulib/lib -I../gnulib/lib \
        $(WARN_CFLAGS) $(WERROR_CFLAGS)
 
index 7dae815..dd73af7 100644 (file)
@@ -139,6 +139,10 @@ main (int argc, char *argv[])
 
   atexit (close_stdout);
 
+  setlocale (LC_ALL, "");
+  bindtextdomain (PACKAGE, LOCALEBASEDIR);
+  textdomain (PACKAGE);
+
   enum { HELP_OPTION = CHAR_MAX + 1 };
 
   static const char *options = "a:Df:h::im:nrv?Vx";
index 5ffdb95..1bfc375 100644 (file)
@@ -33,6 +33,7 @@ guestmount_CFLAGS = \
        -I$(top_srcdir)/src -I$(top_builddir)/src \
        -I$(srcdir)/../gnulib/lib -I../gnulib/lib \
        -DGUESTFS_DEFAULT_PATH='"$(libdir)/guestfs"' \
+       -DLOCALEBASEDIR=\""$(datadir)/locale"\" \
        $(FUSE_CFLAGS) \
        $(WARN_CFLAGS) $(WERROR_CFLAGS)
 
index 9f0a39e..c935493 100644 (file)
@@ -896,6 +896,10 @@ usage (int status)
 int
 main (int argc, char *argv[])
 {
+  setlocale (LC_ALL, "");
+  bindtextdomain (PACKAGE, LOCALEBASEDIR);
+  textdomain (PACKAGE);
+
   enum { HELP_OPTION = CHAR_MAX + 1 };
 
   /* The command line arguments are broadly compatible with (a subset
index b73aa2f..31275ea 100644 (file)
@@ -34,6 +34,8 @@ hivexml_SOURCES = \
 
 hivexml_LDADD = libhivex.la $(LIBXML2_LIBS)
 hivexml_CFLAGS = \
+  -I$(top_srcdir)/src \
+  -DLOCALEBASEDIR=\""$(datadir)/locale"\" \
   $(LIBXML2_CFLAGS) \
   $(WARN_CFLAGS) $(WERROR_CFLAGS)
 
@@ -42,6 +44,8 @@ hivexget_SOURCES = \
 
 hivexget_LDADD = libhivex.la
 hivexget_CFLAGS = \
+  -I$(top_srcdir)/src \
+  -DLOCALEBASEDIR=\""$(datadir)/locale"\" \
   $(WARN_CFLAGS) $(WERROR_CFLAGS)
 
 man_MANS = hivex.3 hivexml.1 hivexget.1
index 3e89d63..fd49293 100644 (file)
 
 #include "hivex.h"
 
+#ifdef HAVE_GETTEXT
+#include "gettext.h"
+#define _(str) dgettext(PACKAGE, (str))
+//#define N_(str) dgettext(PACKAGE, (str))
+#else
+#define _(str) str
+//#define N_(str) str
+#endif
+
 enum { EXIT_NOT_FOUND = 2 };
 
 int
 main (int argc, char *argv[])
 {
+  setlocale (LC_ALL, "");
+  bindtextdomain (PACKAGE, LOCALEBASEDIR);
+  textdomain (PACKAGE);
+
   if (argc < 3 || argc > 4) {
-    fprintf (stderr, "hivexget regfile path [key]\n");
+    fprintf (stderr, _("hivexget regfile path [key]\n"));
     exit (EXIT_FAILURE);
   }
+
   char *file = argv[1];
   char *path = argv[2];
   char *key = argv[3];          /* could be NULL */
 
   if (path[0] != '\\') {
-    fprintf (stderr, "hivexget: path must start with a \\ character\n");
+    fprintf (stderr, _("hivexget: path must start with a \\ character\n"));
     exit (EXIT_FAILURE);
   }
   if (path[1] == '\\') {
   doubled:
-    fprintf (stderr, "hivexget: %s: \\ characters in path are doubled - are you escaping the path parameter correctly?\n", path);
+    fprintf (stderr, _("hivexget: %s: \\ characters in path are doubled - are you escaping the path parameter correctly?\n"), path);
     exit (EXIT_FAILURE);
   }
 
@@ -82,7 +96,7 @@ main (int argc, char *argv[])
       if (errno)
         goto error;
       /* else node not found */
-      fprintf (stderr, "hivexget: %s: %s: path element not found\n",
+      fprintf (stderr, _("hivexget: %s: %s: path element not found\n"),
                path, p);
       exit (EXIT_NOT_FOUND);
     }
@@ -104,7 +118,7 @@ main (int argc, char *argv[])
       if (errno)
         goto error;
       /* else key not found */
-      fprintf (stderr, "hivexget: %s: key not found\n", key);
+      fprintf (stderr, _("hivexget: %s: key not found\n"), key);
       exit (EXIT_NOT_FOUND);
     }
 
index 7fb419f..90cb22b 100644 (file)
 
 #include "hivex.h"
 
+#ifdef HAVE_GETTEXT
+#include "gettext.h"
+#define _(str) dgettext(PACKAGE, (str))
+//#define N_(str) dgettext(PACKAGE, (str))
+#else
+#define _(str) str
+//#define N_(str) str
+#endif
+
 /* Callback functions. */
 static int node_start (hive_h *, void *, hive_node_h, const char *name);
 static int node_end (hive_h *, void *, hive_node_h, const char *name);
@@ -58,14 +67,18 @@ static struct hivex_visitor visitor = {
 #define XML_CHECK(proc, args)                                           \
   do {                                                                  \
     if ((proc args) == -1) {                                            \
-      fprintf (stderr, "%s: failed to write XML document\n", #proc);    \
-      exit (EXIT_FAILURE);                                                         \
+      fprintf (stderr, _("%s: failed to write XML document\n"), #proc); \
+      exit (EXIT_FAILURE);                                              \
     }                                                                   \
   } while (0)
 
 int
 main (int argc, char *argv[])
 {
+  setlocale (LC_ALL, "");
+  bindtextdomain (PACKAGE, LOCALEBASEDIR);
+  textdomain (PACKAGE);
+
   int c;
   int open_flags = 0;
   int visit_flags = 0;
@@ -85,7 +98,7 @@ main (int argc, char *argv[])
   }
 
   if (optind + 1 != argc) {
-    fprintf (stderr, "hivexml: missing name of input file\n");
+    fprintf (stderr, _("hivexml: missing name of input file\n"));
     exit (EXIT_FAILURE);
   }
 
@@ -104,7 +117,7 @@ main (int argc, char *argv[])
   xmlTextWriterPtr writer;
   writer = xmlNewTextWriterFilename ("/dev/stdout", 0);
   if (writer == NULL) {
-    fprintf (stderr, "xmlNewTextWriterFilename: failed to create XML writer\n");
+    fprintf (stderr, _("xmlNewTextWriterFilename: failed to create XML writer\n"));
     exit (EXIT_FAILURE);
   }
 
index d58f137..66d06e0 100644 (file)
@@ -30,6 +30,7 @@ AM_CPPFLAGS = \
 
 libguestfs_test_tool_SOURCES = test-tool.c
 libguestfs_test_tool_CFLAGS = \
+       -DLOCALEBASEDIR=\""$(datadir)/locale"\" \
        -I$(top_srcdir)/src -I$(top_builddir)/src \
        -Wall
 libguestfs_test_tool_LDADD = \
index f38490a..39139e5 100644 (file)
@@ -85,6 +85,10 @@ usage (void)
 int
 main (int argc, char *argv[])
 {
+  setlocale (LC_ALL, "");
+  bindtextdomain (PACKAGE, LOCALEBASEDIR);
+  textdomain (PACKAGE);
+
   static const char *options = "t:?";
   static const struct option long_options[] = {
     { "help", 0, 0, '?' },