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

Source Code for Module DateHandler._Date_cs

  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  """ 
 23  Czech-specific classes for parsing and displaying dates. 
 24  """ 
 25   
 26  #------------------------------------------------------------------------- 
 27  # 
 28  # Python modules 
 29  # 
 30  #------------------------------------------------------------------------- 
 31  import re 
 32   
 33  #------------------------------------------------------------------------- 
 34  # 
 35  # GRAMPS modules 
 36  # 
 37  #------------------------------------------------------------------------- 
 38  from gen.lib import Date 
 39  from _DateParser import DateParser 
 40  from _DateDisplay import DateDisplay 
 41  from _DateHandler import register_datehandler 
 42   
 43  #------------------------------------------------------------------------- 
 44  # 
 45  # Czech parser 
 46  # 
 47  #------------------------------------------------------------------------- 
48 -class DateParserCZ(DateParser):
49 50 modifier_to_int = { 51 u'před' : Date.MOD_BEFORE, 52 u'do' : Date.MOD_BEFORE, 53 u'po' : Date.MOD_AFTER, 54 u'asi' : Date.MOD_ABOUT, 55 u'kolem' : Date.MOD_ABOUT, 56 u'přibl.' : Date.MOD_ABOUT, 57 } 58 59 calendar_to_int = { 60 u'gregoriánský' : Date.CAL_GREGORIAN, 61 u'g' : Date.CAL_GREGORIAN, 62 u'juliánský' : Date.CAL_JULIAN, 63 u'j' : Date.CAL_JULIAN, 64 u'hebrejský' : Date.CAL_HEBREW, 65 u'h' : Date.CAL_HEBREW, 66 u'islámský' : Date.CAL_ISLAMIC, 67 u'i' : Date.CAL_ISLAMIC, 68 u'republikánský' : Date.CAL_FRENCH, 69 u'r' : Date.CAL_FRENCH, 70 u'perský' : Date.CAL_PERSIAN, 71 u'p' : Date.CAL_PERSIAN, 72 } 73 74 quality_to_int = { 75 u'odhadovaný' : Date.QUAL_ESTIMATED, 76 u'odh.' : Date.QUAL_ESTIMATED, 77 u'vypočtený' : Date.QUAL_CALCULATED, 78 u'vyp.' : Date.QUAL_CALCULATED, 79 } 80
81 - def init_strings(self):
82 DateParser.init_strings(self) 83 _span_1 = [u'od'] 84 _span_2 = [u'do'] 85 _range_1 = [u'mezi'] 86 _range_2 = [u'a'] 87 self._span = re.compile("(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" % 88 ('|'.join(_span_1), '|'.join(_span_2)), 89 re.IGNORECASE) 90 self._range = re.compile("(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" % 91 ('|'.join(_range_1), '|'.join(_range_2)), 92 re.IGNORECASE)
93 94 #------------------------------------------------------------------------- 95 # 96 # Czech display 97 # 98 #-------------------------------------------------------------------------
99 -class DateDisplayCZ(DateDisplay):
100 101 calendar = ( 102 "", u" (juliánský)", u" (hebrejský)", 103 u" (republikánský)", u" (perský)", u" (islámský)" 104 ) 105 106 _mod_str = ("", u"před ", u"po ", u"kolem ", "", "", "") 107 108 _qual_str = ("", "odh. ", "vyp. ") 109 110 formats = ( 111 "RRRR-MM-DD (ISO)", "numerický", "Měsíc Den, Rok", 112 "MĚS Den, Rok", "Den, Měsíc, Rok", "Den MĚS Rok" 113 ) 114
115 - def display(self, date):
116 """ 117 Return a text string representing the date. 118 """ 119 mod = date.get_modifier() 120 cal = date.get_calendar() 121 qual = date.get_quality() 122 start = date.get_start_date() 123 124 qual_str = self._qual_str[qual] 125 126 if mod == Date.MOD_TEXTONLY: 127 return date.get_text() 128 elif start == Date.EMPTY: 129 return "" 130 elif mod == Date.MOD_SPAN: 131 d1 = self.display_cal[cal](start) 132 d2 = self.display_cal[cal](date.get_stop_date()) 133 return "%s%s %s %s %s%s" % (qual_str, u'od', d1, 134 u'do', d2, self.calendar[cal]) 135 elif mod == Date.MOD_RANGE: 136 d1 = self.display_cal[cal](start) 137 d2 = self.display_cal[cal](date.get_stop_date()) 138 return "%s%s %s %s %s%s" % (qual_str, u'medzi', 139 d1, u'a', d2, self.calendar[cal]) 140 else: 141 text = self.display_cal[date.get_calendar()](start) 142 return "%s%s%s%s" % (qual_str, self._mod_str[mod], 143 text, self.calendar[cal])
144 145 #------------------------------------------------------------------------- 146 # 147 # Register classes 148 # 149 #------------------------------------------------------------------------- 150 register_datehandler(('cs_CZ', 'cs', 'CZ'), DateParserCZ, DateDisplayCZ) 151