Re: l10n with GtkItemFactory



On Fri, Feb 28, 2003 at 09:19:12PM +0100, Emmanuele Bassi wrote:
I have a menu bar, created using a GkItemFactory, I'd like to localize
using the usual gettext calls.  So far, I've resolved the problem by
passing the path string to the N_() macro, but I'd like to know if there
is some way to make it more clean (for the translator's point of
view)...

I'm not sure what exactly your problem is, but here's what I've done;
hopefully some part of this will answer your question. :P

Define your actions with an enum:

enum {
        ...
        ACTION_FOO,
        ...
};

And then the item factory entries are like this:
{
        ...
        { N_("/_File/_Foo"), NULL, foo_cb, ACTION_FOO },
        ...
}

You can then retrieve those menu items via:

item = gtk_item_factory_get_widget_by_action(item_factory, ACTION_FOO);

Be sure that those strings get passed through gettext, too.
This is the function for it:

gtk_item_factory_set_translate_func(item_factory,
        gettext_translate_func, NULL, NULL);


Where gettext_translate_func is defined like this:

gchar*
gettext_translate_func(const gchar *path, gpointer data) {
    return gettext(path);
}

-- 
      Evan Martin
martine cs washington edu
  http://neugierig.org



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