Re: filename translation implementation - how to decide



On Wed, 2004-12-15 at 17:30 +0100, Alexander Larsson wrote:
> 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

I got ok to commit this, and the stuff in gtk+/libgnomeui/nautilus that
uses it. That in itself fixed some problems with how we display
filenames, and furthermore, it makes the implementation of the gettext
method trivial:

Index: gconvert.c
===================================================================
RCS file: /cvs/gnome/glib/glib/gconvert.c,v
retrieving revision 1.69
diff -u -p -r1.69 gconvert.c
--- gconvert.c	15 Dec 2004 16:42:28 -0000	1.69
+++ gconvert.c	15 Dec 2004 17:15:17 -0000
@@ -1929,10 +1929,39 @@ make_valid_utf8 (const gchar *name)
 gchar *
 g_filename_display_basename (const gchar *filename)
 {
+  static gboolean _initialized = FALSE;
+  const char *translate;
+  const char *translated;
   char *basename;
   char *display_name;
 
   g_return_val_if_fail (filename != NULL, NULL);
+  
+  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);


=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 Alexander Larsson                                            Red Hat, Inc 
                   alexl redhat com    alla lysator liu se 
He's a benighted one-eyed librarian She's a tortured junkie barmaid looking 
for love in all the wrong places. They fight crime! 




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