[PATCH] i18n/l10n of gvfs-cat

View: New views
7 Messages — Rating Filter:   Alert me  

[PATCH] i18n/l10n of gvfs-cat

by Luca Ferretti :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I'm starting provide i18n/l10n to gvfs programs (gvfs-[cat|copy|
less...]).

Here is the initial work on gvfs-cat. Some comments on changes...

Index: programs/Makefile.am
===================================================================
--- programs/Makefile.am (revisione 1087)
+++ programs/Makefile.am (copia locale)
@@ -1,30 +1,31 @@
 NULL =
 
-INCLUDES = \
- -I$(top_srcdir) \
- -I$(top_builddir) \
- $(GLIB_CFLAGS) \
+INCLUDES = \
+ -I$(top_srcdir) \
+ -I$(top_builddir) \
+ $(GLIB_CFLAGS) \
+ -DGVFS_LOCALEDIR=\""$(localedir)"\" \
  -DG_DISABLE_DEPRECATED

        Define and use GVFS_LOCALEDIR in order to get translations, of course

Index: programs/gvfs-cat.c
===================================================================
--- programs/gvfs-cat.c (revisione 1087)
+++ programs/gvfs-cat.c (copia locale)
@@ -28,10 +28,14 @@
 #include <errno.h>
 
 #include <glib.h>
+#include <glib/gi18n.h>
 #include <gio/gio.h>
 
+static gchar **locations = NULL;
+
 static GOptionEntry entries[] =
 {
+ {G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, &locations, "locations", NULL},
  { NULL }
 };
 
        Added a "locations" option entry. Note that gvfs-cat don't use
        any command line option, this is useful below to check if you
        are providing a location to cat an print a warning message.
       
        Note also that, from Glib API refs: "Using G_OPTION_REMAINING
        instead of simply scanning argv for leftover arguments has the
        advantage that GOption takes care of necessary encoding
        conversions for strings or filenames." See below for this too.
       
        I've just a doubt: GOption API provides
        G_OPTION_ARG_STRING_ARRAY and G_OPTION_ARG_FILENAME_ARRAY types.
        Now that GIO is in glib, shouldn't G_OPTION_ARG_FILENAME_ARRAY
        be able to manage URIs?


-  context = g_option_context_new ("- output files at <location>");
+  /* Translators: this message will appear immediately after the */
+  /* usage string - Usage: COMMAND [OPTION]... <THIS_MESSAGE>    */
+  context = g_option_context_new (_("LOCATION... - concatenate LOCATIONS to standard output"));
+  
+  /* Translators: this message will appear after the usage string */
+  /* and before the list of options.                              */
+  summary = g_strconcat (_("Concatenate files at locations and print "
+   "to the standard output. Works just like "
+   "the traditional cat utility, but using "
+   "gvfs location instead locale files: for "
+   "example you can use something like "
+   "smb://server/resource/file.txt "
+   "as location to concatenate."),
+ "\n\n",
+ _("Note: none of the cat option is supported."),
+ NULL);
+
+  g_option_context_set_summary (context, summary);

        Changed the usage string to match GNU tools standards and cat(1)
        --help, added a summary explaining more stuff. Please review and
        suggest better phrase (for example is "using gvfs location" a
        proper description? is "concatenate LOCATIONS and print")


-  
-  if (argc > 1)
+  g_free (summary);
+
+  if (!locations)
     {
-      int i;
-      
-      for (i = 1; i < argc; i++) {
- file = g_file_new_for_commandline_arg (argv[i]);
- cat (file);
- g_object_unref (file);
-      }
+  g_printerr (_("%s: missing locations"), argv[0]);
+  g_printerr ("\n");
+  g_printerr (_("Try \"%s --help\" for more information."), argv[0]);
+  g_printerr ("\n");
+  return 1;
     }

        Use locations option to check if we have any location to cat.
       
        Of course this breaks the cat(1) behavior, but I think you
        should use cat(1) if you simply need to concatenate stdin to
        stdout...


+  int i = 0;
+
+  do {
+  file = g_file_new_for_commandline_arg (locations[i]);
+  cat (file);
+  g_object_unref (file);
+  } while (locations[++i]!=NULL) ;
+
   return 0;
 }

        Also use the locations option to pass URI to cat; changed the
        previous `for` with a `do..while`
       
       

A final note about error messages: currently gvfs-cat prints something
like:

        $ gvfs-cat smb://server/file.txt
        Error opening file: No such file or directory
       
IMHO could be better prepend the program name and the file name (this is
the behavior of plain cat(1))

        $ gvfs-cat smb://server/file.txt
        gvfs-cat: smb://server/file.txt: No such file or directory

PS of course could be interesting add some cat(1) options, such as -n
(number all output lines), -E (display $ at end of each line), -T
(display TAB characters as ^I) and -s (never more than one single blank
line). OK to open a bug and add commented GOptionExtry copying switch
and comments from `cat --help`?

