jenkins-bot has submitted this change and it was merged.
Change subject: make_i18n_dict from compat
......................................................................
make_i18n_dict from compat
Change-Id: I6552bd4ec2edf94f1852ea8d5415730f55de8483
---
A scripts/maintenance/make_i18n_dict.py
1 file changed, 82 insertions(+), 0 deletions(-)
Approvals:
Merlijn van Deen: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/maintenance/make_i18n_dict.py
b/scripts/maintenance/make_i18n_dict.py
new file mode 100644
index 0000000..8319879
--- /dev/null
+++ b/scripts/maintenance/make_i18n_dict.py
@@ -0,0 +1,82 @@
+# -*- coding: utf-8 -*-
+"""
+Generate a i18n file from a given script
+
+usage:
+
+run IDLE at topmost level
+>>> import pwb
+>>> from scripts.maintenance.make_i18n_dict import i18nBot
+>>> bot = i18nBot('<scriptname>', '<msg dict>')
+>>> bot.run()
+
+If you have more than one message dictionary, give all these names to the bot:
+>>> bot = i18nBot('<scriptname>', '<msg dict1>',
'<msg dict2>', '<msg dict3>')
+
+If you have the messages as instance constants you may call the bot as follows:
+>>> bot = i18nBot('<scriptname>.<class instance>',
'<msg dict1>', '<msg dict2>')
+"""
+#
+# (C) xqt 2013-2014
+# (C) Pywikipedia bot team, 2013
+#
+# Distributed under the terms of the MIT license.
+#
+__version__ = '$Id$'
+#
+
+
+class i18nBot(object):
+
+ def __init__(self, script, *args):
+ modules = script.split('.')
+ self.scriptname = modules[0]
+ self.script = __import__('scripts.' + self.scriptname)
+ for m in modules:
+ self.script = getattr(self.script, m)
+ self.messages = list()
+ for msg in args:
+ if hasattr(self.script, msg):
+ self.messages.append(msg)
+ self.messages.sort()
+ self.dict = dict()
+
+ def print_all(self):
+ keys = self.dict.keys()
+ keys.sort()
+ print "# -*- coding: utf-8 -*-"
+ print "msg = {"
+ for code in keys:
+ print "\t'%s': {" % code
+ for msg in self.messages:
+ label = "%s-%s" % (self.scriptname, msg)
+ if label in self.dict[code]:
+ print "\t\t'%s': u'%s'," \
+ % (label, self.dict[code][label])
+ print "\t},"
+ print "};"
+
+ def read(self, item):
+ msg = getattr(self.script, item)
+ self.keys = msg.keys()
+ self.keys.append('qqq')
+ self.keys.sort()
+ for code in self.keys:
+ label = "%s-%s" % (self.scriptname, item)
+ if code == 'qqq':
+ if code not in self.dict:
+ self.dict[code] = {}
+ self.dict[code][label] = \
+ u'Edit summary for %s report' % self.scriptname
+ elif code != 'commons':
+ if code not in self.dict:
+ self.dict[code] = {}
+ self.dict[code][label] = msg[code]
+
+ def run(self):
+ for msg in self.messages:
+ self.read(msg)
+ self.print_all()
+
+if __name__ == "__main__":
+ print __doc__
--
To view, visit
https://gerrit.wikimedia.org/r/120200
To unsubscribe, visit
https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I6552bd4ec2edf94f1852ea8d5415730f55de8483
Gerrit-PatchSet: 3
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: jenkins-bot <>