[Spice-devel] [spice-gtk] Initialise gettext library properly
Jonathon Jongsma
jjongsma at redhat.com
Wed Aug 17 20:58:36 UTC 2016
On Wed, 2016-08-17 at 12:34 -0400, Frediano Ziglio wrote:
> >
> >
> > Hi
> >
> > ----- Original Message -----
> > >
> > > This will allow internationalisation to work correctly.
> >
> > Is this working with spice-gtk lib too?
> >
>
> spice-gtk links to spice-glib so this will initialize gettext for
> both.
>
> I'm actually testing if everything is fine.
> Actually it does not work :(
> The reason is that the constructor function is called too earlier,
> before the application setlocale so it does not take into account
> language settings :(
> Wondering if they tested libsoup too, they should have the same
> issue.
I'm not sure that this is related, but I just noticed that we're
including gi18n.h when we should be including gi18n-lib.h:
==================
In order to use these macros in an application, you must include
<glib/gi18n.h>. For use in a library, you must include <glib/gi18n-
lib.h> after defining the GETTEXT_PACKAGE macro suitably for your
library:
#define GETTEXT_PACKAGE "gtk20"
#include <glib/gi18n-lib.h>
==================
https://developer.gnome.org/glib/stable/glib-I18N.html
>
> Note that if I call setlocale before calling bindtextdomain it's
> working,
> however does not seems that great to call setlocale in a library
> initialization.
>
> Looked at other library strategy. Looks like that or they call
> setlocale (only LC_MESSAGES/LC_CTYPE should be fine) or they
> wrap gettext and similar functions into function that call a
> function that the first time call bindtextdomain (glib does this).
>
> Frediano
>
> >
> > >
> > >
> > > Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
> > > ---
> > > src/Makefile.am | 3 +++
> > > src/spice-glib-main.c | 52
> > > +++++++++++++++++++++++++++++++++++++++++++++++++++
> > > 2 files changed, 55 insertions(+)
> > > create mode 100644 src/spice-glib-main.c
> > >
> > > diff --git a/src/Makefile.am b/src/Makefile.am
> > > index fc84e30..53987dd 100644
> > > --- a/src/Makefile.am
> > > +++ b/src/Makefile.am
> > > @@ -104,6 +104,7 @@ SPICE_COMMON_CPPFLAGS =
> > > \
> > > $(NULL)
> > >
> > > AM_CPPFLAGS = \
> > > + -DLOCALE_DIR=\""$(datadir)/locale"\" \
> > > $(SPICE_COMMON_CPPFLAGS) \
> > > $(SPICE_CFLAGS) \
> > > $(NULL)
> > > @@ -276,6 +277,8 @@ libspice_client_glib_2_0_la_SOURCES =
> > > \
> > > \
> > > client_sw_canvas.c \
> > > client_sw_canvas.h \
> > > + \
> > > + spice-glib-main.c \
> >
> > tbh, I would prefer -init.c or -constructor.c
> >
> > >
> > > $(NULL)
> > >
> > > nodist_libspice_client_glib_2_0_la_SOURCES = \
> > > diff --git a/src/spice-glib-main.c b/src/spice-glib-main.c
> > > new file mode 100644
> > > index 0000000..c2bd7ca
> > > --- /dev/null
> > > +++ b/src/spice-glib-main.c
> > > @@ -0,0 +1,52 @@
> > > +/* -*- Mode: C; c-basic-offset: 4; indent-tabs-mode: nil -*- */
> > > +/*
> > > + Copyright (C) 2016 Red Hat, Inc.
> > > +
> > > + This library is free software; you can redistribute it and/or
> > > + modify it under the terms of the GNU Lesser General Public
> > > + License as published by the Free Software Foundation; either
> > > + version 2.1 of the License, or (at your option) any later
> > > version.
> > > +
> > > + This library is distributed in the hope that it will be
> > > useful,
> > > + but WITHOUT ANY WARRANTY; without even the implied warranty
> > > of
> > > + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> > > GNU
> > > + Lesser General Public License for more details.
> > > +
> > > + You should have received a copy of the GNU Lesser General
> > > Public
> > > + License along with this library; if not, see
> > > <http://www.gnu.org/licenses/>.
> > > +*/
> > > +#include "config.h"
> > > +
> > > +#include <glib.h>
> > > +#include <glib/gi18n-lib.h>
> > > +#include <common/macros.h>
> > > +
> > > +#ifdef G_OS_WIN32
> > > +#define WIN32_LEAN_AND_MEAN
> > > +#include <windows.h>
> > > +
> > > +BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID
> > > lpvReserved);
> > > +
> > > +BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID
> > > lpvReserved)
> > > +{
> > > + if (fdwReason == DLL_PROCESS_ATTACH) {
> > > + char *basedir =
> > > +
> > > g_win32_get_package_installation_directory_of_module(hinstDLL);
> > > + char *localedir = g_build_filename(basedir, "share",
> > > "locale",
> > > NULL);
> > > + bindtextdomain(GETTEXT_PACKAGE, localedir);
> > > + g_free(localedir);
> > > + g_free(basedir);
> > > + bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
> > > + }
> > > + return TRUE;
> > > +}
> > > +
> > > +#else
> > > +
> > > +SPICE_CONSTRUCTOR_FUNC(i18n_init)
> > > +{
> > > + bindtextdomain (GETTEXT_PACKAGE, LOCALE_DIR);
> > > + bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
> > > +}
> > > +
> > > +#endif
> _______________________________________________
> Spice-devel mailing list
> Spice-devel at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/spice-devel
More information about the Spice-devel
mailing list