xffm translation: date specification

edscott wilson garcia edscott at imp.mx
Sat Jun 21 03:05:45 CEST 2003


El vie, 20-06-2003 a las 13:30, Bernhard Walle escribió:
> Hello,
> 
> On Fri, 20 Jun 2003 at 14:00 (-0500), edscott wilson garcia wrote:
> > El vie, 20-06-2003 a las 03:06, Bernhard Walle escribió:
> > > On Thu, 19 Jun 2003 at 11:27 (-0500), edscott wilson garcia wrote:
> > > > El jue, 19-06-2003 a las 10:14, Benedikt Meurer escribió:
> > > > > On Thu, 19, Jun 2003, edscott wilson garcia wrote:
> > > > > > 
> > > > > > There's the rub. We're in translation freeze. There should be a way not
> > > > > > to require the translations.
> > > > > 
> > > > > Please, do not replace with a stupid work-around. Do it right, or leave
> > > > > it like it is now and we change it after 4.0.
> > > > 
> > > > Agreed.
> > > 
> > > Did you read my other mail? The two strings are *already* in the
> > > translation files. So you have only to fill them with live. (The month
> > > translation is done by the time functions automatically if locale is
> > > correctly set.)
> > 
> > Please try to compile in your code and test it. If it works send us a
> > patch so we can commit it (easy patch way: duplicate-file,
> > modify-file-and-test, xfdiff4-the-files-to-create patch).
> 
> Ok, here's the patch. Maybe you'll put the new function in a own file with
> a header file.
> 
> I did *not* use the glib time functions because the g_date_strftime
> function works only with dates and not with times. So the only function
> I can use would be the one to calculate the difference, but this forces
> me to call a converting function which converts from time_t to GDate.
> Since difftime() normally does only a substraction it's much faster. It
> conforms to ANSI C99 so it *should* be available on all systems. Maybe
> you'll have to add this in the configure script -- I don't know this.
> 

It works on both linux and freeBSD.

> I did not make any changes in the translation file and it works correctly.
> So it should not affect the translation freeze. I hope I made all
> correct.
> 

I committed the patch with some modifications to keep the function call
simple. The routine from GNU guys is no longer compiled. The new code
works fine with dates in Spanish where day preceeds month.

 regards,

Edscott

> 
> Regards,
> Bernhard
> 
> -- 
> _________ http://www.bwalle.de _________________________________________________
> Ich glaube nur an Statistiken, die ich selbst gefälscht habe.
> 	-- Winston Churchill
> ----
> 

> Index: add_file.c
> ===================================================================
> RCS file: /cvsroot/xfce/xfce-devel/xffm/src/add_file.c,v
> retrieving revision 1.21
> diff -u -r1.21 add_file.c
> --- add_file.c	10 Jun 2003 18:09:52 -0000	1.21
> +++ add_file.c	20 Jun 2003 18:29:45 -0000
> @@ -57,6 +57,9 @@
>  #ifdef HAVE_UNISTD_H
>  #include <unistd.h>
>  #endif
> +#ifdef HAVE_TIME_H
> +#include <time.h>
> +#endif
>  
>  #include <gdk/gdkkeysyms.h>
>  #include <gtk/gtk.h>
> @@ -77,6 +80,52 @@
>  extern int stop;
>  
>  
> +/*
> + * This function converts a time value specified in seconds since 1970-01-01
> + * to a string representation. It shows the date and the time if the point
> + * if less then six month in the past and only the date otherwise.
> + * The exact format must be provided by a translation string. 
> + *
> + * The function should be thread-save since there are not used static
> + * (or even global) variables if the system provided a localtime_r() function.
> + *
> + * Arguments:     when:    time in seconds since 1970-01-01
> + *                string:  the result char-array in which the string is placed
> + *                length:  the length of the string-array
> + *                
> + * Return value:  string on success, NULL on failure
> + */
> +const char *time_to_string (time_t when, char* string, size_t length) {
> +      time_t          now             = time(NULL);
> +#ifdef HAVE_LOCALTIME_R
> +      struct tm       timestruct;
> +#endif
> +      struct tm*      timestruct_ptr;
> +      char*           formatstring;
> +
> +      memset (string, 0, length);
> +
> +      formatstring = difftime(now, when) > 24*60*60*30*6
> +            /* strftime format for non-recent files (older than 6 months)  */
> +          ? _("%b %e  %Y")
> +            /* strftime format for recent files */
> +          : _("%b %e %H:%M");
> +
> +#ifdef HAVE_LOCALTIME_R
> +      timestruct_ptr = ×truct;
> +      localtime_r(&when, timestruct_ptr);
> +#else
> +      timestruct_ptr = localtime(&when);
> +#endif
> +
> +      if (strftime(string, length, formatstring, localtime(&when)) == 0) {
> +          return NULL;
> +      }
> +
> +      return string;
> +}
> +
> +
>  char *sizetag(long long tama, int count)
>  {
>      char *tag = "B";
> @@ -168,6 +217,7 @@
>      struct group *g;
>      struct passwd *p;
>      char *group, *owner, *tag;
> +    char date[64];
>  
>      if(IS_DIR(en->type))
>  	tag = sizetag(-1, en->count);
> @@ -190,7 +240,7 @@
>  	owner = "?";
>      gtk_tree_store_set((GtkTreeStore *) treemodel, target, 
>  	MODE_COLUMN, mode_string(en->st->st_mode), 
> -	DATE_COLUMN, my_utf_string(time_string(en->st->st_mtime)), 
> +	DATE_COLUMN, my_utf_string(time_to_string(en->st->st_mtime, date, 64)), 
>  	GROUP_COLUMN, group, 
>  	OWNER_COLUMN, owner, 
>  	SIZE_COLUMN, tag, 
> @@ -250,6 +300,9 @@
>  	g_error_free(error);
>      return;
>  }
> +
> +
> +
>  
>  GtkTreeIter add_it(GtkTreeView * treeview, GtkTreeIter * target, tree_entry_t * en, char *name, gboolean insert)
>  {
> ----
> 

> _______________________________________________
> Xfce4-dev mailing list
> Xfce4-dev at xfce.org
> http://moongroup.com/mailman/listinfo/xfce4-dev





More information about the Xfce4-dev mailing list