jenkins-bot has submitted this change and it was merged.
Change subject: archivebot: localized duration (hours, days) in edit summary ......................................................................
archivebot: localized duration (hours, days) in edit summary
Patch contributed by Andrei Stroe at http://sourceforge.net/p/pywikipediabot/patches/561/ . Modified to conform with the current framework.
Bug: 54560 Change-Id: I0453a467e28a25e11051810c93e6787c8b9c8517 --- M scripts/archivebot.py 1 file changed, 18 insertions(+), 3 deletions(-)
Approvals: John Vandenberg: Looks good to me, approved jenkins-bot: Verified
diff --git a/scripts/archivebot.py b/scripts/archivebot.py index 8b073e8..1fe0af2 100644 --- a/scripts/archivebot.py +++ b/scripts/archivebot.py @@ -104,6 +104,21 @@ (or incorrect)."""
+def str2localized_duration(site, string): + """Translate a duration written in the shorthand notation (ex. "24h", "7d") + into an expression in the local language of the wiki ("24 hours", "7 days"). + """ + if string[-1] == 'd': + template = site.mediawiki_message('Days') + elif string[-1] == 'h': + template = site.mediawiki_message('Hours') + if template: + exp = i18n.translate(site.code, template, int(string[:-1])) + return exp.replace('$1', string[:-1]) + else: + return string + + def str2time(string): """Accepts a string defining a time period: 7d - 7 days @@ -217,9 +232,9 @@ # return 'unsigned' maxage = str2time(re_t.group(1)) if self.now - self.timestamp > maxage: - return u'%s %s' % (i18n.twtranslate(self.code, - 'archivebot-older-than'), - re_t.group(1)) + msg = i18n.twtranslate(self.code, 'archivebot-older-than') + duration = str2localized_duration(archiver.site, re_t.group(1)) + return u'%s %s' % (msg, duration) return ''
pywikibot-commits@lists.wikimedia.org