[Commits] click2trans branch master updated.

C. Scott Ananian cscott at laptop.org
Wed Nov 19 01:32:27 EST 2008


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "/home/cscott/public_git/click2trans".

The branch, master has been updated
       via  1439feca573f673586427e158a3f59be016d62ba (commit)
       via  02b0565081a787954274e94e96380f6d2d5b2fe9 (commit)
       via  d01bd165642fea9e4badf913de10cd4306a79548 (commit)
      from  1336d869e0f4fe9b296ef3d00714cb4d62a35b63 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

 .gitignore       |    6 +++
 GetTextInfo.vala |   32 ++++++++++++++
 Makefile         |   25 ++++++----
 TransWidget.vala |  127 +++++++++++++++++++++++++++++++++++++++++++++++++----
 gtktrans.c       |   75 +++++++++++++++++++++++++++++++-
 5 files changed, 243 insertions(+), 22 deletions(-)
 create mode 100644 GetTextInfo.vala

- Log -----------------------------------------------------------------
commit 1439feca573f673586427e158a3f59be016d62ba
Author: C. Scott Ananian <cscott at laptop.org>
Date:   Wed Nov 19 01:32:18 2008 -0500

    Basic persistent translation-lookaside support.  Pretty hacky.

diff --git a/TransWidget.vala b/TransWidget.vala
index b89c703..8dc1e18 100644
--- a/TransWidget.vala
+++ b/TransWidget.vala
@@ -7,8 +7,10 @@ using GetTextInfo;
 using Gee;
 
 public class TransWidget : Gtk.Dialog {
-	public Gtk.Entry msgid1 { get; set; }
-	public Gtk.Entry msgid2 { get; set; }
+	// XXX USE REAL FILENAME
+	private static const string LOOKASIDE_FILENAME="/home/cananian/.lookaside";
+	public Gtk.Label msgid1 { get; set; }
+	public Gtk.Label msgid2 { get; set; }
 	public Gtk.Entry result { get; set; }
 	private Gtk.Label _label;
 	public Gtk.Label label {
@@ -30,14 +32,12 @@ public class TransWidget : Gtk.Dialog {
 		vbox.pack_start_defaults(hbox);
 		hbox.show();
 
-		this.msgid1 = new Entry();
-		this.msgid2 = new Entry();
+		this.msgid1 = new Label("");
+		this.msgid2 = new Label("");
 		this.result = new Entry();
 		hbox.pack_start_defaults(msgid1);
 		hbox.pack_start_defaults(msgid2);
 		hbox.pack_start_defaults(result);
-		this.msgid1.editable = false;
-		this.msgid2.editable = false;
 		this.msgid1.show();
 		this.msgid2.show();
 		this.result.show();
@@ -48,10 +48,10 @@ public class TransWidget : Gtk.Dialog {
 		if (gtimap.contains(this.label)) {
 			var gti = gtimap.get(this.label);
 			if (gti.result == this.label.get_label()) {
-				this.msgid1.text = gti.msgid1;
+				this.msgid1.label = gti.msgid1;
 				this.msgid1.show();
 				if (gti.plural) {
-					this.msgid2.text = gti.msgid2;
+					this.msgid2.label = gti.msgid2;
 					this.msgid2.show();
 				} else {
 					this.msgid2.hide();
@@ -70,16 +70,49 @@ public class TransWidget : Gtk.Dialog {
 	}
 	private static void do_response(TransWidget t, int arg1) {
 		if (arg1 == Gtk.ResponseType.OK) {
-			t.label.set_label(t.result.text);
+			if (t.label.label != t.result.text) {
+				t.label.set_label(t.result.text);
+				if (gtimap.contains(t.label)) {
+					lookaside.set_string("lookaside",
+										 gtimap.get(t.label).msgid1,
+										 t.result.text);
+					// rewrite lookaside.
+					try {
+						size_t size;
+						var lf_contents = lookaside.to_data(out size);
+						GLib.FileUtils.set_contents(LOOKASIDE_FILENAME,
+													lf_contents, (long) size);
+					} catch (GLib.KeyFileError ex) {
+						stdout.printf("This is an unexpected surprise.\n");
+					} catch (GLib.FileError ex) {
+						stdout.printf("COULDN'T WRITE %s\n", LOOKASIDE_FILENAME);
+					}
+				}
+			}
 		}
 		t.destroy();
 	}
 	private static GetTextInfo _last_gti = null;
-	public static void record_gettext(string? domain, string msgid, string result) {
+	private static string _sketchy_buffer;
+	public static weak string record_gettext(string? domain, string msgid, string result) {
 		_last_gti = GetTextInfo.create(domain, msgid, result);
+		try {
+			// XXX: DOESN'T USE DOMAIN, NOT THREAD SAFE
+			_sketchy_buffer = lookaside.get_string("lookaside", msgid);
+			return _sketchy_buffer;
+		} catch (KeyFileError ex) {
+			return result;
+		}
 	}
-	public static void record_ngettext(string? domain, string msgid1, string msgid2, ulong n, string result) {
+	public static weak string record_ngettext(string? domain, string msgid1, string msgid2, ulong n, string result) {
 		_last_gti = GetTextInfo.ncreate(domain, msgid1, msgid2, n, result);
+		try {
+			// XXX: DOESN'T USE DOMAIN, NOT THREAD SAFE, DOESN'T USE N
+			_sketchy_buffer = lookaside.get_string("lookaside", msgid1);
+			return _sketchy_buffer;
+		} catch (KeyFileError ex) {
+			return result;
+		}
 	}
 
 	public static void add_translate_entry(Gtk.Label l, Gtk.Menu m) {
@@ -88,7 +121,7 @@ public class TransWidget : Gtk.Dialog {
 		menuitem.show();
 		m.prepend(menuitem);
 
-		menuitem = new Gtk.MenuItem.with_label("Translate...");
+		menuitem = new Gtk.MenuItem.with_label(_("Translate..."));
 		menuitem.show();
 		m.prepend(menuitem);
 
@@ -101,7 +134,7 @@ public class TransWidget : Gtk.Dialog {
 	public static void init() {
 		lookaside = new GLib.KeyFile();
 		try {
-			lookaside.load_from_file("/home/cananian/.lookaside",
+			lookaside.load_from_file(LOOKASIDE_FILENAME,
 									 KeyFileFlags.KEEP_COMMENTS |
 									 KeyFileFlags.KEEP_TRANSLATIONS);
 		} catch (GLib.KeyFileError ex) {
diff --git a/gtktrans.c b/gtktrans.c
index 9c4b820..54c29ab 100644
--- a/gtktrans.c
+++ b/gtktrans.c
@@ -180,7 +180,7 @@ char *gettext(const char *msgid) {
     //printf("GETTEXT: %s -> %s\n", msgid, result);
     // stash this away
     if (_inited && msgid && result)
-	trans_widget_record_gettext(NULL, msgid, result);
+	result = trans_widget_record_gettext(NULL, msgid, result);
     // return result.
     return result;
 }
@@ -193,7 +193,7 @@ char *dgettext(const char *domain_name, const char *msgid) {
     result = func(domain_name, msgid);
     printf("DGETTEXT: %s %s -> %s\n", domain_name, msgid, result);
     if (_inited && msgid && result)
-	trans_widget_record_gettext(domain_name, msgid, result);
+	result = trans_widget_record_gettext(domain_name, msgid, result);
     return result;
 }
 char *ngettext(const char *msgid1, const char *msgid2, unsigned long int n) {
@@ -205,7 +205,7 @@ char *ngettext(const char *msgid1, const char *msgid2, unsigned long int n) {
     result = func(msgid1, msgid2, n);
     printf("NGETTEXT: %s %s %lu -> %s\n", msgid1, msgid2, n, result);
     if (_inited && msgid1 && msgid2 && result)
-	trans_widget_record_ngettext(NULL, msgid1, msgid2, n, result);
+	result = trans_widget_record_ngettext(NULL, msgid1, msgid2, n, result);
     return result;
 }
 char *dngettext(const char *domain_name, const char *msgid1, const char *msgid2, unsigned long int n) {
@@ -217,6 +217,6 @@ char *dngettext(const char *domain_name, const char *msgid1, const char *msgid2,
     result = func(domain_name, msgid1, msgid2, n);
     printf("DNGETTEXT: %s %s %s %lu -> %s\n", domain_name, msgid1, msgid2, n, result);
     if (_inited && msgid1 && msgid2 && result)
-	trans_widget_record_ngettext(domain_name, msgid1, msgid2, n, result);
+	result = trans_widget_record_ngettext(domain_name, msgid1, msgid2, n, result);
     return result;
 }

commit 02b0565081a787954274e94e96380f6d2d5b2fe9
Author: C. Scott Ananian <cscott at laptop.org>
Date:   Wed Nov 19 00:52:56 2008 -0500

    Record gettext info for label, so we have the msgid at edit time.

diff --git a/.gitignore b/.gitignore
index 55a90d9..01e9fcd 100644
--- a/.gitignore
+++ b/.gitignore
@@ -7,5 +7,10 @@ apidocs
 TransWidget.vapi
 TransWidget.c
 TransWidget.h
+TransWidget.gir
 transwidget
+GetTextInfo.vapi
+GetTextInfo.c
+GetTextInfo.h
+GetTextInfo.gir
 upstream
diff --git a/GetTextInfo.vala b/GetTextInfo.vala
new file mode 100644
index 0000000..e2341b4
--- /dev/null
+++ b/GetTextInfo.vala
@@ -0,0 +1,32 @@
+using Gtk;
+
+public class GetTextInfo : GLib.Object {
+	public string? domain_name { get; set; }
+	public string msgid1 { get; set; }
+	public string msgid2 { get; set; }
+	public ulong n { get; set; }
+	public bool plural { get; set; }
+	public string result { get; set; }
+
+	public static GetTextInfo create(string? domain_name, string msgid, string result) {
+		GetTextInfo gti = new GetTextInfo();
+		gti.domain_name = domain_name;
+		gti.msgid1 = msgid;
+		gti.result = result;
+		//
+		gti.msgid2 = null;
+		gti.n = 0;
+		gti.plural = false;
+		return gti;
+	}
+	public static GetTextInfo ncreate(string? domain_name, string msgid1, string msgid2, ulong n, string result) {
+		GetTextInfo gti = new GetTextInfo();
+		gti.domain_name = domain_name;
+		gti.msgid1 = msgid1;
+		gti.msgid2 = msgid2;
+		gti.n = n;
+		gti.result = result;
+		gti.plural = true;
+		return gti;
+	}
+}
diff --git a/Makefile b/Makefile
index 4608796..8b237b2 100644
--- a/Makefile
+++ b/Makefile
@@ -1,28 +1,33 @@
 CC=gcc
 VALAC=valac
-CFLAGS=-g -Wall -D_GNU_SOURCE
-VALA_FLAGS=--pkg gtk+-2.0 --pkg dbus-glib-1
-PKGS=gtk+-2.0 dbus-glib-1
+CFLAGS=-g -Wall -D_GNU_SOURCE -DGETTEXT_PACKAGE=\"gtktrans\"
+VALA_FLAGS=--pkg gtk+-2.0 --pkg dbus-glib-1 --pkg gee-1.0
+PKGS=gtk+-2.0 dbus-glib-1 gee-1.0
 
 all: gtktrans.so
 
 %.o: %.c
 	$(CC) $(CFLAGS) -fPIC -rdynamic -c -I. $(CFLAGS) $(shell pkg-config --cflags $(PKGS)) $<
 
-gtktrans.o: TransWidget.h
+gtktrans.o: TransWidget.h GetTextInfo.h
 
-gtktrans.so: gtktrans.o TransWidget.o
+gtktrans.so: gtktrans.o TransWidget.o GetTextInfo.o
 	$(CC) -shared -o $@ $^ $(shell pkg-config --libs $(PKGS)) -ldl
 
 # vala app standalone, for testing.
-transwidget: TransWidget.vala
-	$(VALAC) $(VALA_FLAGS) -X -I. -o $@ $<
-# vala app as library.
-TransWidget.c TransWidget.h TransWidget.vapi TransWidget.gidl: TransWidget.vala
-	$(VALAC) $(VALA_FLAGS) -C --library TransWidget --basedir ./ $<
+transwidget: TransWidget.vala GetTextInfo.vala
+	$(VALAC) $(VALA_FLAGS) -X -I. -X -DGETTEXT_PACKAGE=\"gtktrans\" -o $@ $^
+# vala app(s) as library.
+TransWidget.c TransWidget.h TransWidget.vapi TransWidget.gidl: TransWidget.vala GetTextInfo.vapi
+	$(VALAC) $(VALA_FLAGS) --pkg GetTextInfo --vapidir=. -C --library TransWidget --basedir ./ $<
 TransWidget.o: TransWidget.h
 
+GetTextInfo.c GetTextInfo.h GetTextInfo.vapi GetTextInfo.gidl: GetTextInfo.vala
+	$(VALAC) $(VALA_FLAGS) -C --library GetTextInfo --basedir ./ $<
+GetTextInfo.o: GetTextInfo.h
+
 clean:
 	$(RM) TransWidget.c TransWidget.h TransWidget.vapi TransWidget.gidl
+	$(RM) GetTextInfo.c GetTextInfo.h GetTextInfo.vapi GetTextInfo.gidl
 	$(RM) *.o *.so
 	$(RM) transwidget
diff --git a/TransWidget.vala b/TransWidget.vala
index 16bf25f..b89c703 100644
--- a/TransWidget.vala
+++ b/TransWidget.vala
@@ -3,15 +3,19 @@
 using GLib;
 using Gtk;
 using DBus;
+using GetTextInfo;
+using Gee;
 
 public class TransWidget : Gtk.Dialog {
-	public Gtk.Entry entry { get; set; }
+	public Gtk.Entry msgid1 { get; set; }
+	public Gtk.Entry msgid2 { get; set; }
+	public Gtk.Entry result { get; set; }
 	private Gtk.Label _label;
 	public Gtk.Label label {
 		get { return this._label; }
 		set {
 			this._label = value;
-			this.entry.text = value.get_label();
+			this.update_dialog();
 		}
 	}
 	public TransWidget(Gtk.Label label) {
@@ -20,12 +24,44 @@ public class TransWidget : Gtk.Dialog {
 		this.label = label;
 	}
 	construct {
-		set_title("Translate");
+		set_title(_("Translate"));
 		add_button("OK", Gtk.ResponseType.OK);
-		this.entry = new Entry();
-		vbox.pack_start_defaults(this.entry);
-		this.entry.show();
+		var hbox = new Gtk.HBox(false, 5);
+		vbox.pack_start_defaults(hbox);
+		hbox.show();
+
+		this.msgid1 = new Entry();
+		this.msgid2 = new Entry();
+		this.result = new Entry();
+		hbox.pack_start_defaults(msgid1);
+		hbox.pack_start_defaults(msgid2);
+		hbox.pack_start_defaults(result);
+		this.msgid1.editable = false;
+		this.msgid2.editable = false;
+		this.msgid1.show();
+		this.msgid2.show();
+		this.result.show();
+	}
+	private void update_dialog() {
+		this.result.text = this.label.get_label();
+		this.result.show();
+		if (gtimap.contains(this.label)) {
+			var gti = gtimap.get(this.label);
+			if (gti.result == this.label.get_label()) {
+				this.msgid1.text = gti.msgid1;
+				this.msgid1.show();
+				if (gti.plural) {
+					this.msgid2.text = gti.msgid2;
+					this.msgid2.show();
+				} else {
+					this.msgid2.hide();
+				}
+			} else {
+				this.msgid1.hide();
+			}
+		}
 	}
+
 	private static void translate_callback(Gtk.MenuItem m, Gtk.Label l) {
 		stdout.printf("Translating %s\n", l.get_label());
 		var t = new TransWidget(l);
@@ -34,15 +70,16 @@ public class TransWidget : Gtk.Dialog {
 	}
 	private static void do_response(TransWidget t, int arg1) {
 		if (arg1 == Gtk.ResponseType.OK) {
-			t.label.set_label(t.entry.text);
+			t.label.set_label(t.result.text);
 		}
 		t.destroy();
 	}
-	private static string _last_msgid;
-	private static string _last_result;
-	public static void register_msgid(string msgid, string result) {
-		_last_msgid = msgid;
-		_last_result = result;
+	private static GetTextInfo _last_gti = null;
+	public static void record_gettext(string? domain, string msgid, string result) {
+		_last_gti = GetTextInfo.create(domain, msgid, result);
+	}
+	public static void record_ngettext(string? domain, string msgid1, string msgid2, ulong n, string result) {
+		_last_gti = GetTextInfo.ncreate(domain, msgid1, msgid2, n, result);
 	}
 
 	public static void add_translate_entry(Gtk.Label l, Gtk.Menu m) {
@@ -59,19 +96,38 @@ public class TransWidget : Gtk.Dialog {
 							(GLib.Callback) translate_callback, l);
 	}
 
-	public static void register(Gtk.Widget w) {
-		
+	private static GLib.KeyFile lookaside;
+	private static Gee.HashMap<Gtk.Label,GetTextInfo> gtimap;
+	public static void init() {
+		lookaside = new GLib.KeyFile();
+		try {
+			lookaside.load_from_file("/home/cananian/.lookaside",
+									 KeyFileFlags.KEEP_COMMENTS |
+									 KeyFileFlags.KEEP_TRANSLATIONS);
+		} catch (GLib.KeyFileError ex) {
+			/* ignore; we'll write the file if necessary */
+		} catch (GLib.FileError ex) {
+			/* ignore; we'll write the file if necessary */
+		}
+		gtimap = new Gee.HashMap<Gtk.Label,GetTextInfo>(GLib.direct_hash, GLib.direct_equal);
 	}
-	public static void change_label(Gtk.Label l, ParamSpec ps) {
+
+	public static void label_change(Gtk.Label l, ParamSpec ps) {
 		if (l.get_label() != null) {
-			stdout.printf("LABEL CHANGED:%s\t(last %s->%s)\n", l.get_label(), _last_msgid, _last_result);
+			label_update(l);
 		}
 	}
-	public static void tweak_label(Gtk.Label l) {
+	public static void label_init(Gtk.Label l) {
 		if (l.get_label() != null && l.get_label()!="")
-			stdout.printf("CHECK: %s %s\n", _last_result, l.get_label());
+			label_update(l);
 		l.set_selectable(true);
-		GLib.Signal.connect(l, "notify::label", (GLib.Callback) change_label, null);
-		//l.connect("notify::label", change_label);
+		GLib.Signal.connect(l, "notify::label", (GLib.Callback) label_change, null);
+	}
+	private static void label_update(Gtk.Label l) {
+		if (_last_gti != null && l.get_label() == _last_gti.result)
+			gtimap.set(l, _last_gti);
+	}
+	public static void label_dispose(Gtk.Label l) {
+		gtimap.remove(l); // if present
 	}
 }
diff --git a/gtktrans.c b/gtktrans.c
index 117a291..9c4b820 100644
--- a/gtktrans.c
+++ b/gtktrans.c
@@ -36,27 +36,46 @@ gtk_label_constructor_REDIR
     GObject *object = gtk_label_constructor_ORIG
 	(type, n_construct_properties, construct_params);
     GtkLabel *label = GTK_LABEL(object);
-    trans_widget_tweak_label(label);
+    trans_widget_label_init(label);
     return object;
 #endif
 }
 
+static void
+(*gtk_label_dispose_ORIG)
+    (GObject *object) = NULL;
+static void
+gtk_label_dispose_REDIR
+    (GObject *object) {
+#ifdef DONT_DO_ANYTHING
+#else
+    trans_widget_label_dispose(GTK_LABEL(object));
+#endif
+    gtk_label_dispose_ORIG(object);
+}
+
+static int _inited=0;
 static void init_me(void)
 {
     GObjectClass *gobject_class;
     printf("INITIALIZING\n");
-    if (!gtk_label_constructor_ORIG) {
+    if (!_inited) {
 	GtkLabelClass *label_class;
+	_inited=1;
 	/* get the gtk_file_chooser_widget class */
 	gobject_class = g_type_class_ref(GTK_TYPE_LABEL);
 	/* replace standard constructor with our own! */
 	gtk_label_constructor_ORIG = gobject_class->constructor;
 	gobject_class->constructor = gtk_label_constructor_REDIR;
+	/* replace standard dispose function with our own! */
+	gtk_label_dispose_ORIG = gobject_class->dispose;
+	gobject_class->dispose = gtk_label_dispose_REDIR;
 	/* make a new default populate-popup callback, too. */
 	label_class = GTK_LABEL_CLASS(gobject_class);
 	g_assert(label_class->populate_popup == NULL);
 	label_class->populate_popup = trans_widget_add_translate_entry;
     }
+    trans_widget_init();
 }
 
 /* do init in the various gtk entry points */
@@ -158,34 +177,46 @@ char *gettext(const char *msgid) {
 	func = (char *(*)(const char *))
 	    dlsym_ORIG(RTLD_NEXT, "gettext");
     result = func(msgid);
-    printf("GETTEXT: %s -> %s\n", msgid, result);
+    //printf("GETTEXT: %s -> %s\n", msgid, result);
     // stash this away
-    if (msgid && result)
-	trans_widget_register_msgid(msgid, result);
+    if (_inited && msgid && result)
+	trans_widget_record_gettext(NULL, msgid, result);
     // return result.
     return result;
 }
 char *dgettext(const char *domain_name, const char *msgid) {
     static char * (*func)(const *, const char *) = NULL;
-    printf("DGETTEXT: %s\n", msgid);
+    char *result;
     if (!func)
 	func = (char *(*)(const char *, const char *))
 	    dlsym_ORIG(RTLD_NEXT, "dgettext");
-    return func(domain_name, msgid);
+    result = func(domain_name, msgid);
+    printf("DGETTEXT: %s %s -> %s\n", domain_name, msgid, result);
+    if (_inited && msgid && result)
+	trans_widget_record_gettext(domain_name, msgid, result);
+    return result;
 }
 char *ngettext(const char *msgid1, const char *msgid2, unsigned long int n) {
     static char * (*func)(const char *, const char *, unsigned long int) = NULL;
-    printf("NGETTEXT: %s %s %lu\n", msgid1, msgid2, n);
+    char *result;
     if (!func)
 	func = (char *(*)(const char *, const char *, unsigned long int))
 	    dlsym_ORIG(RTLD_NEXT, "ngettext");
-    return func(msgid1, msgid2, n);
+    result = func(msgid1, msgid2, n);
+    printf("NGETTEXT: %s %s %lu -> %s\n", msgid1, msgid2, n, result);
+    if (_inited && msgid1 && msgid2 && result)
+	trans_widget_record_ngettext(NULL, msgid1, msgid2, n, result);
+    return result;
 }
 char *dngettext(const char *domain_name, const char *msgid1, const char *msgid2, unsigned long int n) {
     static char * (*func)(const char *, const char *, const char *, unsigned long int) = NULL;
-    printf("DNGETTEXT: %s %s %lu\n", msgid1, msgid2, n);
+    char *result;
     if (!func)
 	func = (char *(*)(const char *, const char *, const char *, unsigned long int))
 	    dlsym_ORIG(RTLD_NEXT, "dngettext");
-    return func(domain_name, msgid1, msgid2, n);
+    result = func(domain_name, msgid1, msgid2, n);
+    printf("DNGETTEXT: %s %s %s %lu -> %s\n", domain_name, msgid1, msgid2, n, result);
+    if (_inited && msgid1 && msgid2 && result)
+	trans_widget_record_ngettext(domain_name, msgid1, msgid2, n, result);
+    return result;
 }

commit d01bd165642fea9e4badf913de10cd4306a79548
Author: C. Scott Ananian <cscott at laptop.org>
Date:   Tue Nov 18 17:39:26 2008 -0500

    Hook into gettext API.

diff --git a/.gitignore b/.gitignore
index fc88951..55a90d9 100644
--- a/.gitignore
+++ b/.gitignore
@@ -8,3 +8,4 @@ TransWidget.vapi
 TransWidget.c
 TransWidget.h
 transwidget
+upstream
diff --git a/TransWidget.vala b/TransWidget.vala
index dda3ae6..16bf25f 100644
--- a/TransWidget.vala
+++ b/TransWidget.vala
@@ -38,6 +38,12 @@ public class TransWidget : Gtk.Dialog {
 		}
 		t.destroy();
 	}
+	private static string _last_msgid;
+	private static string _last_result;
+	public static void register_msgid(string msgid, string result) {
+		_last_msgid = msgid;
+		_last_result = result;
+	}
 
 	public static void add_translate_entry(Gtk.Label l, Gtk.Menu m) {
 		Gtk.MenuItem menuitem;
@@ -56,4 +62,16 @@ public class TransWidget : Gtk.Dialog {
 	public static void register(Gtk.Widget w) {
 		
 	}
+	public static void change_label(Gtk.Label l, ParamSpec ps) {
+		if (l.get_label() != null) {
+			stdout.printf("LABEL CHANGED:%s\t(last %s->%s)\n", l.get_label(), _last_msgid, _last_result);
+		}
+	}
+	public static void tweak_label(Gtk.Label l) {
+		if (l.get_label() != null && l.get_label()!="")
+			stdout.printf("CHECK: %s %s\n", _last_result, l.get_label());
+		l.set_selectable(true);
+		GLib.Signal.connect(l, "notify::label", (GLib.Callback) change_label, null);
+		//l.connect("notify::label", change_label);
+	}
 }
diff --git a/gtktrans.c b/gtktrans.c
index 0cbbf71..117a291 100644
--- a/gtktrans.c
+++ b/gtktrans.c
@@ -36,7 +36,7 @@ gtk_label_constructor_REDIR
     GObject *object = gtk_label_constructor_ORIG
 	(type, n_construct_properties, construct_params);
     GtkLabel *label = GTK_LABEL(object);
-    gtk_label_set_selectable(label, TRUE);
+    trans_widget_tweak_label(label);
     return object;
 #endif
 }
@@ -149,3 +149,43 @@ void * dlsym(void *handle, const char *name)
     return func(handle, name);
 }
 #endif /* REDIRECT_DLSYM */
+
+/************ gettext redirections ***************/
+char *gettext(const char *msgid) {
+    static char * (*func)(const char *) = NULL;
+    char *result;
+    if (!func)
+	func = (char *(*)(const char *))
+	    dlsym_ORIG(RTLD_NEXT, "gettext");
+    result = func(msgid);
+    printf("GETTEXT: %s -> %s\n", msgid, result);
+    // stash this away
+    if (msgid && result)
+	trans_widget_register_msgid(msgid, result);
+    // return result.
+    return result;
+}
+char *dgettext(const char *domain_name, const char *msgid) {
+    static char * (*func)(const *, const char *) = NULL;
+    printf("DGETTEXT: %s\n", msgid);
+    if (!func)
+	func = (char *(*)(const char *, const char *))
+	    dlsym_ORIG(RTLD_NEXT, "dgettext");
+    return func(domain_name, msgid);
+}
+char *ngettext(const char *msgid1, const char *msgid2, unsigned long int n) {
+    static char * (*func)(const char *, const char *, unsigned long int) = NULL;
+    printf("NGETTEXT: %s %s %lu\n", msgid1, msgid2, n);
+    if (!func)
+	func = (char *(*)(const char *, const char *, unsigned long int))
+	    dlsym_ORIG(RTLD_NEXT, "ngettext");
+    return func(msgid1, msgid2, n);
+}
+char *dngettext(const char *domain_name, const char *msgid1, const char *msgid2, unsigned long int n) {
+    static char * (*func)(const char *, const char *, const char *, unsigned long int) = NULL;
+    printf("DNGETTEXT: %s %s %lu\n", msgid1, msgid2, n);
+    if (!func)
+	func = (char *(*)(const char *, const char *, const char *, unsigned long int))
+	    dlsym_ORIG(RTLD_NEXT, "dngettext");
+    return func(domain_name, msgid1, msgid2, n);
+}
-----------------------------------------------------------------------


--
/home/cscott/public_git/click2trans


More information about the Commits mailing list