message formatting and i18n



Hi all,

some messages in the Midnight Commander don't translate well to other languages because the string is concatenated manually, like in src/ext.c, line 486.

I started to fix some of these in mcedit. How do you feel about the new code?

Well, one thing is not too nice about it: The assignment of errmsg = ... while passing it as a function argument. But I don't want to allocate memory that I don't need.

Roland
? mc.qpg
? rillig
? edit/editcommands.c
? maint/template.c
Index: configure.ac
===================================================================
RCS file: /cvsroot/mc/mc/configure.ac,v
retrieving revision 1.20
diff -u -p -u -r1.20 configure.ac
--- configure.ac	30 Jan 2005 05:06:13 -0000	1.20
+++ configure.ac	6 Feb 2005 15:11:18 -0000
@@ -565,6 +565,12 @@ if test x"$USE_MAINTAINER_MODE" = x"yes"
     fi
 fi
 
+AC_ARG_ENABLE([fast-moves],
+              [  --disable-fast-moves     Disable fast cursor movement in the internal editor])
+if test x"$enable_fast_moves" != x"no"; then
+  AC_DEFINE([FAST_MOVE_CURSOR], [1], [Define to enable fast cursor movement in mcedit])
+fi
+
 ri_GCC_WARNINGS
 
 AC_SUBST(CFLAGS)
Index: edit/edit.c
===================================================================
RCS file: /cvsroot/mc/mc/edit/edit.c,v
retrieving revision 1.93
diff -u -p -u -r1.93 edit.c
--- edit/edit.c	30 Jan 2005 20:34:58 -0000	1.93
+++ edit/edit.c	6 Feb 2005 15:11:18 -0000
@@ -138,11 +138,10 @@ edit_load_file_fast (WEdit *edit, const 
 
     if ((file = mc_open (filename, O_RDONLY | O_BINARY)) == -1) {
 	/* The file-name is printed after the ':' */
-	edit_error_dialog (_("Error"),
-			   get_sys_error (catstrs
-					  (_
-					   (" Cannot open file for reading: "),
-					   filename, " ", (char *) NULL)));
+	GString *errmsg = g_string_new(NULL);
+	g_string_sprintf(errmsg, _(" Cannot open %s for reading "), filename);
+	edit_error_dialog (_("Error"), get_sys_error (errmsg->str));
+	g_string_free (errmsg, TRUE);
 	return 1;
     }
 
@@ -268,19 +267,18 @@ edit_insert_file (WEdit *edit, const cha
 	    edit_insert_stream (edit, f);
 	    edit_cursor_move (edit, current - edit->curs1);
 	    if (pclose (f) > 0) {
-		edit_error_dialog (_("Error"),
-				   catstrs (_
-					    (" Error reading from pipe: "),
-					    p, " ", (char *) NULL));
+	        GString *errmsg = g_string_new (NULL);
+		g_string_sprintf (errmsg, _(" Error reading from pipe: %s "), p);
+		edit_error_dialog (_("Error"), errmsg->str);
+		g_string_free (errmsg, TRUE);
 		g_free (p);
 		return 0;
 	    }
 	} else {
-	    edit_error_dialog (_("Error"),
-			       get_sys_error (catstrs
-					      (_
-					       (" Cannot open pipe for reading: "),
-					       p, " ", (char *) NULL)));
+	    GString *errmsg = g_string_new (NULL);
+	    g_string_sprintf (errmsg, _(" Cannot open pip for reading: %s "), p);
+	    edit_error_dialog (_("Error"), errmsg->str);
+	    g_string_free (errmsg, TRUE);
 	    g_free (p);
 	    return 0;
 	}
@@ -310,6 +308,7 @@ static int
 check_file_access (WEdit *edit, const char *filename, struct stat *st)
 {
     int file;
+    GString *errmsg = (GString *) 0;
 
     /* Try opening an existing file */
     file = mc_open (filename, O_NONBLOCK | O_RDONLY | O_BINARY, 0666);
@@ -324,12 +323,9 @@ check_file_access (WEdit *edit, const ch
 		     O_NONBLOCK | O_RDONLY | O_BINARY | O_CREAT | O_EXCL,
 		     0666);
 	if (file < 0) {
-	    edit_error_dialog (_("Error"),
-			       get_sys_error (catstrs
-					      (_
-					       (" Cannot open file for reading: "),
-					       filename, " ", (char *) NULL)));
-	    return 1;
+	    g_string_sprintf (errmsg = g_string_new (NULL),
+		_(" Cannot open %s for reading "), filename);
+	    goto cleanup;
 	} else {
 	    /* New file, delete it if it's not modified or saved */
 	    edit->delete_file = 1;
@@ -338,22 +334,16 @@ check_file_access (WEdit *edit, const ch
 
     /* Check what we have opened */
     if (mc_fstat (file, st) < 0) {
-	mc_close (file);
-	edit_error_dialog (_("Error"),
-			   get_sys_error (catstrs
-					  (_
-					   (" Cannot get size/permissions info for file: "),
-					   filename, " ", (char *) NULL)));
-	return 1;
+	g_string_sprintf (errmsg = g_string_new (NULL),
+	    _(" Cannot get size/permissions for %s "), filename);
+	goto cleanup;
     }
 
     /* We want to open regular files only */
     if (!S_ISREG (st->st_mode)) {
-	mc_close (file);
-	edit_error_dialog (_("Error"),
-			   catstrs (_(" Not an ordinary file: "), filename,
-				    " ", (char *) NULL));
-	return 1;
+	g_string_sprintf (errmsg = g_string_new (NULL),
+	    _(" %s is not an ordinary file "), filename);
+	goto cleanup;
     }
 
     /*
@@ -365,14 +355,18 @@ check_file_access (WEdit *edit, const ch
     }
 
     if (st->st_size >= SIZE_LIMIT) {
-	mc_close (file);
-	edit_error_dialog (_("Error"),
-			   catstrs (_(" File is too large: "), filename,
-				    (char *) NULL));
-	return 1;
+        g_string_sprintf (errmsg = g_string_new (NULL),
+	    _(" File %s is too large "), filename);
+	goto cleanup;
     }
 
-    mc_close (file);
+cleanup:
+    (void) mc_close (file);
+    if (errmsg) {
+    	edit_error_dialog (_("Error"), errmsg->str);
+	g_string_free (errmsg, TRUE);
+	return 1;
+    }
     return 0;
 }
 


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