From 8e6423a1b6e08e140a888df5398206640deea59e Mon Sep 17 00:00:00 2001
From: Takao Fujiwara <takao.fujiwara@sun.com>
Date: Tue, 6 Jan 2009 12:11:07 +0000
Subject: [PATCH] Bug 1397 - Allow localizing the command line help

Clutter has a set of command line options that are added to every
application by means of clutter_init() or by obtaining the Clutter
GOptionGroup and using g_option_context_parse(). Thus, every Clutter
application will automatically have an --help command line switch
showing the list of options and their description.

At the moment, Clutter does not enable localization of the help,
thus making it less than useful on non-English locales.

This patch enables the machinery to create a localization file and
load it when initializing Clutter, by means of the GLib macros and
locale.h API we already use.

Signed-off-by: Emmanuele Bassi <ebassi@linux.intel.com>
---
 clutter/clutter-main.c            | 18 +++++++++++-------
 clutter/glx/clutter-backend-glx.c |  4 +++-
 clutter/x11/clutter-backend-x11.c |  8 +++++---
 configure.ac                      |  1 +
 po/POTFILES.in                    | 14 ++++++++++++++
 5 files changed, 34 insertions(+), 11 deletions(-)

diff --git a/clutter/clutter-main.c b/clutter/clutter-main.c
index 9edbce8c6..994a844da 100644
--- a/clutter/clutter-main.c
+++ b/clutter/clutter-main.c
@@ -1142,16 +1142,16 @@ clutter_init_real (GError **error)
 
 static GOptionEntry clutter_args[] = {
   { "clutter-show-fps", 0, 0, G_OPTION_ARG_NONE, &clutter_show_fps,
-    "Show frames per second", NULL },
+    N_("Show frames per second"), NULL },
   { "clutter-default-fps", 0, 0, G_OPTION_ARG_INT, &clutter_default_fps,
-    "Default frame rate", "FPS" },
+    N_("Default frame rate"), "FPS" },
   { "g-fatal-warnings", 0, 0, G_OPTION_ARG_NONE, &clutter_fatal_warnings,
-    "Make all warnings fatal", NULL },
+    N_("Make all warnings fatal"), NULL },
 #ifdef CLUTTER_ENABLE_DEBUG
   { "clutter-debug", 0, 0, G_OPTION_ARG_CALLBACK, clutter_arg_debug_cb,
-    "Clutter debugging flags to set", "FLAGS" },
+    N_("Clutter debugging flags to set"), "FLAGS" },
   { "clutter-no-debug", 0, 0, G_OPTION_ARG_CALLBACK, clutter_arg_no_debug_cb,
-    "Clutter debugging flags to unset", "FLAGS" },
+    N_("Clutter debugging flags to unset"), "FLAGS" },
 #endif /* CLUTTER_ENABLE_DEBUG */
   { NULL, },
 };
@@ -1294,13 +1294,14 @@ clutter_get_option_group (void)
   context = clutter_context_get_default ();
 
   group = g_option_group_new ("clutter",
-                              "Clutter Options",
-                              "Show Clutter Options",
+                              _("Clutter Options"),
+                              _("Show Clutter Options"),
                               NULL,
                               NULL);
 
   g_option_group_set_parse_hooks (group, pre_parse_hook, post_parse_hook);
   g_option_group_add_entries (group, clutter_args);
+  g_option_group_set_translation_domain (group, GETTEXT_PACKAGE);
 
   /* add backend-specific options */
   _clutter_backend_add_options (context->backend, group);
@@ -2118,6 +2119,9 @@ clutter_base_init (void)
 
       initialised = TRUE;
 
+      bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
+      bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+
       /* initialise GLib type system */
       g_type_init ();
 
diff --git a/clutter/glx/clutter-backend-glx.c b/clutter/glx/clutter-backend-glx.c
index 9f4f47b4a..71276d161 100644
--- a/clutter/glx/clutter-backend-glx.c
+++ b/clutter/glx/clutter-backend-glx.c
@@ -29,6 +29,8 @@
 #include <unistd.h>
 #endif
 
+#include <glib/gi18n-lib.h>
+
 #include <sys/stat.h>
 #include <sys/ioctl.h>
 #include <fcntl.h>
@@ -150,7 +152,7 @@ static const GOptionEntry entries[] =
   { "vblank", 0, 
     0, 
     G_OPTION_ARG_STRING, &clutter_vblank_name,
-    "VBlank method to be used (none, dri or glx)", "METHOD" 
+    N_("VBlank method to be used (none, dri or glx)"), "METHOD"
   },
   { NULL }
 };
diff --git a/clutter/x11/clutter-backend-x11.c b/clutter/x11/clutter-backend-x11.c
index f05589b9f..412bb77da 100644
--- a/clutter/x11/clutter-backend-x11.c
+++ b/clutter/x11/clutter-backend-x11.c
@@ -23,6 +23,8 @@
 #include "config.h"
 #endif
 
+#include <glib/gi18n-lib.h>
+
 #include <string.h>
 #include <sys/types.h>
 #ifdef HAVE_UNISTD_H
@@ -235,18 +237,18 @@ static const GOptionEntry entries[] =
     "display", 0,
     G_OPTION_FLAG_IN_MAIN,
     G_OPTION_ARG_STRING, &clutter_display_name,
-    "X display to use", "DISPLAY"
+    N_("X display to use"), "DISPLAY"
   },
   {
     "screen", 0,
     G_OPTION_FLAG_IN_MAIN,
     G_OPTION_ARG_INT, &clutter_screen,
-    "X screen to use", "SCREEN"
+    N_("X screen to use"), "SCREEN"
   },
   { "synch", 0,
     0,
     G_OPTION_ARG_NONE, &clutter_synchronise,
-    "Make X calls synchronous", NULL,
+    N_("Make X calls synchronous"), NULL,
   },
   { NULL }
 };
diff --git a/configure.ac b/configure.ac
index 4913faf86..ccfc2e0f5 100644
--- a/configure.ac
+++ b/configure.ac
@@ -637,6 +637,7 @@ AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE, "$GETTEXT_PACKAGE",
 
 ALL_LINGUAS=""
 AM_GLIB_GNU_GETTEXT
+GLIB_DEFINE_LOCALEDIR(LOCALEDIR)
 
 AC_CONFIG_FILES([
         Makefile
diff --git a/po/POTFILES.in b/po/POTFILES.in
index e69de29bb..76922d195 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -0,0 +1,14 @@
+clutter/clutter-actor.c
+clutter/clutter-behaviour.c
+clutter/clutter-color.c
+clutter/clutter-container.c
+clutter/clutter-event.c
+clutter/clutter-fixed.c
+clutter/clutter-fixed.h
+clutter/clutter-main.c
+clutter/clutter-stage-window.c
+clutter/clutter-stage.c
+clutter/clutter-texture.c
+clutter/clutter-units.c
+clutter/glx/clutter-backend-glx.c
+clutter/x11/clutter-backend-x11.c