jenkins-bot has submitted this change and it was merged.
Change subject: Add JSON support to make_i18n_dict.py
......................................................................
Add JSON support to make_i18n_dict.py
It works simply like this
>> from scripts.maintenance.make_i18n_dict import
i18nBot
>> bot = i18nBot('disambredir', 'msg')
>> bot.to_json()
Bug: T87231
Change-Id: Ifcf93e18c3393f908caf80f86ad231ee21faca49
---
M scripts/maintenance/make_i18n_dict.py
1 file changed, 32 insertions(+), 1 deletion(-)
Approvals:
John Vandenberg: Looks good to me, but someone else must approve
XZise: Looks good to me, but someone else must approve
Ladsgroup: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/maintenance/make_i18n_dict.py
b/scripts/maintenance/make_i18n_dict.py
index 590ead5..711c3d4 100644
--- a/scripts/maintenance/make_i18n_dict.py
+++ b/scripts/maintenance/make_i18n_dict.py
@@ -15,6 +15,11 @@
If you have the messages as instance constants you may call the bot as follows:
>> bot =
i18nBot('<scriptname>.<class instance>', '<msg dict1>',
'<msg dict2>')
+
+It's also possible to make json files too by using to_json method:
+>>> from scripts.maintenance.make_i18n_dict import i18nBot
+>>> bot = i18nBot('disambredir', 'msg')
+>>> bot.to_json()
"""
#
# (C) xqt, 2013-2014
@@ -24,6 +29,12 @@
#
__version__ = '$Id$'
#
+
+import os
+import json
+import codecs
+
+from pywikibot import config
class i18nBot(object):
@@ -88,5 +99,25 @@
self.read(msg)
self.print_all()
-if __name__ == "__main__":
+ def to_json(self):
+ if not self.dict:
+ self.run()
+ json_dir = os.path.join(
+ config.base_dir, 'scripts/i18n', self.scriptname)
+ if not os.path.exists(json_dir):
+ os.makedirs(json_dir)
+ for lang in self.dict:
+ file_name = os.path.join(json_dir, '%s.json' % lang)
+ if os.path.isfile(file_name):
+ with codecs.open(file_name, 'r', 'utf-8') as json_file:
+ new_dict = json.loads(json_file.read())
+ else:
+ new_dict = {}
+ new_dict['@metadata'] = new_dict.get('@metadata',
{'authors': []})
+ with codecs.open(file_name, 'w', 'utf-8') as json_file:
+ new_dict.update(self.dict[lang])
+ json.dump(new_dict, json_file, ensure_ascii=False,
+ sort_keys=True, indent=4, separators=(',', ':
'))
+
+if __name__ == '__main__':
print(__doc__)
--
To view, visit
https://gerrit.wikimedia.org/r/201189
To unsubscribe, visit
https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ifcf93e18c3393f908caf80f86ad231ee21faca49
Gerrit-PatchSet: 5
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: Siebrand <siebrand(a)kitano.nl>
Gerrit-Reviewer: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: jenkins-bot <>