filename translation implementation - how to decide



So, I presented two ways to do filename translation. No method is
perfect, both has disadvantages. People has picked sides, discussed and
flames were exchanged. 

Since the time is ticking for the glib/gtk+ API freeze we're soon gonna
run out of time to get this API in place at the right place (glib).
Therefore, to further what I think is the right decision I implemented
the gettext method in glib/gtk+/libgnomeui/nautilus. Patches and test
filesystem po file attached.

However, I'm tired of huge flamewars, and I'm tired of taking the crap
when we have to make a decision that some people will dislike (any
decision here will get flamed). So, how do we actually make a decision
as a group? If we continue to discuss this here we'll only get more
flames and long threads repeating old arguments, which most people won't
even read. (In fact, many core maintainers have already left desktop-
devel-list because of its low signal/noise levels).

Normally with such a decision it would be up to the module maintainers,
but this is a cross-module question. The modules involved seem to be
glib, gtk+, libgnomeui, nautilus, and possibly gnome-session. If the
maintainers of these modules can agree on a decision, would the
community accept this?

I fear we will be unable to make a decision on this, and we'll let it
slide yet another release. I made the implementation to verify that the
solution worked and to have something that can go in quickly if we get
to a decision.

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 Alexander Larsson                                            Red Hat, Inc 
                   alexl redhat com    alla lysator liu se 
He's a globe-trotting flyboy grifter in a wheelchair. She's a wealthy 
insomniac former first lady from aristocratic European stock. They fight 
crime! 
Index: glib/gfileutils.c
===================================================================
RCS file: /cvs/gnome/glib/glib/gfileutils.c,v
retrieving revision 1.50
diff -u -p -r1.50 gfileutils.c
--- glib/gfileutils.c	4 Nov 2004 00:37:47 -0000	1.50
+++ glib/gfileutils.c	15 Dec 2004 14:40:10 -0000
@@ -1448,3 +1448,59 @@ g_file_read_link (const gchar *filename,
   return NULL;
 #endif
 }
