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

Source Code for Module DateHandler._Date_fi

  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_fi.py 9912 2008-01-22 09:17:46Z acraphae $ 
 23   
 24  """ 
 25  Finnish-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  # Finnish parser 
 48  # 
 49  # This handles only dates where days and months are given as numeric, as: 
 50  # - That's how they are normally used in Finland 
 51  # - Parsing Finnish is much more complicated than English 
 52  #------------------------------------------------------------------------- 
53 -class DateParserFI(DateParser):
54 55 # NOTE: these need to be in lower case because the "key" comparison 56 # is done as lower case. In the display method correct capitalization 57 # can be used. 58 59 modifier_to_int = { 60 # examples: 61 # - ennen 1.1.2005 62 # - noin 1.1.2005 63 u'ennen' : Date.MOD_BEFORE, 64 u'e.' : Date.MOD_BEFORE, 65 u'noin' : Date.MOD_ABOUT, 66 u'n.' : Date.MOD_ABOUT, 67 } 68 modifier_after_to_int = { 69 # examples: 70 # - 1.1.2005 jälkeen 71 u'jälkeen' : Date.MOD_AFTER, 72 u'j.' : Date.MOD_AFTER, 73 } 74 75 bce = [u"ekr.", u"ekr"] 76 77 calendar_to_int = { 78 u'gregoriaaninen' : Date.CAL_GREGORIAN, 79 u'greg.' : Date.CAL_GREGORIAN, 80 u'juliaaninen' : Date.CAL_JULIAN, 81 u'jul.' : Date.CAL_JULIAN, 82 u'heprealainen' : Date.CAL_HEBREW, 83 u'hepr.' : Date.CAL_HEBREW, 84 u'islamilainen' : Date.CAL_ISLAMIC, 85 u'isl.' : Date.CAL_ISLAMIC, 86 u'ranskan vallankumouksen aikainen': Date.CAL_FRENCH, 87 u'ranskan v.' : Date.CAL_FRENCH, 88 u'persialainen' : Date.CAL_PERSIAN, 89 u'pers.' : Date.CAL_PERSIAN, 90 } 91 92 quality_to_int = { 93 u'arviolta' : Date.QUAL_ESTIMATED, 94 u'arv.' : Date.QUAL_ESTIMATED, 95 u'laskettuna' : Date.QUAL_CALCULATED, 96 u'lask.' : Date.QUAL_CALCULATED, 97 } 98
99 - def init_strings(self):
100 DateParser.init_strings(self) 101 # date, whitespace 102 self._span = re.compile(u"(?P<start>.+)\s+(-)\s+(?P<stop>.+)", 103 re.IGNORECASE) 104 self._range = re.compile( 105 u"(vuosien\s*)?(?P<start>.+)\s+ja\s+(?P<stop>.+)\s+välillä", 106 re.IGNORECASE)
107 108 #------------------------------------------------------------------------- 109 # 110 # Finnish display 111 # 112 #-------------------------------------------------------------------------
113 -class DateDisplayFI(DateDisplay):
114 115 calendar = ("", 116 u"(juliaaninen)", 117 u"(heprealainen)", 118 u"(ranskan v.)", 119 u"(persialainen)", 120 u"(islamilainen)") 121 122 _qual_str = (u"", u"arviolta", u"laskettuna") 123 124 _bce_str = u"%s ekr." 125 126 formats = ( 127 "VVVV-KK-PP (ISO)", 128 "PP.KK.VVVV" 129 ) 130
131 - def display(self, date):
132 """ 133 Return a text string representing the date. 134 """ 135 mod = date.get_modifier() 136 qual = date.get_quality() 137 cal = date.get_calendar() 138 start = date.get_start_date() 139 140 if mod == Date.MOD_TEXTONLY: 141 return date.get_text() 142 if start == Date.EMPTY: 143 return u"" 144 145 # select numerical date format 146 self.format = 1 147 148 if mod == Date.MOD_SPAN: 149 d1 = self.display_cal[cal](start) 150 d2 = self.display_cal[cal](date.get_stop_date()) 151 text = u"%s - %s" % (d1, d2) 152 elif mod == Date.MOD_RANGE: 153 stop = date.get_stop_date() 154 if start[0] == 0 and start[1] == 0 and stop[0] == 0 and stop[1] == 0: 155 d1 = self.display_cal[cal](start) 156 d2 = self.display_cal[cal](stop) 157 text = u"vuosien %s ja %s välillä" % (d1, d2) 158 else: 159 d1 = self.display_cal[cal](start) 160 d2 = self.display_cal[cal](stop) 161 text = u"%s ja %s välillä" % (d1, d2) 162 else: 163 text = self.display_cal[date.get_calendar()](start) 164 if mod == Date.MOD_AFTER: 165 text = text + u" jälkeen" 166 elif mod == Date.MOD_ABOUT: 167 text = u"noin " + text 168 elif mod == Date.MOD_BEFORE: 169 text = u"ennen " + text 170 171 if qual: 172 # prepend quality 173 text = u"%s %s" % (self._qual_str[qual], text) 174 if cal: 175 # append calendar type 176 text = u"%s %s" % (text, self.calendar[cal]) 177 178 return text
179 180 #------------------------------------------------------------------------- 181 # 182 # Register classes 183 # 184 #------------------------------------------------------------------------- 185 register_datehandler(('fi_FI', 'fi', 'finnish'), DateParserFI, DateDisplayFI) 186