PPS the Italian translation is updated in attached patch, so you can run
`LANG=it LANGUAGE=it gvfs-cat --help` and see the message translated.


_______________________________________________
gnome-vfs-list mailing list
gnome-vfs-list@...
http://mail.gnome.org/mailman/listinfo/gnome-vfs-list

gvfs-cat-i18n.diff.gz (10K) Download Attachment

Re: [PATCH] i18n/l10n of gvfs-cat

by Alexander Larsson :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On Thu, 2008-01-10 at 14:15 +0100, Luca Ferretti wrote:

> Index: programs/gvfs-cat.c
> ===================================================================
> --- programs/gvfs-cat.c (revisione 1087)
> +++ programs/gvfs-cat.c (copia locale)
> @@ -28,10 +28,14 @@
>  #include <errno.h>
>  
>  #include <glib.h>
> +#include <glib/gi18n.h>
>  #include <gio/gio.h>
>  
> +static gchar **locations = NULL;
> +
>  static GOptionEntry entries[] =
>  {
> + {G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, &locations, "locations", NULL},
>   { NULL }
>  };
>  
>         Added a "locations" option entry. Note that gvfs-cat don't use
>         any command line option, this is useful below to check if you
>         are providing a location to cat an print a warning message.
>        
>         Note also that, from Glib API refs: "Using G_OPTION_REMAINING
>         instead of simply scanning argv for leftover arguments has the
>         advantage that GOption takes care of necessary encoding
>         conversions for strings or filenames." See below for this too.

It looks like what G_OPTION_ARG_FILENAME does is convert from locale to
utf8 on windows and just strcpy on unix, while ARG_STRING always
converts from locale to utf8. So, using string here is wrong, and
FILENAME is ok also for uris (as they are ascii-only).


> A final note about error messages: currently gvfs-cat prints something
> like:
>
>         $ gvfs-cat smb://server/file.txt
>         Error opening file: No such file or directory
>        
> IMHO could be better prepend the program name and the file name (this is
> the behavior of plain cat(1))
>
>         $ gvfs-cat smb://server/file.txt
>         gvfs-cat: smb://server/file.txt: No such file or directory

Yeah, that looks better.

> PS of course could be interesting add some cat(1) options, such as -n
> (number all output lines), -E (display $ at end of each line), -T
> (display TAB characters as ^I) and -s (never more than one single blank
> line). OK to open a bug and add commented GOptionExtry copying switch
> and comments from `cat --help`?

Well. You could also just pipe through cat if you need these?

_______________________________________________
gnome-vfs-list mailing list
gnome-vfs-list@...
http://mail.gnome.org/mailman/listinfo/gnome-vfs-list

Re: [PATCH] i18n/l10n of gvfs-cat

by Luca Ferretti :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Il giorno gio, 10/01/2008 alle 15.15 +0100, Alexander Larsson ha
scritto:
> It looks like what G_OPTION_ARG_FILENAME does is convert from locale to
> utf8 on windows and just strcpy on unix, while ARG_STRING always
> converts from locale to utf8. So, using string here is wrong, and
> FILENAME is ok also for uris (as they are ascii-only).

OK, converted to G_OPTION_ARG_FILENAME


> > IMHO could be better prepend the program name and the file name (this is
> > the behavior of plain cat(1))
> >
> >         $ gvfs-cat smb://server/file.txt
> >         gvfs-cat: smb://server/file.txt: No such file or directory
>
> Yeah, that looks better.

Done. The only issue is that now the actual output is something like:

        gvfs-cat: uri:///file/name.ext: error opening file: Error
        opening file: No such file or directory
       
