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

Source Code for Module DateHandler._Date_fr

  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_fr.py 10103 2008-02-24 13:55:55Z acraphae $ 
 23   
 24  """ 
 25  French-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  # French parser 
 48  # 
 49  #------------------------------------------------------------------------- 
50 -class DateParserFR(DateParser):
51 52 month_to_int = DateParser.month_to_int 53 # Add common value 54 month_to_int[u"bluviose"] = 1 55 month_to_int[u"vendose"] = 2 56 month_to_int[u"7bre"] = 9 57 month_to_int[u"8bre"] = 10 58 month_to_int[u"9bre"] = 11 59 month_to_int[u"10bre"] = 12 60 month_to_int[u"xbre"] = 12 61 # Add common latin 62 month_to_int[u"januaris"] = 1 63 month_to_int[u"januarii"] = 1 64 month_to_int[u"januarius"] = 1 65 month_to_int[u"februaris"] = 2 66 month_to_int[u"februarii"] = 2 67 month_to_int[u"februarius"] = 2 68 month_to_int[u"martii"] = 3 69 month_to_int[u"martius"] = 3 70 month_to_int[u"aprilis"] = 4 71 month_to_int[u"maius"] = 5 72 month_to_int[u"maii"] = 5 73 month_to_int[u"junius"] = 6 74 month_to_int[u"junii"] = 6 75 month_to_int[u"julius"] = 7 76 month_to_int[u"julii"] = 7 77 month_to_int[u"augustus"] = 8 78 month_to_int[u"augusti"] = 8 79 month_to_int[u"septembris"] = 9 80 month_to_int[u"7bris"] = 9 81 month_to_int[u"september"] = 9 82 month_to_int[u"october"] = 10 83 month_to_int[u"octobris"] = 10 84 month_to_int[u"8bris"] = 10 85 month_to_int[u"novembris"] = 11 86 month_to_int[u"9bris"] = 11 87 month_to_int[u"november"] = 11 88 month_to_int[u"decembris"] = 12 89 month_to_int[u"10bris"] = 12 90 month_to_int[u"xbris"] = 12 91 month_to_int[u"december"] = 12 92 #local and historical variants 93 # Add common on east france 94 month_to_int[u"janer"] = 1 95 month_to_int[u"jenner"] = 1 96 month_to_int[u"hartmonat"] = 1 97 month_to_int[u"hartung"] = 1 98 month_to_int[u"eismond"] = 1 99 month_to_int[u"hornung"] = 2 100 month_to_int[u"wintermonat"] = 2 101 month_to_int[u"taumond"] = 2 102 month_to_int[u"narrenmond"] = 2 103 month_to_int[u"lenzing"] = 3 104 month_to_int[u"ostermond"] = 4 105 month_to_int[u"wonnemond"] = 5 106 month_to_int[u"wiesenmonat"] = 5 107 month_to_int[u"brachet"] = 6 108 month_to_int[u"heuet"] = 7 109 month_to_int[u"ernting"] = 8 110 month_to_int[u"scheiding"] = 9 111 month_to_int[u"gilbhard"] = 10 112 month_to_int[u"nebelmonat"] = 11 113 month_to_int[u"nebelung"] = 11 114 month_to_int[u"julmond"] = 12 115 116 modifier_to_int = { 117 u'avant' : Date.MOD_BEFORE, 118 u'av.' : Date.MOD_BEFORE, 119 u'après' : Date.MOD_AFTER, 120 u'ap.' : Date.MOD_AFTER, 121 u'ap' : Date.MOD_AFTER, 122 u'env.' : Date.MOD_ABOUT, 123 u'env' : Date.MOD_ABOUT, 124 u'environ': Date.MOD_ABOUT, 125 u'circa' : Date.MOD_ABOUT, 126 u'c.' : Date.MOD_ABOUT, 127 u'ca' : Date.MOD_ABOUT, 128 u'ca.' : Date.MOD_ABOUT, 129 u'vers' : Date.MOD_ABOUT, 130 u'~' : Date.MOD_ABOUT, 131 } 132 133 calendar_to_int = { 134 u'grégorien' : Date.CAL_GREGORIAN, 135 u'g' : Date.CAL_GREGORIAN, 136 u'julien' : Date.CAL_JULIAN, 137 u'j' : Date.CAL_JULIAN, 138 u'hébreu' : Date.CAL_HEBREW, 139 u'h' : Date.CAL_HEBREW, 140 u'islamique' : Date.CAL_ISLAMIC, 141 u'i' : Date.CAL_ISLAMIC, 142 u'révolutionnaire' : Date.CAL_FRENCH, 143 u'r' : Date.CAL_FRENCH, 144 u'perse' : Date.CAL_PERSIAN, 145 u'p' : Date.CAL_PERSIAN, 146 } 147 148 quality_to_int = { 149 u'estimée' : Date.QUAL_ESTIMATED, 150 u'est.' : Date.QUAL_ESTIMATED, 151 u'est' : Date.QUAL_ESTIMATED, 152 u'calculée' : Date.QUAL_CALCULATED, 153 u'calc.' : Date.QUAL_CALCULATED, 154 u'calc' : Date.QUAL_CALCULATED, 155 u'comptée' : Date.QUAL_CALCULATED, 156 u'compt' : Date.QUAL_CALCULATED, 157 u'compt.' : Date.QUAL_CALCULATED, 158 } 159 160 bce = [u"avant le calendrier", u"avant notre ère", 161 u"avant JC", u"avant J.C"] + DateParser.bce 162
163 - def init_strings(self):
164 DateParser.init_strings(self) 165 # This self._numeric is different from the base 166 # avoid bug gregorian / french calendar conversion (+/-10 days) 167 self._numeric = re.compile("((\d+)[/\. ])?\s*((\d+)[/\.])?\s*(\d+)\s*$") 168 self._span = re.compile(u"(de)\s+(?P<start>.+)\s+(à)\s+(?P<stop>.+)", re.IGNORECASE) 169 self._range = re.compile(u"(entre|ent\.|ent)\s+(?P<start>.+)\s+(et)\s+(?P<stop>.+)", re.IGNORECASE) 170 # This self._text are different from the base 171 # by adding ".?" after the first date and removing "\s*$" at the end 172 #gregorian and julian 173 self._text2 = re.compile('(\d+)?.?\s+?%s\s*((\d+)(/\d+)?)?' % self._mon_str, 174 re.IGNORECASE) 175 #hebrew 176 self._jtext2 = re.compile('(\d+)?.?\s+?%s\s*((\d+)(/\d+)?)?' % self._jmon_str, 177 re.IGNORECASE) 178 #french 179 self._ftext2 = re.compile('(\d+)?.?\s+?%s\s*((\d+)(/\d+)?)?' % self._fmon_str, 180 re.IGNORECASE) 181 #persian 182 self._ptext2 = re.compile('(\d+)?.?\s+?%s\s*((\d+)(/\d+)?)?' % self._pmon_str, 183 re.IGNORECASE) 184 #islamic 185 self._itext2 = re.compile('(\d+)?.?\s+?%s\s*((\d+)(/\d+)?)?' % self._imon_str, 186 re.IGNORECASE)
187 188 #------------------------------------------------------------------------- 189 # 190 # French display 191 # 192 #-------------------------------------------------------------------------
193 -class DateDisplayFR(DateDisplay):
194 195 calendar = ( 196 "", u" (Julien)", u" (Hébreu)", 197 u" (Révolutionnaire)", u" (Perse)", u" (Islamique)" 198 ) 199 200 _mod_str = ("", u"avant ", u"après ", u"vers ", "", "", "") 201 202 _qual_str = ("", u"estimée ", u"calculée ", "") 203 204 _bce_str = u"%s avant le calendrier" 205 206 formats = ( 207 "AAAA-MM-JJ (ISO)", "Numérique", "Mois Jour, Année", 208 "MOI Jour, Année", "Jour. Mois Année", "Jour. MOI Année" 209 ) 210
211 - def _display_gregorian(self, date_val):
212 year = self._slash_year(date_val[2], date_val[3]) 213 if self.format == 0: 214 return self.display_iso(date_val) 215 elif self.format == 1: 216 if date_val[2] < 0 or date_val[3]: 217 return self.display_iso(date_val) 218 else: 219 if date_val[0] == 0 and date_val[1] == 0: 220 value = str(date_val[2]) 221 else: 222 value = self._tformat.replace('%m', str(date_val[1])) 223 value = value.replace('%d', str(date_val[0])) 224 # base_display : 225 # value = value.replace('%Y', str(abs(date_val[2]))) 226 # value = value.replace('-', '/') 227 value = value.replace('%Y', str(date_val[2])) 228 elif self.format == 2: 229 # Month Day, Year 230 if date_val[0] == 0: 231 if date_val[1] == 0: 232 value = year 233 else: 234 value = "%s %s" % (self._months[date_val[1]], year) 235 else: 236 value = "%s %d, %s" % (self._months[date_val[1]], date_val[0], year) 237 elif self.format == 3: 238 # MON Day, Year 239 if date_val[0] == 0: 240 if date_val[1] == 0: 241 value = year 242 else: 243 value = "%s %s" % (self.MONS[date_val[1]], year) 244 else: 245 value = "%s %d, %s" % (self.MONS[date_val[1]], date_val[0], year) 246 elif self.format == 4: 247 # Day Month Year 248 if date_val[0] == 0: 249 if date_val[1] == 0: 250 value = year 251 else: 252 value = "%s %s" % (self._months[date_val[1]], year) 253 else: 254 # base_display : 255 # value = "%d %s %s" % (date_val[0], self._months[date_val[1]], year) 256 value = "%d. %s %s" % (date_val[0], self._months[date_val[1]], year) 257 else: 258 # Day MON Year 259 if date_val[0] == 0: 260 if date_val[1] == 0: 261 value = year 262 else: 263 value = "%s %s" % (self.MONS[date_val[1]], year) 264 else: 265 # base_display : 266 # value = "%d %s %s" % (date_val[0], self.MONS[date_val[1]], year) 267 value = "%d. %s %s" % (date_val[0], self.MONS[date_val[1]], year) 268 if date_val[2] < 0: 269 return self._bce_str % value 270 else: 271 return value
272
273 - def _display_french(self, date_val):
274 year = date_val[2] 275 if date_val[0] == 0: 276 if date_val[1] == 0: 277 return year 278 else: 279 return u"%s %d" % (self.french[date_val[1]], year) 280 # convertion mistake before 22.9.1792 281 elif date_val[2] == 0 and date_val[1] == 13: 282 # from 17.9.1792 to 21.9.1792 : trap for Extra months, we cannot date back 283 return self._bce_str % year 284 # on 1792 before 22.9.1792, no negative years 285 elif date_val[2] < 0: 286 return self._bce_str % year 287 # valid dates on 1792 288 else: 289 return u"%s %s %d" % (date_val[0], self.french[date_val[1]], year)
290
291 - def display(self, date):
292 """ 293 Return a text string representing the date. 294 """ 295 mod = date.get_modifier() 296 cal = date.get_calendar() 297 qual = date.get_quality() 298 start = date.get_start_date() 299 300 qual_str = self._qual_str[qual] 301 302 if mod == Date.MOD_TEXTONLY: 303 return date.get_text() 304 elif start == Date.EMPTY: 305 return "" 306 elif mod == Date.MOD_SPAN: 307 d1 = self.display_cal[cal](start) 308 d2 = self.display_cal[cal](date.get_stop_date()) 309 return "%s%s %s %s %s%s" % (qual_str, u'de', d1, u'à', d2, self.calendar[cal]) 310 elif mod == Date.MOD_RANGE: 311 d1 = self.display_cal[cal](start) 312 d2 = self.display_cal[cal](date.get_stop_date()) 313 return "%s%s %s %s %s%s" % (qual_str, u'entre', d1, u'et', d2, self.calendar[cal]) 314 else: 315 text = self.display_cal[date.get_calendar()](start) 316 return "%s%s%s%s" % (qual_str, self._mod_str[mod], text, self.calendar[cal])
317 318 319 #------------------------------------------------------------------------- 320 # 321 # Register classes 322 # 323 #------------------------------------------------------------------------- 324 register_datehandler( 325 ('fr_FR', 'fr', 'french', 'fr_CA', 'fr_BE', 'fr_CH'), 326 DateParserFR, DateDisplayFR) 327