summaryrefslogtreecommitdiff
path: root/endless
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 /endless
parent408f93ec2327a8647030139a2e6f295e8b2c8de1 (diff)
Internationalize the shared library
Add infrastructure for translating the single string in the shared library. [#1]
Diffstat (limited to 'endless')
-rw-r--r--endless/Makefile.am3
-rw-r--r--endless/hello.c5
-rw-r--r--endless/init.c40
3 files changed, 45 insertions, 3 deletions
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;
+ }
+}