Add i18n support with gettext
authorJavier Jardón <javier.jardon@codethink.co.uk>
Mon, 28 Mar 2011 17:47:30 +0000 (18:47 +0100)
committerJavier Jardón <jjardon@gnome.org>
Mon, 28 Mar 2011 17:47:30 +0000 (18:47 +0100)
Makefile.am
config.vapi [new file with mode: 0644]
configure.ac
po/Makevars [new file with mode: 0644]
po/POTFILES.in [new file with mode: 0644]
src/moonshot-window.vala

index fdc3ce5..03e39a4 100644 (file)
@@ -1,13 +1,17 @@
 ACLOCAL_AMFLAGS = -I m4 ${ACLOCAL_FLAGS}
 
+SUBDIRS = po
+
 bin_PROGRAMS = src/moonshot
 
 
 AM_CPPFLAGS = \
        -include config.h \
+       -DLOCALEDIR=\""$(localedir)"\" \
        $(moonshot_CFLAGS)
 
 AM_VALAFLAGS = \
+       config.vapi \
        --pkg gtk+-2.0
 
 src_moonshot_SOURCES = \
diff --git a/config.vapi b/config.vapi
new file mode 100644 (file)
index 0000000..6e2f2ae
--- /dev/null
@@ -0,0 +1,15 @@
+[CCode (prefix = "", lower_case_cprefix = "", cheader_filename = "config.h")]
+namespace Config
+{
+        /* Package information */
+        public const string PACKAGE_NAME;
+        public const string PACKAGE_STRING;
+        public const string PACKAGE_VERSION;
+
+        /* Gettext package */
+        public const string GETTEXT_PACKAGE;
+
+        /* Configured paths - these variables are not present in config.h, they are
+         * passed to underlying C code as cmd line macros. */
+        public const string LOCALEDIR;
+}
index 34f258e..a1ebb36 100644 (file)
@@ -24,8 +24,16 @@ PKG_CHECK_MODULES(moonshot,[
         gtk+-2.0 >= 2.22
 ])
 
+# i18n stuff
+AM_GNU_GETTEXT([external])
+AM_GNU_GETTEXT_VERSION([0.18.1])
+
+AC_SUBST([GETTEXT_PACKAGE],[PACKAGE_TARNAME])
+AC_DEFINE([GETTEXT_PACKAGE],[PACKAGE_TARNAME],[Define to the gettext package name.])
+
 AC_CONFIG_FILES([
         Makefile
+        po/Makefile.in
 ])
 
 AC_OUTPUT
diff --git a/po/Makevars b/po/Makevars
new file mode 100644 (file)
index 0000000..32692ab
--- /dev/null
@@ -0,0 +1,41 @@
+# Makefile variables for PO directory in any package using GNU gettext.
+
+# Usually the message domain is the same as the package name.
+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 = Free Software Foundation, 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 =
+
+# 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 (file)
index 0000000..667e27c
--- /dev/null
@@ -0,0 +1 @@
+# List of source files which contain translatable strings.
index 0d55ffd..681356e 100644 (file)
@@ -11,6 +11,10 @@ class MainWindow : Window
     {
         Gtk.init(ref args);
 
+        Intl.bindtextdomain (Config.GETTEXT_PACKAGE, Config.LOCALEDIR);
+        Intl.bind_textdomain_codeset (Config.GETTEXT_PACKAGE, "UTF-8");
+        Intl.textdomain (Config.GETTEXT_PACKAGE);
+
         var window = new MainWindow();
         window.show();