From 89671a4914caf1e20ea20a19c6bff7a058ebb3c4 Mon Sep 17 00:00:00 2001 From: "P. F. Chimento" Date: Sun, 7 Apr 2013 04:19:32 +0200 Subject: Internationalize the shared library Add infrastructure for translating the single string in the shared library. [#1] --- endless/Makefile.am | 3 ++- endless/hello.c | 5 +++-- endless/init.c | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 endless/init.c (limited to 'endless') 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 #include #include +#include #include #include @@ -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 +#include +#include + +/* 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; + } +} -- cgit v1.2.3