Package DateHandler :: Module _Date_ru
[frames] | no frames]

Source Code for Module DateHandler._Date_ru

  1  # -*- coding: utf-8 -*- 
  2  # 
  3  # Gramps - a GTK+/GNOME based genealogy program 
  4  # 
  5  # Copyright (C) 2004-2006  Donald N. Allingham 
  6  # 
  7  # This program is free software; you can redistribute it and/or modify 
  8  # it under the terms of the GNU General Public License as published by 
  9  # the Free Software Foundation; either version 2 of the License, or 
 10  # (at your option) any later version. 
 11  # 
 12  # This program is distributed in the hope that it will be useful,  
 13  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
 14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 15  # GNU General Public License for more details. 
 16  # 
 17  # You should have received a copy of the GNU General Public License 
 18  # along with this program; if not, write to the Free Software 
 19  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
 20  # 
 21   
 22  # $Id:_Date_ru.py 9912 2008-01-22 09:17:46Z acraphae $ 
 23   
 24  """ 
 25  Russian-specific classes for parsing and displaying dates. 
 26  """ 
 27   
 28  #------------------------------------------------------------------------- 
 29  # 
 30  # Python modules 
 31  # 
 32  #------------------------------------------------------------------------- 
 33  import re 
 34   
 35  #------------------------------------------------------------------------- 
 36  # 
 37  # GRAMPS modules 
 38  # 
 39  #------------------------------------------------------------------------- 
 40  from gen.lib import Date 
 41  from _DateParser import DateParser 
 42  from _DateDisplay import DateDisplay 
 43  from _DateHandler import register_datehandler 
 44   
 45  #------------------------------------------------------------------------- 
 46  # 
 47  # Russian parser 
 48  # 
 49  #------------------------------------------------------------------------- 
