Xqt has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/80174


Change subject: New maintenance script for creating i18n dicts from a given 
script.
......................................................................

New maintenance script for creating i18n dicts from a given script.

Change-Id: Id0ecf83eb92f7a65a7585dd2228eb9ea3dbd3fc6
---
A maintenance/make_i18n_dict.py
1 file changed, 82 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/pywikibot/compat 
refs/changes/74/80174/1

diff --git a/maintenance/make_i18n_dict.py b/maintenance/make_i18n_dict.py
new file mode 100644
index 0000000..ccfc4ae
--- /dev/null
+++ b/maintenance/make_i18n_dict.py
@@ -0,0 +1,82 @@
+# -*- coding: utf-8  -*-
+"""
+Generate a i18n file from a given script
+
+usage:
+
+run IDLE
+>>> from 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
+# (C) Pywikipedia bot team, 2013
+#
+# Distributed under the terms of the MIT license.
+#
+__version__ = '$Id$'
+#
+import sys
+sys.path.insert(1, '..')
+
+class i18nBot(object):
+
+    def __init__(self, script, *args):
+        modules = script.split('.')
+        self.scriptname = modules[0]
+        
+        self.script = __import__(self.scriptname, modules[1:])
+        if len(modules) == 2 and hasattr(self.script, modules[1]):
+            self.script = getattr(self.script, modules[1])
+        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 "msg = {"
+        for code in keys:
+            print " " * 8 + "'%s': {" % code
+            for msg in self.messages:
+                label = "%s-%s" % (self.scriptname, msg)
+                if label in self.dict[code]:
+                    print " " * 16 +"'%s': u'%s'," \
+                          % (label, self.dict[code][label])
+            print " " * 8 + "},"
+        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__":
+    run()

-- 
To view, visit https://gerrit.wikimedia.org/r/80174
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Id0ecf83eb92f7a65a7585dd2228eb9ea3dbd3fc6
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/compat
Gerrit-Branch: master
Gerrit-Owner: Xqt <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to