Re: filename translation implementation - how to decide



On Wed, 2004-12-15 at 10:59 -0500, Owen Taylor wrote:
> On Wed, 2004-12-15 at 16:21 +0100, Alexander Larsson wrote:
> > 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.
> 
> I discussed this with Matthias and there is no way we feel comfortable
> adding a bunch of not-fully-agreed-upon code to GLib right before the
> release.
> 
> (Time isn't ticking for the GLib/GTK+ API freeze ... that was months
> ago, it's ticking for the 2.6.0 *release*, which is this week.)
> 
> What we discussed doing was adding:
> 
>  g_filename_display_basename()
> 
> that does full path => display name (possibly translated) of the last
> component, and implementing that for now with g_basename() and
> g_file_display_name(). Translation could conceivably be added in a
> 2.6.x release.

What about this:

Index: glib/gconvert.c
===================================================================
RCS file: /cvs/gnome/glib/glib/gconvert.c,v
retrieving revision 1.67
diff -u -p -r1.67 gconvert.c
--- glib/gconvert.c	12 Dec 2004 20:53:02 -0000	1.67
+++ glib/gconvert.c	15 Dec 2004 16:27:48 -0000
@@ -1907,6 +1907,38 @@ make_valid_utf8 (const gchar *name)
 }
 
 /**
+ * g_filename_display_basename:
+ * @filename: an absolute pathname in the GLib file name encoding
+ *
+ * Returns the display basename for the particular filename, guaranteed
+ * to be valid UTF-8. The display name might not be identical to the
filename,
+ * for instance there might be problems converting it to UTF-8, and
some files
+ * can be translated in the display
+ *
+ * You must pass the whole absolute pathname to this functions so that
+ * translation of well known locations can be done.
+ *
+ * This function is prefered over g_filename_display_name() if you know
the
+ * whole path, as it allows translation.
+ *
+ * Return value: a newly allocated string containing
+ *   a rendition of the filename in valid UTF-8
+ *
+ * Since: 2.6
+ **/
+gchar *
+g_filename_display_basename (const gchar *filename)
+{
+  char *basename;
+  char *display_name;
+  
+  basename = g_path_get_basename (filename);
+  display_name = g_filename_display_name (basename);
+  g_free (basename);
+  return display_name;
+}
+
+/**
  * g_filename_display_name:
  * @filename: a pathname hopefully in the GLib file name encoding
  * 
@@ -1917,6 +1949,10 @@ make_valid_utf8 (const gchar *name)
  * Unlike g_filename_to_utf8(), the result is guaranteed 
  * to be non-NULL even if the filename actually isn't in the GLib
  * file name encoding.
+ *
+ * If you know the whole pathname of the file you should use
+ * g_filename_display_basename(), since that allows location-based
+ * translation of filenames.
  *
  * Return value: a newly allocated string containing
  *   a rendition of the filename in valid UTF-8
Index: glib/gconvert.h
===================================================================
RCS file: /cvs/gnome/glib/glib/gconvert.h,v
retrieving revision 1.18
diff -u -p -r1.18 gconvert.h
--- glib/gconvert.h	12 Dec 2004 20:53:02 -0000	1.18
+++ glib/gconvert.h	15 Dec 2004 16:27:48 -0000
@@ -126,6 +126,8 @@ gchar *g_filename_to_uri   (const gchar 
 gchar *g_filename_display_name (const gchar *filename) G_GNUC_MALLOC;
 gboolean g_get_filename_charsets (G_CONST_RETURN gchar ***charsets);
 
+gchar *g_filename_display_basename (const gchar *filename)
G_GNUC_MALLOC;
+
 gchar **g_uri_list_extract_uris (const gchar *uri_list) G_GNUC_MALLOC;
 
 G_END_DECLS


=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 Alexander Larsson                                            Red Hat, Inc 
                   alexl redhat com    alla lysator liu se 
He's a hate-fuelled crooked photographer with nothing left to lose. She's a 
plucky green-skinned advertising executive fleeing from a Satanic cult. They 
fight crime! 




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