[PATCH] i18nstat: extension for counting missing translations
Martin Geisler
mg at daimi.au.dk
Sun Feb 1 00:05:58 UTC 2009
# HG changeset patch
# User Martin Geisler <mg at daimi.au.dk>
# Date 1233446618 -3600
# Node ID 37d96bcd074be8b071b002dce28887e8cc7d94e2
# Parent a343cd25e425ccaaa7075836e6217017a5593568
i18nstat: extension for counting missing translations
This is in contrib/ since it is not a general-purpose extension.
diff --git a/contrib/i18nstat.py b/contrib/i18nstat.py
new file mode 100644
--- /dev/null
+++ b/contrib/i18nstat.py
@@ -0,0 +1,58 @@
+# i18nstat.py - internationalization statistics
+#
+# Copyright 2009 Matt Mackall <mpm at selenic.com> and others
+#
+# This software may be used and distributed according to the terms
+# of the GNU General Public License, incorporated herein by reference.
+
+"""count missing translations
+
+Active this extension to make Mercurial keep track of untranslated
+messages. This is useful for targeting the most often used messages
+when preparing a new translation.
+
+The statistics is stored as a pickle in ~/.hgi18n. Delete this file to
+reset the statistics.
+"""
+
+import atexit, pickle, os
+from mercurial import util, i18n, extensions, commands
+
+stats = {}
+
+def gettext(orig, message):
+ stats.setdefault(message, 0)
+ # check in the catalog directly in order to report accurate
+ # statistics for translations that are identical to the message
+ if message in i18n.t._catalog:
+ del stats[message]
+ else:
+ stats[message] += 1
+ return orig(message)
+
+def i18nstat(ui, repo):
+ """print i18n statistics"""
+ for (msg, count) in sorted(stats.iteritems(), key=lambda (m,c): c):
+ ui.write(" %3d: %r\n" % (count, util.ellipsis(msg.strip(), 65)))
+
+def extsetup():
+ global stats
+ fn = os.path.expanduser('~/.hgi18n')
+ try:
+ fp = open(fn)
+ stats = pickle.load(fp)
+ except (IOError, EOFError):
+ stats = {}
+
+ def save():
+ fp = open(fn, 'w')
+ pickle.dump(stats, fp)
+
+ atexit.register(save)
+ extensions.wrapfunction(i18n, '_', gettext)
+
+cmdtable = {
+ "i18nstat": (i18nstat, [])
+ }
+
+commands.optionalrepo += " i18nstat"
More information about the Mercurial-devel
mailing list