File indexing completed on 2024-05-05 17:52:55

0001 # -*- coding: UTF-8 -*-
0002 
0003 """
0004 Reformat documentation update date for Russian KDE Team.
0005 
0006 Sieve has no options.
0007 
0008 @author: Alexander Potashev <aspotashev@gmail.com>
0009 @license: GPLv3
0010 """
0011 
0012 from pology import _, n_
0013 from pology.report import report
0014 from pology.msgreport import report_msg_content
0015 import os
0016 import re
0017 
0018 
0019 def setup_sieve (p):
0020 
0021     p.set_desc(_("@info sieve discription",
0022     "Reformat documentation update date for Russian KDE Team."
0023     ))
0024 
0025 
0026 class Sieve (object):
0027 
0028     def __init__ (self, params):
0029         # Some dates have non-standard format, here is the workaround for them:
0030         self.pretranslated = {
0031             'April 8, 2003': '8 апреля 2003 г.',
0032             'April 7, 2003': '7 апреля 2003 г.',
0033             '28/08/2009': '28 августа 2009 г.',
0034             '22/05/2009': '22 мая 2009 г.',
0035             '07 January 2005': '7 января 2005 г.',
0036             'March 7, 2003': '7 марта 2003 г.',
0037             'March 8, 2003': '8 марта 2003 г.',
0038             'April 06, 2003': '6 апреля 2003 г.',
0039             'April 07, 2003': '7 апреля 2003 г.',
0040             'Month Daynumber, 4-Digit-Year': '2 февраля 2005 г.',
0041             'April 2018': 'апрель 2018 г.',
0042             '04/02/2007': '4 февраля 2007 г.',
0043         }
0044     
0045         # Other dates should have the following format: (yyyy-mm-dd)
0046         self.date_re = re.compile("^[0-9][0-9][0-9][0-9]\-[0-9][0-9]\-[0-9][0-9]$")
0047 
0048     def format_date (self, date_en):
0049         if date_en in self.pretranslated:
0050             return self.pretranslated[date_en]
0051         elif self.date_re.match(date_en):
0052             date_result = os.popen("date '+%-d m%mm %Y' -d " + date_en).readlines()[0].decode('utf-8').rstrip() + ' г.'
0053 
0054             # Translate name of months into Russian
0055             return date_result.\
0056                 replace('m01m', 'января').\
0057                 replace('m02m', 'февраля').\
0058                 replace('m03m', 'марта').\
0059                 replace('m04m', 'апреля').\
0060                 replace('m05m', 'мая').\
0061                 replace('m06m', 'июня').\
0062                 replace('m07m', 'июля').\
0063                 replace('m08m', 'августа').\
0064                 replace('m09m', 'сентября').\
0065                 replace('m10m', 'октября').\
0066                 replace('m11m', 'ноября').\
0067                 replace('m12m', 'декабря')
0068         else:
0069             print("\nThis is not a valid date: %s\n" % date_en)
0070 
0071     def process (self, msg, cat):
0072         # Detect documentation update date message
0073         if ("\n".join(msg.auto_comment) == "Tag: date"):
0074             new_msgstr = self.format_date(msg.msgid)
0075             if (msg.fuzzy or msg.msgstr[0] != new_msgstr):
0076                 msg.msgstr[0] = new_msgstr
0077                 msg.unfuzzy()
0078                 report_msg_content(msg, cat)
0079 
0080     def finalize (self):
0081         ""
0082