Skip to content

Instantly share code, notes, and snippets.

@abderrahim
Created November 1, 2011 13:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abderrahim/1330536 to your computer and use it in GitHub Desktop.
Save abderrahim/1330536 to your computer and use it in GitHub Desktop.
/*
* compile with:
* valac -C poextract.vala
* gcc -shared `pkg-config --cflags --libs glib-2.0` -o libpoextract.so poextract.c
* and run with:
* LD_PRELOAD=./libpoextract.so:/usr/lib/preloadable_libintl.so <application>
*/
/* These functions are from preloadable_libintl.so */
extern string libintl_textdomain (string? domain);
extern string libintl_dcgettext (string? domain, string msgid, int category);
extern string libintl_dcngettext (string? domain, string msgid1, string msgid2, ulong n, int category);
string default_domain = null;
public string textdomain (string? domain) {
if (domain != null)
default_domain = domain;
return libintl_textdomain (domain);
}
public string dcgettext (string? domain, string msgid, int category) {
var result = libintl_dcgettext (domain, msgid, category);
if ((domain == null || domain == default_domain)
&& (result in msgid)) {
if (default_domain != null && !("\004" in msgid)) {
var f = FileStream.open ("%s.pot".printf (default_domain), "a");
f.printf ("msgid \"%s\"\n", msgid.escape (""));
f.printf ("msgstr \"\"\n\n");
} else
print ("dcgettext %s, %s, %d\n", domain, msgid, category);
}
return result;
}
public string dcngettext (string? domain, string msgid1, string msgid2, ulong n, int category) {
var result = libintl_dcngettext (domain, msgid1, msgid2, n, category);
if ((domain == null || domain == default_domain)
&& (result in msgid1 || result in msgid2)) {
print ("dcngettext %s, %s, %s, %d\n", domain, msgid1, msgid2, category);
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment