Re: glib gettext implementation



On 22 Aug 2001, Havoc Pennington wrote:

> 
> Alex Larsson <alexl redhat com> writes:
> > On 22 Aug 2001, Havoc Pennington wrote:
> > 
> > > 
> > > Hi,
> > > 
> > > Can we do something like:
> > > 
> > > #ifndef G_DISABLE_GETTEXT_NAMESPACE_POLLUTION
> > > #define _(x) whatever
> > > #define N_(x) whatever
> > > #endif
> > > 
> > > Or if that's too audacious, maybe #ifdef G_ENABLE_CONVENIENT_GETTEXT
> > > or something.
> > 
> > Well. I guess this would help for apps. libraries still have to define 
> > these differently.
> > 
> 
> We can handle that too:
>  
> #ifdef G_ENABLE_GETTEXT_MACROS
> #define _(x) gettext
> #endif
> #ifdef G_ENABLE_DGETTEXT_MACROS
> #define _(x) dgettext
> #endif

Well. The glib implementation for example is:
glibintl.h:
#define _(String) _glib_gettext(String)

gutils.c:
G_CONST_RETURN gchar *
_glib_gettext (const gchar *str)
{
  static gboolean _glib_gettext_initialized = FALSE;

  if (!_glib_gettext_initialized)
    {
      bindtextdomain(GETTEXT_PACKAGE, GLIB_LOCALE_DIR);
      _glib_gettext_initialized = TRUE;
    }
  
  return dgettext (GETTEXT_PACKAGE, str);
}

But the gtk+ one is just:
#define _(String) dgettext(GETTEXT_PACKAGE,String)

But using that means that gtk+ needs in its init function:
  bindtextdomain (GETTEXT_PACKAGE, GTK_LOCALEDIR);
  bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");

and that enforces an init function on the library.

Btw. Shouldn't glib also bind the codeset to UTF-8?

/ Alex






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