:-(

Do I've to remove "error opening file" from gvfs-cat?

> > PS of course could be interesting add some cat(1) options, such as -n
> > (number all output lines), -E (display $ at end of each line), -T
> > (display TAB characters as ^I) and -s (never more than one single blank
> > line). OK to open a bug and add commented GOptionExtry copying switch
> > and comments from `cat --help`?
>
> Well. You could also just pipe through cat if you need these?
>

Changed the note tip suggesting the pipe.

Note 1: there was a perror("Error writing to stdout"), I changed to
g_printerr

Note 2: yeah, there are some wrong indentations I'll fix before commit.

[gvfs-cat-i18n.diff]

Index: programs/Makefile.am
===================================================================
--- programs/Makefile.am (revisione 1144)
+++ programs/Makefile.am (copia locale)
@@ -1,30 +1,31 @@
 NULL =
 
-INCLUDES = \
- -I$(top_srcdir) \
- -I$(top_builddir) \
- $(GLIB_CFLAGS) \
+INCLUDES = \
+ -I$(top_srcdir) \
+ -I$(top_builddir) \
+ $(GLIB_CFLAGS) \
+ -DGVFS_LOCALEDIR=\""$(localedir)"\" \
  -DG_DISABLE_DEPRECATED
 
-libraries = \
+libraries = \
  $(GLIB_LIBS)
 
-bin_PROGRAMS = \
- gvfs-mount \
- gvfs-cat \
- gvfs-save \
- gvfs-ls \
- gvfs-info \
- gvfs-trash \
- gvfs-rm \
- gvfs-copy \
- gvfs-move \
- gvfs-monitor-file \
- gvfs-monitor-dir \
+bin_PROGRAMS = \
+ gvfs-mount \
+ gvfs-cat \
+ gvfs-save \
+ gvfs-ls \
+ gvfs-info \
+ gvfs-trash \
+ gvfs-rm \
+ gvfs-copy \
+ gvfs-move \
+ gvfs-monitor-file \
+ gvfs-monitor-dir \
  $(NULL)
 
-bin_SCRIPTS = \
- gvfs-less \
+bin_SCRIPTS = \
+ gvfs-less \
  $(NULL)
 
 gvfs_cat_SOURCES = gvfs-cat.c
Index: programs/gvfs-cat.c
===================================================================
--- programs/gvfs-cat.c (revisione 1144)
+++ programs/gvfs-cat.c (copia locale)
@@ -28,10 +28,14 @@
 #include <errno.h>
 
 #include <glib.h>
+#include <glib/gi18n.h>
 #include <gio/gio.h>
 
+static gchar **locations = NULL;
+
 static GOptionEntry entries[] =
 {
+ {G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &locations, "locations", NULL},
  { NULL }
 };
 
@@ -49,7 +53,10 @@
   in = (GInputStream *)g_file_read (file, NULL, &error);
   if (in == NULL)
     {
-      g_printerr ("Error opening file: %s\n", error->message);
+      /* Translators: the first %s is the program name, the second one  */
+      /* is the URI of the file, the third is the error message.        */
+      g_printerr (_("%s: %s: error opening file: %s\n"),
+  g_get_prgname (), g_file_get_uri (file), error->message);
       g_error_free (error);
       return;
     }
@@ -68,7 +75,10 @@
       
       if (written == -1 && errno != EINTR)
  {
-  perror ("Error writing to stdout");
+      /* Translators: the first %s is the program name, the second one  */
+      /* is the URI of the file.                                        */
+ g_printerr (_("%s: %s, error writing to stdout"),
+    g_get_prgname (), g_file_get_uri (file));
   goto out;
  }
       res -= written;
@@ -77,7 +87,10 @@
  }
       else if (res < 0)
  {
-  g_printerr ("Error reading: %s\n", error->message);
+      /* Translators: the first %s is the program name, the second one  */
+      /* is the URI of the file, the third is the error message.        */
+  g_printerr (_("%s: %s: error reading: %s\n"),
+      g_get_prgname (), g_file_get_uri (file), error->message);
   g_error_free (error);
   error = NULL;
   break;
@@ -91,7 +104,10 @@
   close_res = g_input_stream_close (in, NULL, &error);
   if (!close_res)
     {
-      g_printerr ("Error closing: %s\n", error->message);
+      /* Translators: the first %s is the program name, the second one  */
+      /* is the URI of the file, the third is the error message.        */
+      g_printerr (_("%s: %s:error closing: %s\n"),
+  g_get_prgname (), g_file_get_uri (file), error->message);
       g_error_free (error);
     }
 }
@@ -99,30 +115,63 @@
 int
 main (int argc, char *argv[])
 {
-  GError *error;
-  GOptionContext *context;
+  GError *error = NULL;
+  GOptionContext *context = NULL;
   GFile *file;
-  
+  gchar *summary;
+
   setlocale (LC_ALL, "");
 
+  bindtextdomain (GETTEXT_PACKAGE, GVFS_LOCALEDIR);
+  bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+  textdomain (GETTEXT_PACKAGE);
+
   g_type_init ();
   
-  error = NULL;
-  context = g_option_context_new ("- output files at <location>");
+  /* Translators: this message will appear immediately after the */
+  /* usage string - Usage: COMMAND [OPTION]... <THIS_MESSAGE>    */
+  context = g_option_context_new (_("LOCATION... - concatenate LOCATIONS to standard output"));
+  
+  /* Translators: this message will appear after the usage string */
+  /* and before the list of options.                              */
+  summary = g_strconcat (_("Concatenate files at locations and print to the "
+   "standard output. Works just like the traditional "
+   "cat utility, but using gvfs location instead "
+   "local files: for example you can use something "
+   "like smb://server/resource/file.txt as location "
+   "to concatenate."),
+ "\n\n",
+ _("Note: just pipe through cat if you need its "
+   "formatting option like -n, -T or other."),
+ NULL);
+
+  g_option_context_set_summary (context, summary);
+
   g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE);
   g_option_context_parse (context, &argc, &argv, &error);
