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

Source Code for Module DateHandler._Date_pl

  1  # -*- coding: utf-8 -*- 
  2  # 
  3  # Gramps - a GTK+/GNOME based genealogy program 
  4  # 
  5  # Copyright (C) 2004-2007  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  # Polish version 2007 by Piotr Czubaszek 
 23   
 24  """ 
 25  Polish-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  # Polish parser 
 48  # 
 49  #------------------------------------------------------------------------- 
50 -class DateParserPL(DateParser):
51 52 month_to_int = DateParser.month_to_int 53 month_to_int[u"styczeń"] = 1 54 month_to_int[u"sty"] = 1 55 month_to_int[u"I"] = 1 56 month_to_int[u"luty"] = 2 57 month_to_int[u"lut"] = 2 58 month_to_int[u"II"] = 2 59 month_to_int[u"marzec"] = 3 60 month_to_int[u"mar"] = 3 61 month_to_int[u"III"] = 3 62 month_to_int[u"kwiecień"] = 4 63 month_to_int[u"kwi"] = 4 64 month_to_int[u"IV"] = 4 65 month_to_int[u"maj"] = 5 66 month_to_int[u"V"] = 5 67 month_to_int[u"czerwiec"] = 6 68 month_to_int[u"cze"] = 6 69 month_to_int[u"VI"] = 6 70 month_to_int[u"lipiec"] = 7 71 month_to_int[u"lip"] = 7 72 month_to_int[u"VII"] = 7 73 month_to_int[u"sierpień"] = 8 74 month_to_int[u"sie"] = 8 75 month_to_int[u"VIII"] = 8 76 month_to_int[u"wrzesień"] = 9 77 month_to_int[u"wrz"] = 9 78 month_to_int[u"IX"] = 9 79 month_to_int[u"październik"] = 10 80 month_to_int[u"paź"] = 10 81 month_to_int[u"X"] = 10 82 month_to_int[u"listopad"] = 11 83 month_to_int[u"lis"] = 11 84 month_to_int[u"XI"] = 11 85 month_to_int[u"grudzień"] = 12 86 month_to_int[u"gru"] = 12 87 month_to_int[u"XII"] = 12 88 89 modifier_to_int = { 90 u'przed' : Date.MOD_BEFORE, 91 u'po' : Date.MOD_AFTER, 92 u'około' : Date.MOD_ABOUT, 93 u'ok.' : Date.MOD_ABOUT, 94 u'circa' : Date.MOD_ABOUT, 95 u'ca.' : Date.MOD_ABOUT, 96 } 97 98 calendar_to_int = { 99 u'gregoriański' : Date.CAL_GREGORIAN, 100 u'greg.' : Date.CAL_GREGORIAN, 101 u'juliański' : Date.CAL_JULIAN, 102 u'jul.' : Date.CAL_JULIAN, 103 u'hebrajski' : Date.CAL_HEBREW, 104 u'hebr.' : Date.CAL_HEBREW, 105 u'islamski' : Date.CAL_ISLAMIC, 106 u'isl.' : Date.CAL_ISLAMIC, 107 u'francuski republikański': Date.CAL_FRENCH, 108 u'franc.' : Date.CAL_FRENCH, 109 u'perski' : Date.CAL_PERSIAN, 110 } 111 112 quality_to_int = { 113 u'szacowany' : Date.QUAL_ESTIMATED, 114 u'szac.' : Date.QUAL_ESTIMATED, 115 u'obliczony' : Date.QUAL_CALCULATED, 116 u'obl.' : Date.QUAL_CALCULATED, 117 } 118 119 bce = ["przed naszą erą", "przed Chrystusem", 120 "p.n.e."] + DateParser.bce 121
122 - def init_strings(self):
123 DateParser.init_strings(self) 124 self._span = re.compile("(od)\s+(?P<start>.+)\s+(do)\s+(?P<stop>.+)",re.IGNORECASE) 125 self._range = re.compile(u"(między)\s+(?P<start>.+)\s+(a)\s+(?P<stop>.+)", re.IGNORECASE) 126 self._text2 = re.compile('(\d+)?.?\s+?%s\s*((\d+)(/\d+)?)?' % self._mon_str, 127 re.IGNORECASE) 128 self._jtext2= re.compile('(\d+)?.?\s+?%s\s*((\d+)(/\d+)?)?' % self._jmon_str, 129 re.IGNORECASE)
130 131 #------------------------------------------------------------------------- 132 # 133 # Polish display 134 # 135 #-------------------------------------------------------------------------
136 -class DateDisplayPL(DateDisplay):
137 138 calendar = ( 139 "", u" (juliański)", u" (hebrajski)", 140 u" (francuski republikański)", u" (perski)", u" (islamski)" 141 ) 142 143 _mod_str = ("",u"przed ",u"po ",u"ok. ","","","") 144 145 _qual_str = ("",u"szacowany ",u"obliczony ") 146 147 _bce_str = "%s p.n.e." 148 149 formats = ( 150 "RRRR-MM-DD (ISO)", "Numeryczny", "Miesiąc Dzień, Rok", 151 "Dzień.Miesiąc.Rok", "Dzień Miesiąc Rok", "Dzień MieRzym Rok" 152 ) 153 154 roman_months = ( 155 "", 156 "I", 157 "II", 158 "III", 159 "IV", 160 "V", 161 "VI", 162 "VII", 163 "VIII", 164 "IX", 165 "X", 166 "XI", 167 "XII" 168 ) 169
170 - def _display_gregorian(self,date_val):
171 year = self._slash_year(date_val[2],date_val[3]) 172 if self.format == 0: 173 return self.display_iso(date_val) 174 elif self.format == 1: 175 if date_val[3]: 176 return self.display_iso(date_val) 177 else: 178 if date_val[0] == 0 and date_val[1] == 0: 179 value = str(date_val[2]) 180 else: 181 value = self._tformat.replace('%m',str(date_val[0])) 182 value = value.replace('%d',str(date_val[1])) 183 value = value.replace('%y',str(date_val[2])) 184 elif self.format == 2: 185 # Month Day, Year 186 if date_val[0] == 0: 187 if date_val[1] == 0: 188 value = year 189 else: 190 value = "%s %s" % (self._months[date_val[1]],year) 191 else: 192 value = "%s %d, %s" % (self._months[date_val[1]],date_val[0],year) 193 elif self.format == 3: 194 # Day. Month. Year 195 if date_val[0] == 0: 196 if date_val[1] == 0: 197 value = year 198 else: 199 value = "%d.%s" % (date_val[1],year) 200 else: 201 value = "%d.%d.%s" % (date_val[0],date_val[1],year) 202 elif self.format == 4: 203 # Day Month Year 204 if date_val[0] == 0: 205 if date_val[1] == 0: 206 value = year 207 else: 208 value = "%s %s" % (self._months[date_val[1]],year) 209 else: 210 value = "%d %s %s" % (date_val[0],self._months[date_val[1]],year) 211 else: 212 # Day RomanMon Year 213 if date_val[0] == 0: 214 if date_val[1] == 0: 215 value = year 216 else: 217 value = "%s %s" % (self.roman_months[date_val[1]],year) 218 else: 219 value = "%d %s %s" % (date_val[0],self.roman_months[date_val[1]],year) 220 if date_val[2] < 0: 221 return self._bce_str % value 222 else: 223 return value
224
225 - def display(self,date):
226 """ 227 Return a text string representing the date. 228 """ 229 mod = date.get_modifier() 230 cal = date.get_calendar() 231 qual = date.get_quality() 232 start = date.get_start_date() 233 234 qual_str = self._qual_str[qual] 235 236 if mod == Date.MOD_TEXTONLY: 237 return date.get_text() 238 elif start == Date.EMPTY: 239 return "" 240 elif mod == Date.MOD_SPAN: 241 d1 = self.display_cal[cal](start) 242 d2 = self.display_cal[cal](date.get_stop_date()) 243 return "%s%s %s %s %s%s" % (qual_str,u'od',d1,u'do',d2,self.calendar[cal]) 244 elif mod == Date.MOD_RANGE: 245 d1 = self.display_cal[cal](start) 246 d2 = self.display_cal[cal](date.get_stop_date()) 247 return "%s%s %s %s %s%s" % (qual_str,u'między',d1,u'a',d2,self.calendar[cal]) 248 else: 249 text = self.display_cal[date.get_calendar()](start) 250 return "%s%s%s%s" % (qual_str,self._mod_str[mod],text,self.calendar[cal])
251 252 #------------------------------------------------------------------------- 253 # 254 # Register classes 255 # 256 #------------------------------------------------------------------------- 257 register_datehandler(('pl_PL','polish','Polish_Poland','pl'), 258 DateParserPL, DateDisplayPL) 259