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

Source Code for Module DateHandler._Date_nl

  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_nl.py 9912 2008-01-22 09:17:46Z acraphae $ 
 23   
 24  # Written by Benny Malengier 
 25  # Last change 2005/12/05: 
 26  # Correspond  naming of dates with actual action, so for abbreviation 
 27  # of month given by mnd. not MAAND 
 28  # Also less possibilities 
 29   
 30  """ 
 31  Dutch-specific classes for parsing and displaying dates. 
 32  """ 
 33   
 34  #------------------------------------------------------------------------- 
 35  # 
 36  # Python modules 
 37  # 
 38  #------------------------------------------------------------------------- 
 39  import re 
 40   
 41  #------------------------------------------------------------------------- 
 42  # 
 43  # GRAMPS modules 
 44  # 
 45  #------------------------------------------------------------------------- 
 46  from gen.lib import Date 
 47  from _DateParser import DateParser 
 48  from _DateDisplay import DateDisplay 
 49  from _DateHandler import register_datehandler 
 50   
 51  #------------------------------------------------------------------------- 
 52  # 
 53  # Dutch parser 
 54  # 
 55  #------------------------------------------------------------------------- 
56 -class DateParserNL(DateParser):
57 58 month_to_int = DateParser.month_to_int 59 # Always add dutch and flemish name variants 60 # no matter what the current locale is 61 month_to_int[u"januari"] = 1 62 month_to_int[u"jan"] = 1 63 # Add other common latin, local and historical variants 64 month_to_int[u"januaris"] = 1 65 month_to_int[u"feber"] = 2 66 month_to_int[u"februaris"] = 2 67 month_to_int[u"merz"] = 3 68 month_to_int[u"aprilis"] = 4 69 month_to_int[u"maius"] = 5 70 month_to_int[u"junius"] = 6 71 month_to_int[u"julius"] = 7 72 month_to_int[u"augst"] = 8 73 month_to_int[u"7ber"] = 9 74 month_to_int[u"7bris"] = 9 75 month_to_int[u"8ber"] = 10 76 month_to_int[u"8bris"] = 10 77 month_to_int[u"9ber"] = 11 78 month_to_int[u"9bris"] = 11 79 month_to_int[u"10ber"] = 12 80 month_to_int[u"10bris"] = 12 81 month_to_int[u"xber"] = 12 82 month_to_int[u"xbris"] = 12 83 84 modifier_to_int = { 85 u'voor' : Date.MOD_BEFORE, 86 u'na' : Date.MOD_AFTER, 87 u'tegen' : Date.MOD_ABOUT, 88 u'om' : Date.MOD_ABOUT, 89 u'rond' : Date.MOD_ABOUT, 90 u'circa' : Date.MOD_ABOUT, 91 u'ca.' : Date.MOD_ABOUT, 92 } 93 94 calendar_to_int = { 95 u'gregoriaans' : Date.CAL_GREGORIAN, 96 u'greg.' : Date.CAL_GREGORIAN, 97 u'juliaans' : Date.CAL_JULIAN, 98 u'jul.' : Date.CAL_JULIAN, 99 u'hebreeuws' : Date.CAL_HEBREW, 100 u'hebr.' : Date.CAL_HEBREW, 101 u'islamitisch' : Date.CAL_ISLAMIC, 102 u'isl.' : Date.CAL_ISLAMIC, 103 u'franse republiek': Date.CAL_FRENCH, 104 u'fran.' : Date.CAL_FRENCH, 105 u'persisch' : Date.CAL_PERSIAN, 106 } 107 108 quality_to_int = { 109 u'geschat' : Date.QUAL_ESTIMATED, 110 u'gesch.' : Date.QUAL_ESTIMATED, 111 u'berekend' : Date.QUAL_CALCULATED, 112 u'ber.' : Date.QUAL_CALCULATED, 113 } 114 115 bce = ["voor onze tijdrekening", "voor Christus", "v. Chr."] + DateParser.bce 116
117 - def init_strings(self):
118 DateParser.init_strings(self) 119 self._span = re.compile("(van)\s+(?P<start>.+)\s+(tot)\s+(?P<stop>.+)", 120 re.IGNORECASE) 121 self._range = re.compile("tussen\s+(?P<start>.+)\s+en\s+(?P<stop>.+)", 122 re.IGNORECASE) 123 self._text2 = re.compile('(\d+)?.?\s+?%s\s*((\d+)(/\d+)?)?' 124 % self._mon_str, 125 re.IGNORECASE) 126 self._jtext2 = re.compile('(\d+)?.?\s+?%s\s*((\d+)(/\d+)?)?' 127 % self._jmon_str, 128 re.IGNORECASE)
129 130 #------------------------------------------------------------------------- 131 # 132 # Dutch display 133 # 134 #-------------------------------------------------------------------------
135 -class DateDisplayNL(DateDisplay):
136 137 calendar = ( 138 "", u" (juliaans)", u" (hebreeuws)", 139 u" (franse republiek)", u" (persisch)", u" (islamitisch)" 140 ) 141 142 _mod_str = ("", u"voor ", u"na ", u"rond ", "", "", "") 143 144 _qual_str = ("", u"geschat ", u"berekend ") 145 146 _bce_str = "%s v. Chr." 147 148 formats = ( 149 "JJJJ-MM-DD (ISO)", "Numerisch DD/MM/JJ", "Maand Dag, Jaar", 150 "Mnd. Dag Jaar", "Dag Maand Jaar", "Dag Mnd. Jaar" 151 ) 152
153 - def _display_gregorian(self, date_val):
154 year = self._slash_year(date_val[2], date_val[3]) 155 if self.format == 0: 156 return self.display_iso(date_val) 157 elif self.format == 1: 158 if date_val[3]: 159 return self.display_iso(date_val) 160 else: 161 # Numeric 162 if date_val[0] == 0 and date_val[1] == 0: 163 value = str(date_val[2]) 164 else: 165 value = self._tformat.replace('%m', str(date_val[1])) 166 value = value.replace('%d', str(date_val[0])) 167 value = value.replace('%Y', str(abs(date_val[2]))) 168 value = value.replace('-', '/') 169 elif self.format == 2: 170 # Month Day, Year 171 if date_val[0] == 0: 172 if date_val[1] == 0: 173 value = year 174 else: 175 value = "%s %s" % (self._months[date_val[1]], year) 176 else: 177 value = "%s %d, %s" % (self._months[date_val[1]], date_val[0], year) 178 elif self.format == 3: 179 # Mnd Day, Year 180 if date_val[0] == 0: 181 if date_val[1] == 0: 182 value = year 183 else: 184 value = "%s %s" % (self.MONS[date_val[1]], year) 185 else: 186 value = "%s %d, %s" % (self.MONS[date_val[1]], date_val[0], year) 187 elif self.format == 4: 188 # Day Month Year 189 if date_val[0] == 0: 190 if date_val[1] == 0: 191 value = year 192 else: 193 value = "%s %s" % (self._months[date_val[1]], year) 194 else: 195 value = "%d %s %s" % (date_val[0], self._months[date_val[1]], year) 196 else: 197 # Day Mnd Year 198 if date_val[0] == 0: 199 if date_val[1] == 0: 200 value = year 201 else: 202 value = "%s %s" % (self.MONS[date_val[1]], year) 203 else: 204 value = "%d %s %s" % (date_val[0], self.MONS[date_val[1]], year) 205 if date_val[2] < 0: 206 return self._bce_str % value 207 else: 208 return value
209
210 - def display(self, date):
211 """ 212 Return a text string representing the date. 213 """ 214 mod = date.get_modifier() 215 cal = date.get_calendar() 216 qual = date.get_quality() 217 start = date.get_start_date() 218 219 qual_str = self._qual_str[qual] 220 221 if mod == Date.MOD_TEXTONLY: 222 return date.get_text() 223 elif start == Date.EMPTY: 224 return "" 225 elif mod == Date.MOD_SPAN: 226 d1 = self.display_cal[cal](start) 227 d2 = self.display_cal[cal](date.get_stop_date()) 228 return "%s%s %s %s %s%s" % (qual_str, u'van', d1, 229 u'tot', d2, self.calendar[cal]) 230 elif mod == Date.MOD_RANGE: 231 d1 = self.display_cal[cal](start) 232 d2 = self.display_cal[cal](date.get_stop_date()) 233 return "%stussen %s en %s%s" % (qual_str, d1, d2, 234 self.calendar[cal]) 235 else: 236 text = self.display_cal[date.get_calendar()](start) 237 return "%s%s%s%s" % (qual_str, self._mod_str[mod], text, 238 self.calendar[cal])
239 240 #------------------------------------------------------------------------- 241 # 242 # Register classes 243 # 244 #------------------------------------------------------------------------- 245 register_datehandler(('nl_NL', 'dutch', 'nl_BE', 'nl'), 246 DateParserNL, DateDisplayNL) 247