speechd-discuss
[Top][All Lists]
Advanced

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

[PATCH] Add i18n utilities to common library


From: Rui Batista
Subject: [PATCH] Add i18n utilities to common library
Date: Wed, 06 Oct 2010 14:08:45 +0100

Please disregard, forgot to add i18n.c to src/comm/Makefile.am.

Will send it along with i18n support to the server options and help
strings.


Regards,
Qua, 2010-10-06 ?s 11:37 +0100, Rui Batista escreveu:
> This patches adds internationalization support to the common library.
> the i18n_init function should be called before
> any gettext translation function usage.
> 
> The include/i18n.h contains the i18n_init declaration and includes the
> glib i18n headers for convenience.
> ---
>  include/Makefile.am    |    2 +-
>  include/i18n.h         |   38 ++++++++++++++++++++++++++++++++++++++
>  src/common/Makefile.am |    4 +++-
>  src/common/i18n.c      |   43 +++++++++++++++++++++++++++++++++++++++++++
>  4 files changed, 85 insertions(+), 2 deletions(-)
>  create mode 100644 include/i18n.h
>  create mode 100644 src/common/i18n.c
> 
> diff --git a/include/Makefile.am b/include/Makefile.am
> index 4597166..9bec647 100644
> --- a/include/Makefile.am
> +++ b/include/Makefile.am
> @@ -1,4 +1,4 @@
>  ## Process this file with automake to produce Makefile.in
>  
> -noinst_HEADERS = fdsetconv.h speechd_types.h spd_utils.h
> +noinst_HEADERS = fdsetconv.h speechd_types.h spd_utils.h i18n.h
>  
> diff --git a/include/i18n.h b/include/i18n.h
> new file mode 100644
> index 0000000..ad0988e
> --- /dev/null
> +++ b/include/i18n.h
> @@ -0,0 +1,38 @@
> +/*
> + * i18n.h - i18n support for Speech Dispatcher
> + *
> + * Copyright (C) 2010 Brailcom, o.p.s.
> + *
> + * This is free software; you can redistribute it and/or modify it
> + * under the terms of the GNU General Public License as published by
> + * the Free Software Foundation; either version 2, or (at your option)
> + * any later version.
> + *
> + * This software 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
> + * General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this package; see the file COPYING.  If not, write to
> + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
> + * Boston, MA 02110-1301, USA.
> + *
> + */
> +
> +#ifndef I18N_H
> +#define I18N_H
> +#include <glib/gi18n.h>
> +
> +/*
> +* Inits i18n support for Speech Dispatcher components
> +* This function must be called before any component outputs messages
> +* that should be translated to the user.
> +* It obtains the current locale from environment variables,
> +* See setlocale (3) for more information.
> +* If the initialization support fails because of out of memory errors,
> +* the abort() function is called.
> +*/
> +void init_i18n(void);
> +
> +#endif
> diff --git a/src/common/Makefile.am b/src/common/Makefile.am
> index 68c5766..8f25bc2 100644
> --- a/src/common/Makefile.am
> +++ b/src/common/Makefile.am
> @@ -1,7 +1,9 @@
>  ## Process this file with automake to produce Makefile.in
>  
>  noinst_LTLIBRARIES = libcommon.la
> -libcommon_la_CFLAGS = $(ERROR_CFLAGS)
> +libcommon_la_CFLAGS = $(ERROR_CFLAGS) $(GLIB_CFLAGS) \
> +-DGETTEXT_PACKAGE=\"$(GETTEXT_PACKAGE)\" -DLOCALEDIR=\"$(localedir)\"
>  libcommon_la_CPPFLAGS = "-I$(top_srcdir)/include/" $(GLIB_CFLAGS)
>  libcommon_la_LIBADD = $(GLIB_LIBS)
>  libcommon_la_SOURCES = fdsetconv.c spd_getline.c
> +
> diff --git a/src/common/i18n.c b/src/common/i18n.c
> new file mode 100644
> index 0000000..78d7e8f
> --- /dev/null
> +++ b/src/common/i18n.c
> @@ -0,0 +1,43 @@
> +/*
> + * i18n.c - i18n support for Speech-dispatcher
> + *
> + * Copyright (C) 2010 Brailcom, o.p.s.
> + *
> + * This is free software; you can redistribute it and/or modify it
> + * under the terms of the GNU General Public License as published by
> + * the Free Software Foundation; either version 2, or (at your option)
> + * any later version.
> + *
> + * This software 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
> + * General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this package; see the file COPYING.  If not, write to
> + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
> + * Boston, MA 02110-1301, USA.
> + *
> + */
> +
> +#if HAVE_CONFIG_H
> +#include <config.h>
> +#endif
> +
> +#include <i18n.h>
> +#include <locale.h>          /* For setlocale. */
> +#include <stdlib.h>
> +
> +
> +void init_i18n(void)
> +{
> +     setlocale(LC_ALL, "");
> +
> +     if(bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR) == NULL) {
> +             abort();
> +     }
> +
> +     if(textdomain(GETTEXT_PACKAGE) == NULL) {
> +             abort();
> +     }
> +}

Rui Batista
E-mail/googletalk: ruiandrebatista (at) gmail (dot) com
MSN/WLM: ruiandrebatista (at) hotmail (dot) com (don't send mail to this
one)
Skype: ruiandrebatista
twitter: http://twitter.com/ragb
weblog: http://unreliabledevice.net




reply via email to

[Prev in Thread] Current Thread [Next in Thread]