Ladsgroup has uploaded a new change for review. https://gerrit.wikimedia.org/r/201189
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, 26 insertions(+), 1 deletion(-) git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core refs/changes/89/201189/1 diff --git a/scripts/maintenance/make_i18n_dict.py b/scripts/maintenance/make_i18n_dict.py index 590ead5..13eecb8 100644 --- a/scripts/maintenance/make_i18n_dict.py +++ b/scripts/maintenance/make_i18n_dict.py @@ -25,6 +25,12 @@ __version__ = '$Id$' # +import os +import json +import codecs + +from pywikibot import config + class i18nBot(object): @@ -88,5 +94,24 @@ 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) + content = '{}' + if os.path.isfile(file_name): + json_file = codecs.open(file_name, 'r', 'utf-8') + content = json_file.read() + json_file = codecs.open(file_name, 'w', 'utf-8') + new_dict = json.loads(content) + 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: newchange Gerrit-Change-Id: Ifcf93e18c3393f908caf80f86ad231ee21faca49 Gerrit-PatchSet: 1 Gerrit-Project: pywikibot/core Gerrit-Branch: master Gerrit-Owner: Ladsgroup <ladsgr...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits