#!/usr/bin/env python import sys import os import os.path CMD_XGETTEXT_TMPL = "xgettext --keyword=__ --keyword=__n:1,2 --language=perl --output=%(output)s --from-code utf-8 %(sourcejs)s" SUFFIX_TMPL = "|:js:%(handle)s" handle2js = { 'quicktags': 'wp-includes/js/quicktags.js', 'wp-ajax': 'wp-includes/js/wp-ajax.js', 'autosave': 'wp-includes/js/autosave.js', 'listman': 'wp-includes/js/list-manipulation.js', 'dbx-admin-key': 'wp-admin/js/dbx-admin-key.js', 'ajaxcat': 'wp-admin/js/cat.js', 'ajaxlinkcat': 'wp-admin/js/link-cat.js', 'upload': 'wp-admin/js/upload.js', } def main(wp_root=None): if wp_root == None: print >>sys.stderr, "Usage: wp-js-gettext.py WP_ROOT" sys.exit(1) for (handle, jspath) in handle2js.items(): potfile = os.path.basename(jspath)+'.pot' unsuffixed = potfile + '.unsuffixed' cwd = os.getcwd() os.chdir(wp_root) xgettext = CMD_XGETTEXT_TMPL % {'sourcejs': jspath, 'output': os.path.join(cwd, unsuffixed)} exitcode = os.system(xgettext) os.chdir(cwd) if 0 == exitcode and os.path.isfile(unsuffixed): import msgsuffix msgsuffix.suffix_pot(unsuffixed, SUFFIX_TMPL % {'handle': handle}, potfile) os.remove(unsuffixed) else: if 0 != exitcode: print >>sys.stderr, "xgettext exited with status %d (handle: %s)." % (exitcode, handle) if not os.path.isfile(unsuffixed): print >>sys.stderr, unsuffixed + " doesn't exist, maybe xgettext didn't do its jobs or couldn't find any strings." if __name__ == "__main__": main(*sys.argv[1:])