[Spice-devel] [spice-gtk] Initialise gettext library properly

Frediano Ziglio fziglio at redhat.com
Wed Aug 17 16:34:06 UTC 2016


> 
> 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.

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


More information about the Spice-devel mailing list