+
   g_option_context_free (context);
-  
-  if (argc > 1)
+  g_free (summary);
+
+  if (!locations)
     {
-      int i;
-      
-      for (i = 1; i < argc; i++) {
- file = g_file_new_for_commandline_arg (argv[i]);
- cat (file);
- g_object_unref (file);
-      }
+    /* Translators: the %s is the program name. This error message */
+    /* means the user is calling gvfs-cat without any argument.    */
+    g_printerr (_("%s: missing locations"), g_get_prgname ());
+    g_printerr ("\n");
+    g_printerr (_("Try \"%s --help\" for more information."),
+ g_get_prgname ());
+    g_printerr ("\n");
+    return 1;
     }
 
+  int i = 0;
+
+  do {
+  file = g_file_new_for_commandline_arg (locations[i]);
+  cat (file);
+  g_object_unref (file);
+  } while (locations[++i]!=NULL) ;
+
   return 0;
 }
Index: po/POTFILES.in
===================================================================
--- po/POTFILES.in (revisione 1144)
+++ po/POTFILES.in (copia locale)
@@ -57,3 +57,4 @@
 hal/ghalmount.c
 hal/ghalvolume.c
 hal/ghalvolumemonitor.c
+programs/gvfs-cat.c


_______________________________________________
gnome-vfs-list mailing list
gnome-vfs-list@...
http://mail.gnome.org/mailman/listinfo/gnome-vfs-list

Re: [PATCH] i18n/l10n of gvfs-cat

by Alexander Larsson :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On Fri, 2008-01-18 at 09:31 +0100, Luca Ferretti wrote:

>
> > > IMHO could be better prepend the program name and the file name (this is
> > > the behavior of plain cat(1))
> > >
> > >         $ gvfs-cat smb://server/file.txt
> > >         gvfs-cat: smb://server/file.txt: No such file or directory
> >
> > Yeah, that looks better.
>
> Done. The only issue is that now the actual output is something like:
>
>         gvfs-cat: uri:///file/name.ext: error opening file: Error
>         opening file: No such file or directory
>        
> :-(
>
> Do I've to remove "error opening file" from gvfs-cat?

This is a more general problem of how errors reported in GErrors should
look, when you chain them like this (or even more so if you have things
like "error doing highlevel op: error doing midlevel op: lowlevel error
message").

Take this case, there is an error in the open_file operation, where it
can't find the file requested. Should the error from that be "No such
file or directory" or "Error opening file: No such file or directory".
It sort of depends on the context of how the message is used...


Anyway, the patch looks good to commit.


_______________________________________________
gnome-vfs-list mailing list
gnome-vfs-list@...
http://mail.gnome.org/mailman/listinfo/gnome-vfs-list

Re: [PATCH] i18n/l10n of gvfs-cat

by Luca Ferretti :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Il giorno ven, 18/01/2008 alle 09.31 +0100, Luca Ferretti ha scritto:
> Il giorno gio, 10/01/2008 alle 15.15 +0100, Alexander Larsson ha
> scritto:

> Note 2: yeah, there are some wrong indentations I'll fix before commit.

It's `indent -nut -ts2 gvfs-cat.c`, isn't it?

_______________________________________________
gnome-vfs-list mailing list
gnome-vfs-list@...
http://mail.gnome.org/mailman/listinfo/gnome-vfs-list

Re: [PATCH] i18n/l10n of gvfs-cat

by Alexander Larsson :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On Fri, 2008-01-18 at 09:56 +0100, Luca Ferretti wrote:
> Il giorno ven, 18/01/2008 alle 09.31 +0100, Luca Ferretti ha scritto:
> > Il giorno gio, 10/01/2008 alle 15.15 +0100, Alexander Larsson ha
> > scritto:
>
> > Note 2: yeah, there are some wrong indentations I'll fix before commit.
>
> It's `indent -nut -ts2 gvfs-cat.c`, isn't it?

I don't know, I don't use indent for it. gvfs (and gio) use the Gtk+
coding style.

_______________________________________________
gnome-vfs-list mailing list
gnome-vfs-list@...
http://mail.gnome.org/mailman/listinfo/gnome-vfs-list

Re: [PATCH] i18n/l10n of gvfs-cat

by Luca Ferretti :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Il giorno ven, 18/01/2008 alle 09.45 +0100, Alexander Larsson ha
scritto:
> On Fri, 2008-01-18 at 09:31 +0100, Luca Ferretti wrote:
> >
>
> Anyway, the patch looks good to commit.
>

Committed, thanks.


_______________________________________________
gnome-vfs-list mailing list
gnome-vfs-list@...
http://mail.gnome.org/mailman/listinfo/gnome-vfs-list