speechd-discuss
[Top][All Lists]
Advanced

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

[PATCH 1/2] Add i18n utilities to common library


From: Rui Batista
Subject: [PATCH 1/2] Add i18n utilities to common library
Date: Wed, 6 Oct 2010 14:30:03 +0100

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 |    6 ++++--
 src/common/i18n.c      |   43 +++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 86 insertions(+), 3 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..746909a
--- /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 i18n_init(void);
+
+#endif
diff --git a/src/common/Makefile.am b/src/common/Makefile.am
index 68c5766..139ba32 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
+libcommon_la_SOURCES = fdsetconv.c spd_getline.c i18n.c
+
diff --git a/src/common/i18n.c b/src/common/i18n.c
new file mode 100644
index 0000000..e23bbbf
--- /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 i18n_init(void)
+{
+       setlocale(LC_ALL, "");
+
+       if(bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR) == NULL) {
+               abort();
+       }
+
+       if(textdomain(GETTEXT_PACKAGE) == NULL) {
+               abort();
+       }
+}
-- 
1.7.0.4




reply via email to

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