+
+/**
+ * g_translated_display_name_from_path:
+ * @filename: the absolute pathname of a file
+ *
+ * Returns the display name (the base name) to use for a particular
+ * filename. Some well known locations have their names automatically
+ * translated to the current language, and the filename is converted from
+ * the filename charset to UTF8. If the conversion fails the function tries
+ * its best to generate a nice name.
+ *
+ * Whenever you need to display a name in the user interface you should
+ * display the translated displayname.
+ *
+ * Returns: A newly allocated UTF8 string
+ *
+ * Since: 2.6
+ */
+gchar *
+g_translated_display_name_from_path (const gchar *filename)
+{
+  static gboolean _initialized = FALSE;
+  const char *translate;
+  const char *translated;
+  char *basename;
+  char *display_name;
+  
+  if (!_initialized)
+    {
+      bindtextdomain("filesystem", GLIB_LOCALE_DIR);
+#    ifdef HAVE_BIND_TEXTDOMAIN_CODESET
+      bind_textdomain_codeset ("filesystem", "UTF-8");
+#    endif
+      _initialized = TRUE;
+    }
+
+  translate = filename;
+  if (g_str_has_prefix (translate, g_get_home_dir ()))
+    {
+      translate += strlen (g_get_home_dir ());
+      if (*translate == '/')
+	translate++;
+    }
+
+  /* Don't translate empty string */
+  if (*translate != 0)
+    {
+      translated = dgettext ("filesystem", translate);
+      if (translated != translate)
+	return g_strdup (translated);
+    }
+  
+  basename = g_path_get_basename (filename);
+  display_name = g_filename_display_name (basename);
+  return display_name;
+}
Index: glib/gfileutils.h
===================================================================
RCS file: /cvs/gnome/glib/glib/gfileutils.h,v
retrieving revision 1.14
diff -u -p -r1.14 gfileutils.h
--- glib/gfileutils.h	27 Oct 2004 16:46:29 -0000	1.14
+++ glib/gfileutils.h	15 Dec 2004 14:40:10 -0000
@@ -103,6 +103,9 @@ gchar *g_build_path     (const gchar *se
 gchar *g_build_filename (const gchar *first_element,
 			 ...);
 
+gchar *g_translated_display_name_from_path (const gchar *filename);
+
+
 G_END_DECLS
 
 #endif /* __G_FILEUTILS_H__ */


 
Index: gtk/gtkfilesystemunix.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkfilesystemunix.c,v
retrieving revision 1.49
diff -u -p -r1.49 gtkfilesystemunix.c
--- gtk/gtkfilesystemunix.c	27 Sep 2004 16:51:18 -0000	1.49
+++ gtk/gtkfilesystemunix.c	15 Dec 2004 14:40:13 -0000
@@ -1743,9 +1743,7 @@ gtk_file_folder_unix_get_info (GtkFileFo
 
   if (types & GTK_FILE_INFO_DISPLAY_NAME)
     {
-      gchar *display_name = g_filename_to_utf8 (basename, -1, NULL, NULL, NULL);
-      if (!display_name)
-	display_name = g_strescape (basename, NULL);
+      gchar *display_name = g_translated_display_name_from_path (filename);
 
       gtk_file_info_set_display_name (info, display_name);
 


Index: file-chooser/gtkfilesystemgnomevfs.c
===================================================================
RCS file: /cvs/gnome/libgnomeui/file-chooser/gtkfilesystemgnomevfs.c,v
retrieving revision 1.53
diff -u -p -r1.53 gtkfilesystemgnomevfs.c
--- file-chooser/gtkfilesystemgnomevfs.c	24 Nov 2004 16:18:27 -0000	1.53
+++ file-chooser/gtkfilesystemgnomevfs.c	15 Dec 2004 14:40:17 -0000
@@ -2036,6 +2036,8 @@ info_from_vfs_info (const gchar      *ur
 		    GtkFileInfoType   types)
 {
   GtkFileInfo *info = gtk_file_info_new ();
+  char *local_file;
+  char *display_name;
 
   if (types & GTK_FILE_INFO_DISPLAY_NAME)
     {
@@ -2048,9 +2050,16 @@ info_from_vfs_info (const gchar      *ur
 	}
       else
 	{
-	  gchar *display_name = g_filename_to_utf8 (vfs_info->name, -1, NULL, NULL, NULL);
-	  if (!display_name)
-	    display_name = g_strescape (vfs_info->name, NULL);
+	  local_file = gnome_vfs_get_local_path_from_uri (uri);
+	  if (local_file != NULL)
+	    {
+	      display_name = g_translated_display_name_from_path (local_file);
+	      g_free (local_file);
+	    }
+	  else
+	    {
+	      display_name = g_filename_display_name (vfs_info->name);
+	    }
 
 	  gtk_file_info_set_display_name (info, display_name);
 

Index: libnautilus-private/nautilus-file-utilities.c
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-file-utilities.c,v
retrieving revision 1.121
diff -u -p -r1.121 nautilus-file-utilities.c
--- libnautilus-private/nautilus-file-utilities.c	28 Oct 2004 14:00:37 -0000	1.121
+++ libnautilus-private/nautilus-file-utilities.c	15 Dec 2004 14:40:21 -0000
@@ -410,9 +410,8 @@ nautilus_get_vfs_method_display_name (ch
 char *
 nautilus_get_uri_shortname_for_display (GnomeVFSURI *uri)
 {
-	gboolean utf8_filenames;
-	const char *filename_charset;
 	char *utf8_name, *name, *tmp;
+	char *text_uri, *local_file;
 	gboolean validated;
 	const char *method;
 
@@ -422,32 +421,12 @@ nautilus_get_uri_shortname_for_display (
 	if (name == NULL) {
 		name = gnome_vfs_uri_to_string (uri, GNOME_VFS_URI_HIDE_PASSWORD);
 	} else if (g_ascii_strcasecmp (uri->method_string, "file") == 0) {
-		utf8_filenames = eel_get_filename_charset (&filename_charset);
-		if (utf8_filenames) {
-			/* If not valid utf8, and filenames are utf8, test if converting
-			   from the locale works */
-			if (!g_utf8_validate (name, -1, NULL)) {
-				utf8_name = g_locale_to_utf8 (name, -1, NULL, NULL, NULL);
-				if (utf8_name != NULL) {
-					g_free (name);
-					name = utf8_name;
-					/* Guaranteed to be correct utf8 here */
-					validated = TRUE;
-				}
-			} else {
-				/* name was valid, no need to re-validate */
-				validated = TRUE;
-			}
-		} else {
-			/* Try to convert from filename charset to utf8 */
-			utf8_name = g_convert (name, -1, "UTF-8", filename_charset, NULL, NULL, NULL);
-			if (utf8_name != NULL) {
-				g_free (name);
-				name = utf8_name;
-				/* Guaranteed to be correct utf8 here */
-				validated = TRUE;
-			}
-		}
+		text_uri = gnome_vfs_uri_to_string (uri, GNOME_VFS_URI_HIDE_PASSWORD);
+		local_file = gnome_vfs_get_local_path_from_uri (text_uri);
+		name = g_translated_display_name_from_path (local_file);
+		g_free (local_file);
+		g_free (text_uri);
+		validated = TRUE;
 	} else if (!gnome_vfs_uri_has_parent (uri)) {
 		/* Special-case the display name for roots that are not local files */
 		method = nautilus_get_vfs_method_display_name (uri->method_string);
Index: libnautilus-private/nautilus-file.c
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-file.c,v
retrieving revision 1.358
diff -u -p -r1.358 nautilus-file.c
--- libnautilus-private/nautilus-file.c	22 Nov 2004 15:24:36 -0000	1.358
+++ libnautilus-private/nautilus-file.c	15 Dec 2004 14:40:21 -0000
@@ -60,6 +60,7 @@
 #include <libgnomevfs/gnome-vfs-volume.h>
 #include <libgnomevfs/gnome-vfs-volume-monitor.h>
 #include <libgnomevfs/gnome-vfs-drive.h>
+#include <glib/gfileutils.h>
 #include <libnautilus-extension/nautilus-file-info.h>
 #include <libxml/parser.h>
 #include <pwd.h>
@@ -2679,8 +2680,7 @@ nautilus_file_get_display_name_nocopy (N
 	gboolean validated;
 	GnomeVFSURI *vfs_uri;
 	const char *method;
-	gboolean utf8_filenames;
-	const char *filename_charset;
+	char *uri, *local_file;
 
 	if (file == NULL) {
 		return NULL;
@@ -2711,32 +2711,12 @@ nautilus_file_get_display_name_nocopy (N
 			 */
 			/* Keep in sync with nautilus_get_uri_shortname_for_display */
 			if (has_local_path (file)) {
-				utf8_filenames = eel_get_filename_charset (&filename_charset);
-				if (utf8_filenames) {
-					/* If not valid utf8, and filenames are utf8, test if converting
-					   from the locale works */
-					if (!g_utf8_validate (name, -1, NULL)) {
-						utf8_name = g_locale_to_utf8 (name, -1, NULL, NULL, NULL);
-						if (utf8_name != NULL) {
-							g_free (name);
-							name = utf8_name;
-							/* Guaranteed to be correct utf8 here */
-							validated = TRUE;
-						}
-					} else {
-						/* name was valid, no need to re-validate */
-						validated = TRUE;
-					}
-				} else {
-					/* Try to convert from filename charset to utf8 */
-					utf8_name = g_convert (name, -1, "UTF-8", filename_charset, NULL, NULL, NULL);
-					if (utf8_name != NULL) {
-						g_free (name);
-						name = utf8_name;
-						/* Guaranteed to be correct utf8 here */
-						validated = TRUE;
-					}
-				}
+				uri = nautilus_file_get_uri (file);
+				local_file = gnome_vfs_get_local_path_from_uri (uri);
+				name = g_translated_display_name_from_path (local_file);
+				g_free (local_file);
+				g_free (uri);
+				validated = TRUE;
 			} else if (strcmp (name, "/") == 0) {
 				/* Special-case the display name for roots that are not local files */
 				g_free (name);
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2004-12-15 14:17+0100\n"
"PO-Revision-Date: 2004-12-15 14:18+0100\n"
"Last-Translator: FULL NAME <EMAIL ADDRESS>\n"
"Language-Team: LANGUAGE <LL li org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: 8bit\n"

#: strings.c:3
msgid "Desktop"
msgstr "Skrivbord"


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