50 -class DateParserRU(DateParser):
51 52 modifier_to_int = { 53 u'перед' : Date.MOD_BEFORE, 54 u'по' : Date.MOD_BEFORE, 55 u'после' : Date.MOD_AFTER, 56 u'п.' : Date.MOD_AFTER, 57 u'п' : Date.MOD_AFTER, 58 u'с' : Date.MOD_AFTER, 59 u'ок' : Date.MOD_ABOUT, 60 u'ок.' : Date.MOD_ABOUT, 61 u'около' : Date.MOD_ABOUT, 62 u'примерно' : Date.MOD_ABOUT, 63 u'прим' : Date.MOD_ABOUT, 64 u'прим.' : Date.MOD_ABOUT, 65 u'приблизительно' : Date.MOD_ABOUT, 66 u'приб.' : Date.MOD_ABOUT, 67 u'прибл.' : Date.MOD_ABOUT, 68 u'приб' : Date.MOD_ABOUT, 69 u'прибл' : Date.MOD_ABOUT, 70 } 71 72 calendar_to_int = { 73 u'григорианский' : Date.CAL_GREGORIAN, 74 u'г' : Date.CAL_GREGORIAN, 75 u'юлианский' : Date.CAL_JULIAN, 76 u'ю' : Date.CAL_JULIAN, 77 u'еврейский' : Date.CAL_HEBREW, 78 u'е' : Date.CAL_HEBREW, 79 u'исламский' : Date.CAL_ISLAMIC, 80 u'и' : Date.CAL_ISLAMIC, 81 u'республиканский': Date.CAL_FRENCH, 82 u'р' : Date.CAL_FRENCH, 83 u'персидский' : Date.CAL_PERSIAN, 84 u'п' : Date.CAL_PERSIAN, 85 } 86 87 quality_to_int = { 88 u'оценено' : Date.QUAL_ESTIMATED, 89 u'оцен.' : Date.QUAL_ESTIMATED, 90 u'оц.' : Date.QUAL_ESTIMATED, 91 u'оцен' : Date.QUAL_ESTIMATED, 92 u'оц' : Date.QUAL_ESTIMATED, 93 u'вычислено' : Date.QUAL_CALCULATED, 94 u'вычисл.' : Date.QUAL_CALCULATED, 95 u'выч.' : Date.QUAL_CALCULATED, 96 u'вычисл' : Date.QUAL_CALCULATED, 97 u'выч' : Date.QUAL_CALCULATED, 98 } 99 100 hebrew_to_int = { 101 u"тишрей":1, 102 u"хешван":2, 103 u"кислев":3, 104 u"тевет":4, 105 u"шеват":5, 106 u"адар":6, 107 u"адар бет":7, 108 u"нисан":8, 109 u"ияр":9, 110 u"сиван":10, 111 u"таммуз":11, 112 u"ав":12, 113 u"элул":13, 114 } 115 116 islamic_to_int = { 117 u"мухаррам":1, 118 u"сафар":2, 119 u"раби-аль-авваль":3, 120 u"раби-ассани":4, 121 u"джумада-аль-уля":5, 122 u"джумада-аль-ахира":6, 123 u"раджаб":7, 124 u"шаабан":8, 125 u"рамадан":9, 126 u"шавваль":10, 127 u"зуль-каада":11, 128 u"зуль-хиджжа":12, 129 } 130 131 persian_to_int = { 132 u"фарвардин":1, 133 u"урдбихишт":2, 134 u"хурдад":3, 135 u"тир":4, 136 u"мурдад":5, 137 u"шахривар":6, 138 u"михр":7, 139 u"абан":8, 140 u"азар":9, 141 u"дай":10, 142 u"бахман":11, 143 u"исфаидармуз":12, 144 } 145 146 french_to_int = { 147 u"вандемьер":1, 148 u"брюмер":2, 149 u"фример":3, 150 u"нивоз":4, 151 u"плювиоз":5, 152 u"вантоз":6, 153 u"жерминаль":7, 154 u"флореаль":8, 155 u"прериаль":9, 156 u"мессидор":10, 157 u"термидор":11, 158 u"фрюктидор":12, 159 u"дополнит.":13, 160 } 161 162 bce = [ 163 u'до нашей эры', u'до н. э.', u'до н.э.', 164 u'до н э', u'до нэ'] + DateParser.bce 165
166 - def init_strings(self):
167 DateParser.init_strings(self) 168 _span_1 = [u'с', u'от'] 169 _span_2 = [u'по'] 170 _range_1 = [u'между', u'меж\.', u'меж'] 171 _range_2 = [u'и'] 172 self._span = re.compile("(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" % 173 ('|'.join(_span_1), '|'.join(_span_2)), 174 re.IGNORECASE) 175 self._range = re.compile("(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" % 176 ('|'.join(_range_1), '|'.join(_range_2)), 177 re.IGNORECASE)
178 179 #------------------------------------------------------------------------- 180 # 181 # Russian displayer 182 # 183 #-------------------------------------------------------------------------
184 -class DateDisplayRU(DateDisplay):
185 186 calendar = ( 187 u"", 188 u" (юлианский)", 189 u" (еврейский)", 190 u" (республиканский)", 191 u" (персидский)", 192 u" (исламский)" 193 ) 194 195 _mod_str = ( 196 u"", 197 u"перед ", 198 u"после ", 199 u"около ", 200 u"", u"", u"") 201 202 _qual_str = (u"", u"оцен ", u"вычисл ") 203 204 _bce_str = u"%s до н.э." 205 206 formats = ( 207 "ГГГГ-ММ-ДД (ISO)", "Численный", "Месяц День, Год", 208 "МЕС ДД, ГГГГГ", "День Месяц, Год", "ДД МЕС, ГГГГГ" 209 ) 210 211 hebrew = ( u"", 212 u"Тишрей", 213 u"Хешван", 214 u"Кислев", 215 u"Тевет", 216 u"Шеват", 217 u"Адар", 218 u"Адар бет", 219 u"Нисан", 220 u"Ияр", 221 u"Сиван", 222 u"Таммуз", 223 u"Ав", 224 u"Элул", 225 ) 226 227 islamic = ( u"", 228 u"Мухаррам", 229 u"Сафар", 230 u"Раби-аль-авваль", 231 u"Раби-ассани", 232 u"Джумада-аль-уля", 233 u"Джумада-аль-ахира", 234 u"Раджаб", 235 u"Шаабан", 236 u"Рамадан", 237 u"Шавваль", 238 u"Зуль-каада", 239 u"Зуль-хиджжа", 240 ) 241 242 persian = ( u"", 243 u"Фарвардин", 244 u"Урдбихишт", 245 u"Хурдад", 246 u"Тир", 247 u"Мурдад", 248 u"Шахривар", 249 u"Михр", 250 u"Абан", 251 u"Азар", 252 u"Дай", 253 u"Бахман", 254 u"Исфаидармуз", 255 ) 256 257 french = ( u"", 258 u"Вандемьер", 259 u"Брюмер", 260 u"Фример", 261 u"Нивоз", 262 u"Плювиоз", 263 u"Вантоз", 264 u"Жерминаль", 265 u"Флореаль", 266 u"Прериаль", 267 u"Мессидор", 268 u"Термидор", 269 u"Фрюктидор", 270 u"Дополнит." 271 ) 272
273 - def display(self, date):
274 """ 275 Return a text string representing the date. 276 """ 277 mod = date.get_modifier() 278 cal = date.get_calendar() 279 qual = date.get_quality() 280 start = date.get_start_date() 281 282 qual_str = self._qual_str[qual] 283 284 if mod == Date.MOD_TEXTONLY: 285 return date.get_text() 286 elif start == Date.EMPTY: 287 return "" 288 elif mod == Date.MOD_SPAN: 289 d1 = self.display_cal[cal](start) 290 d2 = self.display_cal[cal](date.get_stop_date()) 291 return "%sс %s %s %s%s" % (qual_str, d1, u'по', d2, 292 self.calendar[cal]) 293 elif mod == Date.MOD_RANGE: 294 d1 = self.display_cal[cal](start) 295 d2 = self.display_cal[cal](date.get_stop_date()) 296 return "%s%s %s %s %s%s" % (qual_str, u'между', d1, u'и', 297 d2, self.calendar[cal]) 298 else: 299 text = self.display_cal[date.get_calendar()](start) 300 return "%s%s%s%s" % (qual_str, self._mod_str[mod], 301 text, self.calendar[cal])
302 303 #------------------------------------------------------------------------- 304 # 305 # Register classes 306 # 307 #------------------------------------------------------------------------- 308 register_datehandler(('ru_RU', 'ru', 'russian'), DateParserRU, DateDisplayRU) 309