[patch] locale-aware date format for ftp and file

Jakub Bogusz <[email protected]>
Newsgroups gmane.comp.web.links
Message-ID <[email protected]>
Hello,

The attached patch allows to localize the date format used for ftp and
file listings, like it's done in utilities like ls.
Especially "%b %e  %Y" format string used currently is specific to
English and some other languages usually don't put the day of month
between month and year - so I think the date format should be locale-aware.

Patch includes pl.po update as an example of localizing date format.
String containing just spaces is used as date replacement, so it should
be "translated" to proper number of spaces (equal length of formatted
date). I adjusted ftp.c so both files use strings with the same number
of spaces.


-- 
Jakub Bogusz    http://qboosh.pl/

_______________________________________________
elinks-dev mailing list
[email protected]
http://linuxfromscratch.org/mailman/listinfo/elinks-dev
elinks-date-format.patch (text/plain, 2.6 KB)
--- elinks-0.11.3/src/util/file.c.orig	2007-12-02 01:03:26.631355000 +0100
+++ elinks-0.11.3/src/util/file.c	2007-12-02 01:19:06.416911036 +0100
@@ -461,16 +461,16 @@ stat_date(struct string *string, struct 
 
 		if (current_time > when + 6L * 30L * 24L * 60L * 60L
 		    || current_time < when - 60L * 60L)
-			fmt = "%b %e  %Y";
+			fmt = gettext("%b %e  %Y");
 		else
-			fmt = "%b %e %H:%M";
+			fmt = gettext("%b %e %H:%M");
 
 		add_date_to_string(string, fmt, &when);
 		add_char_to_string(string, ' ');
 		return;
 	}
 #endif
-	add_to_string(string, "             ");
+	add_to_string(string, gettext("             "));
 }
 
 
--- elinks-0.11.3/src/protocol/ftp/ftp.c.orig	2007-12-02 01:03:26.739361000 +0100
+++ elinks-0.11.3/src/protocol/ftp/ftp.c	2007-12-02 01:23:34.644196437 +0100
@@ -1147,7 +1147,7 @@ display_dir_entry(struct cache_entry *ca
 		time_t when = ftp_info->mtime;
 		struct tm *when_tm;
 	       	unsigned char *fmt;
-		unsigned char date[13];
+		unsigned char date[MAX_STR_LEN];
 		int wr;
 
 		if (ftp_info->local_time_zone)
@@ -1157,20 +1157,19 @@ display_dir_entry(struct cache_entry *ca
 
 		if (current_time > when + 6L * 30L * 24L * 60L * 60L
 		    || current_time < when - 60L * 60L)
-			fmt = "%b %e  %Y";
+			fmt = gettext("%b %e  %Y");
 		else
-			fmt = "%b %e %H:%M";
+			fmt = gettext("%b %e %H:%M");
 
-		wr = strftime(date, sizeof(date), fmt, when_tm);
-
-		while (wr < sizeof(date) - 1) date[wr++] = ' ';
-		date[sizeof(date) - 1] = '\0';
-		add_to_string(&string, date);
+		if (strftime(date, sizeof(date), fmt, when_tm) <= 0)
+			add_to_string(&string, gettext("             "));
+		else {
+			add_to_string(&string, date);
+			add_char_to_string(&string, ' ');
+		}
 	} else
 #endif
-	add_to_string(&string, "            ");
-
-	add_char_to_string(&string, ' ');
+	add_to_string(&string, gettext("             "));
 
 	if (ftp_info->type == FTP_FILE_DIRECTORY && colorize_dir) {
 		add_to_string(&string, "<font color=\"");
--- elinks-0.11.3/po/pl.po.orig	2007-04-15 22:51:02.000000000 +0200
+++ elinks-0.11.3/po/pl.po	2007-12-02 01:29:45.701341779 +0100
@@ -7428,6 +7428,18 @@
 msgid "Use EPSV instead of EPRT (passive vs active mode, IPv6 only)."
 msgstr "Używaj EPSV zamiast EPRT (tryb pasywny kontra aktywny, tylko IPv6)."
 
+#: src/protocol/ftp/ftp.c:1160 src/util/file.c:464
+msgid "%b %e  %Y"
+msgstr "%e.%m.%Y "
+
+#: src/protocol/ftp/ftp.c:1162 src/util/file.c:466
+msgid "%b %e %H:%M"
+msgstr "%e.%m %H:%M"
+
+#: src/protocol/ftp/ftp.c:1165 src/protocol/ftp/ftp.c:1172 src/util/file.c:473
+msgid "             "
+msgstr "             "
+
 #. name:
 #: src/protocol/gopher/gopher.c:46
 msgid "Gopher"
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.