]> Pileus Git - ~andy/gtk/commitdiff
New function which allows to change the function used for translation
authorMatthias Clasen <mclasen@redhat.com>
Thu, 3 Feb 2005 17:46:40 +0000 (17:46 +0000)
committerMatthias Clasen <matthiasc@src.gnome.org>
Thu, 3 Feb 2005 17:46:40 +0000 (17:46 +0000)
2005-02-03  Matthias Clasen  <mclasen@redhat.com>

* gtk/gtk.symbols:
* gtk/gtkstock.h:
* gtk/gtkstock.c (gtk_stock_set_translate_func):
New function which allows to change the function used for
translation stock labels, on a per-domain basis. Use this
functionality to switch the GTK+ stock items to use Q_()
prefixed msgids.  (#166179, Funda Wang)

ChangeLog
ChangeLog.pre-2-10
ChangeLog.pre-2-8
docs/reference/ChangeLog
docs/reference/gtk/gtk-sections.txt
gtk/gtk.symbols
gtk/gtkstock.c
gtk/gtkstock.h

index 7cda5d5f62e050a3556f99a888602139edd832fc..a02f78353c5374e976e70efc4f34efe58f19a9b8 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
 2005-02-03  Matthias Clasen  <mclasen@redhat.com>
 
+       * gtk/gtk.symbols: 
+       * gtk/gtkstock.h: 
+       * gtk/gtkstock.c (gtk_stock_set_translate_func): 
+       New function which allows to change the function used for
+       translation stock labels, on a per-domain basis. Use this
+       functionality to switch the GTK+ stock items to use Q_()
+       prefixed msgids.  (#166179, Funda Wang)
+       
        * gdk/gdkkeynames.c: Make the gdk_key array const (#166075,
        Tommi Komulainen)
 
index 7cda5d5f62e050a3556f99a888602139edd832fc..a02f78353c5374e976e70efc4f34efe58f19a9b8 100644 (file)
@@ -1,5 +1,13 @@
 2005-02-03  Matthias Clasen  <mclasen@redhat.com>
 
+       * gtk/gtk.symbols: 
+       * gtk/gtkstock.h: 
+       * gtk/gtkstock.c (gtk_stock_set_translate_func): 
+       New function which allows to change the function used for
+       translation stock labels, on a per-domain basis. Use this
+       functionality to switch the GTK+ stock items to use Q_()
+       prefixed msgids.  (#166179, Funda Wang)
+       
        * gdk/gdkkeynames.c: Make the gdk_key array const (#166075,
        Tommi Komulainen)
 
index 7cda5d5f62e050a3556f99a888602139edd832fc..a02f78353c5374e976e70efc4f34efe58f19a9b8 100644 (file)
@@ -1,5 +1,13 @@
 2005-02-03  Matthias Clasen  <mclasen@redhat.com>
 
+       * gtk/gtk.symbols: 
+       * gtk/gtkstock.h: 
+       * gtk/gtkstock.c (gtk_stock_set_translate_func): 
+       New function which allows to change the function used for
+       translation stock labels, on a per-domain basis. Use this
+       functionality to switch the GTK+ stock items to use Q_()
+       prefixed msgids.  (#166179, Funda Wang)
+       
        * gdk/gdkkeynames.c: Make the gdk_key array const (#166075,
        Tommi Komulainen)
 
index 40f7c5488d25220e87f2522f3b762aed16eab2ca..56308930cac9da093b938046a8db8972f30e4b97 100644 (file)
@@ -1,3 +1,7 @@
+2005-02-03  Matthias Clasen  <mclasen@redhat.com>
+
+       * gtk/gtk-sections.txt: Add gtk_stock_set_translate_func.
+
 2005-02-02  Matthias Clasen  <mclasen@redhat.com>
 
        * gdk/tmpl/event_structs.sgml: 
index 1f3b72c830357d7a469f3ef86d6f90f2c92aafc7..67d90fcd69fe60c65e40c8b079d8991bc604b1b4 100644 (file)
@@ -5363,6 +5363,7 @@ gtk_stock_item_copy
 gtk_stock_item_free
 gtk_stock_list_ids
 gtk_stock_lookup
+gtk_stock_set_translate_func
 <SUBSECTION Stock IDs>
 GTK_STOCK_ABOUT
 GTK_STOCK_ADD
index 902da3b546727407420e8d455bfaededd07bb0b3..bd5c90e63b0556b48794ab50b8343fa89d686e1b 100644 (file)
@@ -1946,6 +1946,7 @@ gtk_stock_item_copy
 gtk_stock_item_free
 gtk_stock_list_ids
 gtk_stock_lookup
+gtk_stock_set_translate_func
 gtk_style_apply_default_background
 gtk_style_attach
 gtk_style_copy
index 247ac94b15fcdbd83c41c68c1586c87f9c7b5318..606df1b3002f0b6056496de06cc68e6ee58f6359 100644 (file)
@@ -33,6 +33,7 @@
 #include "gtkintl.h"
 #include <gdk/gdkkeysyms.h>
 
+static GHashTable *translate_hash = NULL;
 static GHashTable *stock_hash = NULL;
 static void init_stock_hash (void);
 
@@ -41,6 +42,14 @@ static void init_stock_hash (void);
  */
 #define NON_STATIC_MASK (1 << 29)
 
+typedef struct _GtkStockTranslateFunc GtkStockTranslateFunc;
+struct _GtkStockTranslateFunc
+{
+  GtkTranslateFunc func;
+  gpointer data;
+  GtkDestroyNotify notify;
+};
+
 static void
 real_add (const GtkStockItem *items,
           guint               n_items,
@@ -155,7 +164,17 @@ gtk_stock_lookup (const gchar  *stock_id,
       *item = *found;
       item->modifier &= ~NON_STATIC_MASK;
       if (item->label)
-        item->label = dgettext (item->translation_domain, item->label);
+       {
+         GtkStockTranslateFunc *translate;
+
+         translate = (GtkStockTranslateFunc *) 
+           g_hash_table_lookup (translate_hash, item->translation_domain);
+         
+         if (translate != NULL && translate->func != NULL)
+           item->label = (* translate->func) (item->label, translate->data);
+         else
+           item->label = dgettext (item->translation_domain, item->label);
+       }
     }
 
   return found != NULL;
@@ -308,14 +327,22 @@ static const GtkStockItem builtin_items [] =
   { GTK_STOCK_FIND, N_("_Find"), GDK_CONTROL_MASK, 'f', GETTEXT_PACKAGE },
   { GTK_STOCK_FIND_AND_REPLACE, N_("Find and _Replace"), GDK_CONTROL_MASK, 'r', GETTEXT_PACKAGE },
   { GTK_STOCK_FLOPPY, N_("_Floppy"), 0, 0, GETTEXT_PACKAGE },
-  { GTK_STOCK_GOTO_BOTTOM, N_("_Bottom"), 0, 0, GETTEXT_PACKAGE },
-  { GTK_STOCK_GOTO_FIRST, N_("_First"), 0, 0, GETTEXT_PACKAGE },
-  { GTK_STOCK_GOTO_LAST, N_("_Last"), 0, 0, GETTEXT_PACKAGE },
-  { GTK_STOCK_GOTO_TOP, N_("_Top"), 0, 0, GETTEXT_PACKAGE },
-  { GTK_STOCK_GO_BACK, N_("_Back"), 0, 0, GETTEXT_PACKAGE },
-  { GTK_STOCK_GO_DOWN, N_("_Down"), 0, 0, GETTEXT_PACKAGE },
-  { GTK_STOCK_GO_FORWARD, N_("_Forward"), 0, 0, GETTEXT_PACKAGE },
-  { GTK_STOCK_GO_UP, N_("_Up"), 0, 0, GETTEXT_PACKAGE },
+  /* translators, strip the prefix up to and including the first | */
+  { GTK_STOCK_GOTO_BOTTOM, N_("Navigation|_Bottom"), 0, 0, GETTEXT_PACKAGE },
+  /* translators, strip the prefix up to and including the first | */
+  { GTK_STOCK_GOTO_FIRST, N_("Navigation|_First"), 0, 0, GETTEXT_PACKAGE },
+  /* translators, strip the prefix up to and including the first | */
+  { GTK_STOCK_GOTO_LAST, N_("Navigation|_Last"), 0, 0, GETTEXT_PACKAGE },
+  /* translators, strip the prefix up to and including the first | */
+  { GTK_STOCK_GOTO_TOP, N_("Navigation|_Top"), 0, 0, GETTEXT_PACKAGE },
+  /* translators, strip the prefix up to and including the first | */
+  { GTK_STOCK_GO_BACK, N_("Navigation|_Back"), 0, 0, GETTEXT_PACKAGE },
+  /* translators, strip the prefix up to and including the first | */
+  { GTK_STOCK_GO_DOWN, N_("Navigation|_Down"), 0, 0, GETTEXT_PACKAGE },
+  /* translators, strip the prefix up to and including the first | */
+  { GTK_STOCK_GO_FORWARD, N_("Navigation|_Forward"), 0, 0, GETTEXT_PACKAGE },
+  /* translators, strip the prefix up to and including the first | */
+  { GTK_STOCK_GO_UP, N_("Navigation|_Up"), 0, 0, GETTEXT_PACKAGE },
   { GTK_STOCK_HARDDISK, N_("_Harddisk"), 0, 0, GETTEXT_PACKAGE },
   { GTK_STOCK_HELP, N_("_Help"), GDK_CONTROL_MASK, 'h', GETTEXT_PACKAGE },
   { GTK_STOCK_HOME, N_("_Home"), 0, 0, GETTEXT_PACKAGE },
@@ -324,18 +351,31 @@ static const GtkStockItem builtin_items [] =
   { GTK_STOCK_INDEX, N_("_Index"), 0, 0, GETTEXT_PACKAGE },
   { GTK_STOCK_ITALIC, N_("_Italic"), 0, 0, GETTEXT_PACKAGE },
   { GTK_STOCK_JUMP_TO, N_("_Jump to"), 0, 0, GETTEXT_PACKAGE },
-  { GTK_STOCK_JUSTIFY_CENTER, N_("_Center"), 0, 0, GETTEXT_PACKAGE },
-  { GTK_STOCK_JUSTIFY_FILL, N_("_Fill"), 0, 0, GETTEXT_PACKAGE },
-  { GTK_STOCK_JUSTIFY_LEFT, N_("_Left"), 0, 0, GETTEXT_PACKAGE },
-  { GTK_STOCK_JUSTIFY_RIGHT, N_("_Right"), 0, 0, GETTEXT_PACKAGE },
-  { GTK_STOCK_MEDIA_FORWARD, N_("_Forward"), 0, 0, GETTEXT_PACKAGE },
-  { GTK_STOCK_MEDIA_NEXT, N_("_Next"), 0, 0, GETTEXT_PACKAGE },
-  { GTK_STOCK_MEDIA_PAUSE, N_("P_ause"), 0, 0, GETTEXT_PACKAGE },
-  { GTK_STOCK_MEDIA_PLAY, N_("_Play"), 0, 0, GETTEXT_PACKAGE },
-  { GTK_STOCK_MEDIA_PREVIOUS, N_("Pre_vious"), 0, 0, GETTEXT_PACKAGE },
-  { GTK_STOCK_MEDIA_RECORD, N_("_Record"), 0, 0, GETTEXT_PACKAGE },
-  { GTK_STOCK_MEDIA_REWIND, N_("R_ewind"), 0, 0, GETTEXT_PACKAGE },
-  { GTK_STOCK_MEDIA_STOP, N_("_Stop"), 0, 0, GETTEXT_PACKAGE },
+  /* translators, strip the prefix up to and including the first | */
+  { GTK_STOCK_JUSTIFY_CENTER, N_("Justify|_Center"), 0, 0, GETTEXT_PACKAGE },
+  /* translators, strip the prefix up to and including the first | */
+  { GTK_STOCK_JUSTIFY_FILL, N_("Justify|_Fill"), 0, 0, GETTEXT_PACKAGE },
+  /* translators, strip the prefix up to and including the first | */
+  { GTK_STOCK_JUSTIFY_LEFT, N_("Justify|_Left"), 0, 0, GETTEXT_PACKAGE },
+  /* translators, strip the prefix up to and including the first | */
+  { GTK_STOCK_JUSTIFY_RIGHT, N_("Justify|_Right"), 0, 0, GETTEXT_PACKAGE },
+
+  /* translators, strip the prefix up to and including the first | */
+  { GTK_STOCK_MEDIA_FORWARD, N_("Media|_Forward"), 0, 0, GETTEXT_PACKAGE },
+  /* translators, strip the prefix up to and including the first | */
+  { GTK_STOCK_MEDIA_NEXT, N_("Media|_Next"), 0, 0, GETTEXT_PACKAGE },
+  /* translators, strip the prefix up to and including the first | */
+  { GTK_STOCK_MEDIA_PAUSE, N_("Media|P_ause"), 0, 0, GETTEXT_PACKAGE },
+  /* translators, strip the prefix up to and including the first | */
+  { GTK_STOCK_MEDIA_PLAY, N_("Media|_Play"), 0, 0, GETTEXT_PACKAGE },
+  /* translators, strip the prefix up to and including the first | */
+  { GTK_STOCK_MEDIA_PREVIOUS, N_("Media|Pre_vious"), 0, 0, GETTEXT_PACKAGE },
+  /* translators, strip the prefix up to and including the first | */
+  { GTK_STOCK_MEDIA_RECORD, N_("Media|_Record"), 0, 0, GETTEXT_PACKAGE },
+  /* translators, strip the prefix up to and including the first | */
+  { GTK_STOCK_MEDIA_REWIND, N_("Media|R_ewind"), 0, 0, GETTEXT_PACKAGE },
+  /* translators, strip the prefix up to and including the first | */
+  { GTK_STOCK_MEDIA_STOP, N_("Media|_Stop"), 0, 0, GETTEXT_PACKAGE },
   { GTK_STOCK_NETWORK, N_("_Network"), 0, 0, GETTEXT_PACKAGE },
   { GTK_STOCK_NEW, N_("_New"), GDK_CONTROL_MASK, 'n', GETTEXT_PACKAGE },
   { GTK_STOCK_NO, N_("_No"), 0, 0, GETTEXT_PACKAGE },
@@ -370,6 +410,56 @@ static const GtkStockItem builtin_items [] =
   { GTK_STOCK_ZOOM_OUT, N_("Zoom _Out"), 0, 0, GETTEXT_PACKAGE }
 };
 
+/**
+ * gtk_stock_set_translate_func: 
+ * @func: a #GtkTranslateFunc 
+ * @data: data to pass to @func
+ * @notify: a #GtkDestroyNotify that is called when @data is 
+ *   no longer needed
+ *
+ * Sets a function to be used for translating the @label of 
+ * a stock item.
+ *
+ * If no function is registered for a translation domain,
+ * dgettext() is used.
+ *
+ * Since: 2.8
+ * 
+ */
+void
+gtk_stock_set_translate_func (const gchar      *domain,
+                             GtkTranslateFunc  func,
+                             gpointer          data,
+                             GtkDestroyNotify  notify)
+{
+  GtkStockTranslateFunc *translate;
+  
+  translate = (GtkStockTranslateFunc *) 
+    g_hash_table_lookup (translate_hash, domain);
+
+  if (translate)
+    {
+      if (translate->notify)
+       (* translate->notify) (translate->data);
+    }
+  else
+    translate = g_new0 (GtkStockTranslateFunc, 1);
+    
+  translate->func = func;
+  translate->data = data;
+  translate->notify = notify;
+      
+  g_hash_table_insert (translate_hash, domain, translate);
+}
+
+static gchar *
+sgettext_swapped (const gchar *msgid, 
+                 const gchar *domainname)
+{
+  return g_strip_context (msgid, dgettext (domainname, msgid));
+}
+
+
 static void
 init_stock_hash (void)
 {
@@ -379,4 +469,14 @@ init_stock_hash (void)
 
       gtk_stock_add_static (builtin_items, G_N_ELEMENTS (builtin_items));
     }
+
+  if (translate_hash == NULL)
+    {
+      translate_hash = g_hash_table_new (g_str_hash, g_str_equal);
+
+      gtk_stock_set_translate_func (GETTEXT_PACKAGE, 
+                                   sgettext_swapped,
+                                   GETTEXT_PACKAGE,
+                                   NULL);
+    }
 }
index 419cc5075ab0db2690b2b74b174179cd24415393..d079a1aa218c77f9e77863563bd79329bf603862 100644 (file)
@@ -29,6 +29,7 @@
 
 
 #include <gdk/gdk.h>
+#include <gtk/gtkitemfactory.h> /* for GtkTranslateFunc */
 
 #ifdef __cplusplus
 extern "C" {
@@ -60,6 +61,10 @@ GSList*  gtk_stock_list_ids  (void);
 GtkStockItem *gtk_stock_item_copy (const GtkStockItem *item);
 void          gtk_stock_item_free (GtkStockItem       *item);
 
+void          gtk_stock_set_translate_func (const gchar      *domain,
+                                           GtkTranslateFunc  func,
+                                           gpointer          data,
+                                           GtkDestroyNotify  notify);
 
 /* Stock IDs (not all are stock items; some are images only) */
 #define GTK_STOCK_DIALOG_AUTHENTICATION \