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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20# 21 22# Written by Benny Malengier 23# Last change 2005/12/05: 24# Correspond naming of dates with actual action, so for abbreviation 25# of month given by mnd. not MAAND 26# Also less possibilities 27 28""" 29Dutch-specific classes for parsing and displaying dates. 30""" 31 32#------------------------------------------------------------------------- 33# 34# Python modules 35# 36#------------------------------------------------------------------------- 37import re 38 39#------------------------------------------------------------------------- 40# 41# Gramps modules 42# 43#------------------------------------------------------------------------- 44from ..lib.date import Date 45from ._dateparser import DateParser 46from ._datedisplay import DateDisplay 47from ._datehandler import register_datehandler 48 49#------------------------------------------------------------------------- 50# 51# Dutch parser 52# 53#------------------------------------------------------------------------- 54class DateParserNL(DateParser): 55 56 month_to_int = DateParser.month_to_int 57 # Always add dutch and flemish name variants 58 # no matter what the current locale is 59 month_to_int["januari"] = 1 60 month_to_int["jan"] = 1 61 # Add other common latin, local and historical variants 62 month_to_int["januaris"] = 1 63 month_to_int["feber"] = 2 64 month_to_int["februaris"] = 2 65 month_to_int["merz"] = 3 66 #make sure on all distro mrt and maa are accepted 67 month_to_int["maa"] = 3 68 month_to_int["mrt"] = 3 69 month_to_int["aprilis"] = 4 70 month_to_int["maius"] = 5 71 month_to_int["junius"] = 6 72 month_to_int["julius"] = 7 73 month_to_int["augst"] = 8 74 month_to_int["7ber"] = 9 75 month_to_int["7bris"] = 9 76 month_to_int["8ber"] = 10 77 month_to_int["8bris"] = 10 78 month_to_int["9ber"] = 11 79 month_to_int["9bris"] = 11 80 month_to_int["10ber"] = 12 81 month_to_int["10bris"] = 12 82 month_to_int["xber"] = 12 83 month_to_int["xbris"] = 12 84 85 modifier_to_int = { 86 'voor' : Date.MOD_BEFORE, 87 'na' : Date.MOD_AFTER, 88 'ca.' : Date.MOD_ABOUT, 89 'circa' : Date.MOD_ABOUT, 90 'om' : Date.MOD_ABOUT, 91 'omstreeks' : Date.MOD_ABOUT, 92 'ongeveer' : Date.MOD_ABOUT, 93 'rond' : Date.MOD_ABOUT, 94 'tegen' : Date.MOD_ABOUT, 95 } 96 97 calendar_to_int = { 98 'gregoriaans' : Date.CAL_GREGORIAN, 99 'greg.' : Date.CAL_GREGORIAN, 100 'juliaans' : Date.CAL_JULIAN, 101 'jul.' : Date.CAL_JULIAN, 102 'hebreeuws' : Date.CAL_HEBREW, 103 'hebr.' : Date.CAL_HEBREW, 104 'islamitisch' : Date.CAL_ISLAMIC, 105 'isl.' : Date.CAL_ISLAMIC, 106 'frans republiekeins' : Date.CAL_FRENCH, 107 'fran.' : Date.CAL_FRENCH, 108 'persisch' : Date.CAL_PERSIAN, 109 'zweeds' : Date.CAL_SWEDISH, 110 'z' : Date.CAL_SWEDISH, 111 } 112 113 quality_to_int = { 114 'geschat' : Date.QUAL_ESTIMATED, 115 'gesch.' : Date.QUAL_ESTIMATED, 116 'berekend' : Date.QUAL_CALCULATED, 117 'ber.' : Date.QUAL_CALCULATED, 118 } 119 120 bce = ["voor onze tijdrekening", "voor Christus", "v. Chr."] + DateParser.bce 121 122 def init_strings(self): 123 DateParser.init_strings(self) 124 self._span = re.compile( 125 r"(van)\s+(?P<start>.+)\s+(tot)\s+(?P<stop>.+)", re.IGNORECASE) 126 self._range = re.compile(r"tussen\s+(?P<start>.+)\s+en\s+(?P<stop>.+)", 127 re.IGNORECASE) 128 self._text2 = re.compile(r'(\d+)?.?\s+?%s\s*((\d+)(/\d+)?)?' 129 % self._mon_str, re.IGNORECASE) 130 self._jtext2 = re.compile(r'(\d+)?.?\s+?%s\s*((\d+)(/\d+)?)?' 131 % self._jmon_str, re.IGNORECASE) 132 133#------------------------------------------------------------------------- 134# 135# Dutch display 136# 137#------------------------------------------------------------------------- 138class DateDisplayNL(DateDisplay): 139 """ 140 Dutch language date display class. 141 """ 142 # TODO: Translate these month strings: 143 long_months = ( "", "januari", "februari", "maart", "april", "mei", 144 "juni", "juli", "augustus", "september", "oktober", 145 "november", "december" ) 146 147 short_months = ( "", "jan", "feb", "mrt", "apr", "mei", "jun", 148 "jul", "aug", "sep", "okt", "nov", "dec" ) 149 150 calendar = ( 151 "", "juliaans", "hebreeuws", 152 "frans republikeins", "persisch", "islamitisch", 153 "zweeds" ) 154 155 _mod_str = ("", "voor ", "na ", "omstreeks ", "", "", "") 156 157 _qual_str = ("", "geschat ", "berekend ") 158 159 _bce_str = "%s v. Chr." 160 161 formats = ( 162 "JJJJ-MM-DD (ISO)", "Numeriek DD/MM/JJJJ", "Maand Dag, Jaar", 163 "Mnd. Dag Jaar", "Dag Maand Jaar", "Dag Mnd. Jaar" 164 ) 165 # this definition must agree with its "_display_gregorian" method 166 167 def _display_gregorian(self, date_val, **kwargs): 168 """ 169 display gregorian calendar date in different format 170 """ 171 # this must agree with its locale-specific "formats" definition 172 year = self._slash_year(date_val[2], date_val[3]) 173 if self.format == 0: 174 return self.display_iso(date_val) 175 elif self.format == 1: 176 if date_val[3]: 177 return self.display_iso(date_val) 178 else: 179 # day/month_number/year 180 if date_val[0] == date_val[1] == 0: 181 value = str(date_val[2]) 182 else: 183 value = self.dhformat.replace('%m', str(date_val[1])) 184 value = value.replace('%d', str(date_val[0])) 185 value = value.replace('%Y', str(abs(date_val[2]))) 186 value = value.replace('-', '/') 187 elif self.format == 2: 188 # month_name day, year 189 if date_val[0] == 0: 190 if date_val[1] == 0: 191 value = year 192 else: 193 value = "%s %s" % (self.long_months[date_val[1]], year) 194 else: 195 value = "%s %d, %s" % (self.long_months[date_val[1]], 196 date_val[0], year) 197 elif self.format == 3: 198 # month_abbreviation day, year 199 if date_val[0] == 0: 200 if date_val[1] == 0: 201 value = year 202 else: 203 value = "%s %s" % (self.short_months[date_val[1]], year) 204 else: 205 value = "%s %d, %s" % (self.short_months[date_val[1]], 206 date_val[0], year) 207 elif self.format == 4: 208 # day month_name year 209 if date_val[0] == 0: 210 if date_val[1] == 0: 211 value = year 212 else: 213 value = "%s %s" % (self.long_months[date_val[1]], year) 214 else: 215 value = "%d %s %s" % (date_val[0], 216 self.long_months[date_val[1]], year) 217 else: 218 # day month_abbreviation year 219 if date_val[0] == 0: 220 if date_val[1] == 0: 221 value = year 222 else: 223 value = "%s %s" % (self.short_months[date_val[1]], year) 224 else: 225 value = "%d %s %s" % (date_val[0], 226 self.short_months[date_val[1]], year) 227 if date_val[2] < 0: 228 return self._bce_str % value 229 else: 230 return value 231 232 def display(self, date): 233 """ 234 Return a text string representing the date. 235 """ 236 mod = date.get_modifier() 237 cal = date.get_calendar() 238 qual = date.get_quality() 239 start = date.get_start_date() 240 newyear = date.get_new_year() 241 242 qual_str = self._qual_str[qual] 243 244 if mod == Date.MOD_TEXTONLY: 245 return date.get_text() 246 elif start == Date.EMPTY: 247 return "" 248 elif mod == Date.MOD_SPAN: 249 d1 = self.display_cal[cal](start) 250 d2 = self.display_cal[cal](date.get_stop_date()) 251 scal = self.format_extras(cal, newyear) 252 return "%s%s %s %s %s%s" % (qual_str, 'van', d1, 253 'tot', d2, scal) 254 elif mod == Date.MOD_RANGE: 255 d1 = self.display_cal[cal](start) 256 d2 = self.display_cal[cal](date.get_stop_date()) 257 scal = self.format_extras(cal, newyear) 258 return "%stussen %s en %s%s" % (qual_str, d1, d2, 259 scal) 260 else: 261 text = self.display_cal[date.get_calendar()](start) 262 scal = self.format_extras(cal, newyear) 263 return "%s%s%s%s" % (qual_str, self._mod_str[mod], text, 264 scal) 265 266#------------------------------------------------------------------------- 267# 268# Register classes 269# 270#------------------------------------------------------------------------- 271register_datehandler( 272 ('nl_NL', 'dutch', 'Dutch', 'nl_BE', 'nl', ('%d-%m-%Y',)), 273 DateParserNL, DateDisplayNL) 274