summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorP. F. Chimento <philip.chimento@gmail.com>2013-04-07 04:19:32 +0200
committerP. F. Chimento <philip.chimento@gmail.com>2013-04-17 17:15:52 +0200
commit89671a4914caf1e20ea20a19c6bff7a058ebb3c4 (patch)
treea99b4544f888cfe6b6bbf99c4e0519117d40e89d
parent408f93ec2327a8647030139a2e6f295e8b2c8de1 (diff)
Internationalize the shared library
Add infrastructure for translating the single string in the shared library. [#1]
-rw-r--r--.gitignore47
-rw-r--r--Makefile.am5
-rwxr-xr-xautogen.sh5
-rw-r--r--configure.ac13
-rw-r--r--endless/Makefile.am3
-rw-r--r--endless/hello.c5
-rw-r--r--endless/init.c40
-rw-r--r--m4/as-linguas.m426
-rw-r--r--po/Makevars41
-rw-r--r--po/POTFILES.in2
-rw-r--r--po/pt_BR.po22
11 files changed, 206 insertions, 3 deletions
diff --git a/.gitignore b/.gitignore
index 6877869..aff4368 100644
--- a/.gitignore
+++ b/.gitignore
@@ -12,6 +12,7 @@ endless-0.pc
# Autotools droppings
.deps
.libs
+stamp*
/Makefile
/Makefile.in
/aclocal.m4
@@ -29,6 +30,51 @@ endless-0.pc
/m4/ltsugar.m4
/m4/ltversion.m4
+# Gettext droppings
+/ABOUT-NLS
+/po/Makefile*
+/po/POTFILES
+/po/Rules-quot
+/po/boldquot.sed
+/po/en@boldquot.header
+/po/en@quot.header
+/po/eos-sdk.pot
+/po/insert-header.sin
+/po/quot.sed
+/po/remove-potcdate.sed
+/po/remove-potcdate.sin
+/m4/codeset.m4
+/m4/fcntl-o.m4
+/m4/gettext.m4
+/m4/glibc21.m4
+/m4/glibc2.m4
+/m4/iconv.m4
+/m4/intdiv0.m4
+/m4/intldir.m4
+/m4/intl.m4
+/m4/intlmacosx.m4
+/m4/intmax.m4
+/m4/inttypes_h.m4
+/m4/inttypes-pri.m4
+/m4/lcmessage.m4
+/m4/lib-ld.m4
+/m4/lib-link.m4
+/m4/lib-prefix.m4
+/m4/lock.m4
+/m4/longlong.m4
+/m4/nls.m4
+/m4/po.m4
+/m4/printf-posix.m4
+/m4/progtest.m4
+/m4/size_max.m4
+/m4/stdint_h.m4
+/m4/threadlib.m4
+/m4/uintmax_t.m4
+/m4/visibility.m4
+/m4/wchar_t.m4
+/m4/wint_t.m4
+/m4/xsize.m4
+
# Packages
*.egg
*.egg-info
@@ -54,6 +100,7 @@ nosetests.xml
# Translations
*.mo
+*.gmo
# Mr Developer
.mr.developer.cfg
diff --git a/Makefile.am b/Makefile.am
index 544ef5b..d4a27a0 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -7,12 +7,17 @@
## -----------
## Please keep this file well-commented.
+# Subdirectories where we also want to run make
+SUBDIRS = po
+
# Our Autoconf macros are kept in the m4/ directory
ACLOCAL_AMFLAGS = -I m4
# Extra files to distribute in the tarball
EXTRA_DIST = @EOS_SDK_API_NAME@.pc.in
+# Compiler flags
+DEFS = -DLOCALEDIR=\"$(localedir)\" @DEFS@
AM_CFLAGS = @STRICT_CFLAGS@
DISTCLEANFILES =
diff --git a/autogen.sh b/autogen.sh
index 4c5ae11..7f94f51 100755
--- a/autogen.sh
+++ b/autogen.sh
@@ -2,6 +2,7 @@
# Run this script on a clean source checkout to get ready for building.
FILE_MUST_EXIST=endless/endless.h
+POT_FILE=po/eos-sdk.pot
test -n "$srcdir" || srcdir=`dirname "$0"`
test -n "$srcdir" || srcdir=.
@@ -13,6 +14,10 @@ test -f $FILE_MUST_EXIST || {
exit 1
}
+# GNU gettext automake support doesn't get along with git
+# https://bugzilla.gnome.org/show_bug.cgi?id=661128
+touch -t 200001010000 $POT_FILE
+
# NOCONFIGURE is used by gnome-common
if test -z "$NOCONFIGURE"; then
echo "This script will run ./configure automatically. If you wish to pass "
diff --git a/configure.ac b/configure.ac
index b2404b5..ecf750e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -80,6 +80,14 @@ EOS_REQUIRED_MODULES_PRIVATE="$GLIB_REQUIREMENT $GOBJECT_REQUIREMENT $GIO_REQUIR
AC_SUBST(EOS_REQUIRED_MODULES)
AC_SUBST(EOS_REQUIRED_MODULES_PRIVATE)
+# Gettext package name
+GETTEXT_PACKAGE=$PACKAGE
+AC_SUBST(GETTEXT_PACKAGE)
+AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE, ["$GETTEXT_PACKAGE"],
+ [Package name for Gettext])
+# Detect which languages are available
+AS_ALL_LINGUAS
+
# Configure options
# -----------------
# --enable-strict-flags: Compile with strict compiler flags. Done automatically
@@ -125,6 +133,9 @@ AC_SUBST(STRICT_CFLAGS)
AC_PROG_CC
# Library configuration tool
PKG_PROG_PKG_CONFIG
+# Gettext
+AM_GNU_GETTEXT([external])
+AM_GNU_GETTEXT_VERSION([0.18.1])
# Required libraries
# ------------------
@@ -137,8 +148,10 @@ PKG_CHECK_MODULES([EOS_SDK], [
# List files here that the configure script should output
AC_CONFIG_FILES([
Makefile
+ po/Makefile.in
$EOS_SDK_API_NAME.pc
])
+AC_CONFIG_HEADERS([config.h]) dnl Header with system-dependent #defines
# Do the output
AC_OUTPUT
diff --git a/endless/Makefile.am b/endless/Makefile.am
index 92c9ab3..89af544 100644
--- a/endless/Makefile.am
+++ b/endless/Makefile.am
@@ -9,7 +9,8 @@ endless_private_installed_headers = \
endless/types.h
endless_library_sources = \
- endless/hello.c
+ endless/hello.c \
+ endless/init.c
# Endless GUI library
lib_LTLIBRARIES = libendless-@EOS_SDK_API_VERSION@.la
diff --git a/endless/hello.c b/endless/hello.c
index 1db6f90..83be05a 100644
--- a/endless/hello.c
+++ b/endless/hello.c
@@ -1,7 +1,9 @@
/* Copyright 2013 Endless Mobile, Inc. */
+#include <config.h>
#include <string.h>
#include <glib.h>
+#include <glib/gi18n-lib.h>
#include <gio/gio.h>
#include <endless/endless.h>
@@ -29,7 +31,7 @@ gboolean
eos_hello_sample_function(GFile *file,
GError **error)
{
- char hello_string[] = "Hello, world!\n";
+ char *hello_string = _("Hello, world!\n");
GFileOutputStream *stream;
ssize_t write_count;
gboolean success;
@@ -66,4 +68,3 @@ eos_hello_sample_function(GFile *file,
return TRUE;
}
-
diff --git a/endless/init.c b/endless/init.c
new file mode 100644
index 0000000..69ce87b
--- /dev/null
+++ b/endless/init.c
@@ -0,0 +1,40 @@
+/* Copyright 2013 Endless Mobile, Inc. */
+
+#include <config.h>
+#include <glib.h>
+#include <glib/gi18n-lib.h>
+
+/* Constructors supported since GCC 2.7; I have this on GLib's authority. This
+should also work on Clang. */
+#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7)
+
+#define _EOS_CONSTRUCTOR(func) static void __attribute__((constructor)) func (void);
+#define _EOS_DESTRUCTOR(func) static void __atrribute__((destructor)) func (void);
+
+#else
+
+#error "We do not currently support constructors for your compiler."
+
+#endif /* compiler version */
+
+static gboolean _eos_initialized = FALSE;
+
+/*
+ * _eos_init:
+ *
+ * This function initializes the library. It is called automatically when the
+ * library is loaded.
+ */
+_EOS_CONSTRUCTOR(_eos_init);
+static void
+_eos_init (void)
+{
+ if (G_UNLIKELY (!_eos_initialized))
+ {
+ /* Initialize Gettext */
+ bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
+ bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+
+ _eos_initialized = TRUE;
+ }
+}
diff --git a/m4/as-linguas.m4 b/m4/as-linguas.m4
new file mode 100644
index 0000000..8b4e07f
--- /dev/null
+++ b/m4/as-linguas.m4
@@ -0,0 +1,26 @@
+# Set ALL_LINGUAS based on the .po files present. Optional argument is the
+# name of the po directory. $podir/LINGUAS.ignore can be used to ignore a
+# subset of the po files.
+
+# Public domain, according to Emmanuele
+
+AC_DEFUN([AS_ALL_LINGUAS],
+[
+ AC_MSG_CHECKING([for linguas])
+ podir="m4_default([$1],[$srcdir/po])"
+ linguas=`cd $podir && ls *.po 2>/dev/null | awk 'BEGIN { FS="."; ORS=" " } { print $[]1 }'`
+ if test -f "$podir/LINGUAS.ignore"; then
+ ALL_LINGUAS="";
+ ignore_linguas=`sed -n -e 's/^\s\+\|\s\+$//g' -e '/^#/b' -e '/\S/!b' \
+ -e 's/\s\+/\n/g' -e p "$podir/LINGUAS.ignore"`;
+ for lang in $linguas; do
+ if ! echo "$ignore_linguas" | grep -q "^${lang}$"; then
+ ALL_LINGUAS="$ALL_LINGUAS $lang";
+ fi;
+ done;
+ else
+ ALL_LINGUAS="$linguas";
+ fi;
+ AC_SUBST([ALL_LINGUAS])
+ AC_MSG_RESULT($ALL_LINGUAS)
+])
diff --git a/po/Makevars b/po/Makevars
new file mode 100644
index 0000000..03b5cc3
--- /dev/null
+++ b/po/Makevars
@@ -0,0 +1,41 @@
+# Makefile variables for PO directory in any package using GNU gettext.
+
+# The domain is the same as the package name defined in configure.ac.
+DOMAIN = $(PACKAGE)
+
+# These two variables depend on the location of this directory.
+subdir = po
+top_builddir = ..
+
+# These options get passed to xgettext.
+XGETTEXT_OPTIONS = --keyword=_ --keyword=N_
+
+# This is the copyright holder that gets inserted into the header of the
+# $(DOMAIN).pot file. Set this to the copyright holder of the surrounding
+# package. (Note that the msgstr strings, extracted from the package's
+# sources, belong to the copyright holder of the package.) Translators are
+# expected to transfer the copyright for their translations to this person
+# or entity, or to disclaim their copyright. The empty string stands for
+# the public domain; in this case the translators are expected to disclaim
+# their copyright.
+COPYRIGHT_HOLDER = Endless Mobile, Inc.
+
+# This is the email address or URL to which the translators shall report
+# bugs in the untranslated strings:
+# - Strings which are not entire sentences, see the maintainer guidelines
+# in the GNU gettext documentation, section 'Preparing Strings'.
+# - Strings which use unclear terms or require additional context to be
+# understood.
+# - Strings which make invalid assumptions about notation of date, time or
+# money.
+# - Pluralisation problems.
+# - Incorrect English spelling.
+# - Incorrect formatting.
+# It can be your email address, or a mailing list address where translators
+# can write to without being subscribed, or the URL of a web page through
+# which the translators can contact you.
+MSGID_BUGS_ADDRESS = philip@endlessm.com
+
+# This is the list of locale categories, beyond LC_MESSAGES, for which the
+# message catalogs shall be used. It is usually empty.
+EXTRA_LOCALE_CATEGORIES =
diff --git a/po/POTFILES.in b/po/POTFILES.in
new file mode 100644
index 0000000..bc44e28
--- /dev/null
+++ b/po/POTFILES.in
@@ -0,0 +1,2 @@
+# List of source files which contain translatable strings.
+endless/hello.c
diff --git a/po/pt_BR.po b/po/pt_BR.po
new file mode 100644
index 0000000..68e2b87
--- /dev/null
+++ b/po/pt_BR.po
@@ -0,0 +1,22 @@
+# Portuguese translations for open-endless-sdk package.
+# Copyright (C) 2013 Endless Mobile, Inc.
+# This file is distributed under the same license as the open-endless-sdk package.
+# Philip Chimento <l10n@endlessm.com>, 2013.
+#
+msgid ""
+msgstr ""
+"Project-Id-Version: open-endless-sdk 0.0\n"
+"Report-Msgid-Bugs-To: philip@endlessm.com\n"
+"POT-Creation-Date: 2013-04-12 15:56+0100\n"
+"PO-Revision-Date: 2013-04-07 03:03+0200\n"
+"Last-Translator: Philip Chimento <l10n@endlessm.com>\n"
+"Language-Team: Brazilian Portuguese\n"
+"Language: pt_BR\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=ISO-8859-1\n"
+"Content-Transfer-Encoding: 8bit\n"
+"Plural-Forms: nplurals=2; plural=(n > 1);\n"
+
+#: endless/hello.c:35
+msgid "Hello, world!\n"
+msgstr "Bom dia, mundo!\n"