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

Source Code for Module DateHandler._Date_sk

  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_sk.py 10103 2008-02-24 13:55:55Z acraphae $ 
 23   
 24  """ 
 25  Slovak-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  # Slovak parser 
 48  # 
 49  #------------------------------------------------------------------------- 
50 -class DateParserSK(DateParser):
51 52 modifier_to_int = { 53 u'pred' : Date.MOD_BEFORE, 54 u'do' : Date.MOD_BEFORE, 55 u'po' : Date.MOD_AFTER, 56 u'asi' : Date.MOD_ABOUT, 57 u'okolo' : Date.MOD_ABOUT, 58 u'pribl.' : Date.MOD_ABOUT, 59 } 60 61 calendar_to_int = { 62 u'gregoriánsky' : Date.CAL_GREGORIAN, 63 u'g' : Date.CAL_GREGORIAN, 64 u'juliánský' : Date.CAL_JULIAN, 65 u'j' : Date.CAL_JULIAN, 66 u'hebrejský' : Date.CAL_HEBREW, 67 u'h' : Date.CAL_HEBREW, 68 u'islamský' : Date.CAL_ISLAMIC, 69 u'i' : Date.CAL_ISLAMIC, 70 u'republikánsky' : Date.CAL_FRENCH, 71 u'r' : Date.CAL_FRENCH, 72 u'perzský' : Date.CAL_PERSIAN, 73 u'p' : Date.CAL_PERSIAN, 74 } 75 76 quality_to_int = { 77 u'odhadovaný' : Date.QUAL_ESTIMATED, 78 u'odh.' : Date.QUAL_ESTIMATED, 79 u'vypočítaný' : Date.QUAL_CALCULATED, 80 u'vyp.' : Date.QUAL_CALCULATED, 81 } 82
83 - def init_strings(self):
84 DateParser.init_strings(self) 85 _span_1 = [u'od'] 86 _span_2 = [u'do'] 87 _range_1 = [u'medzi'] 88 _range_2 = [u'a'] 89 self._span = re.compile("(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" % 90 ('|'.join(_span_1), '|'.join(_span_2)), 91 re.IGNORECASE) 92 self._range = re.compile("(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" % 93 ('|'.join(_range_1), '|'.join(_range_2)), 94 re.IGNORECASE)
95 96 #------------------------------------------------------------------------- 97 # 98 # Slovak display 99 # 100 #-------------------------------------------------------------------------
101 -class DateDisplaySK(DateDisplay):
102 103 calendar = ( 104 "", u" (juliánský)", u" (hebrejský)", 105 u" (republikánsky)", u" (perzský)", u" (islamský)" 106 ) 107 108 _mod_str = ("", u"pred ", u"po ", u"okolo ", "", "", "") 109 110 _qual_str = ("", "odh. ", "vyp. ") 111 112 formats = ( 113 "RRRR-MM-DD (ISO)", "numerický", "Mesiac Deň, Rok", 114 "MES Deň, Rok", "Deň, Mesiac, Rok", "Deň MES Rok" 115 ) 116
117 - def display(self, date):
118 """ 119 Return a text string representing the date. 120 """ 121 mod = date.get_modifier() 122 cal = date.get_calendar() 123 qual = date.get_quality() 124 start = date.get_start_date() 125 126 qual_str = self._qual_str[qual] 127 128 if mod == Date.MOD_TEXTONLY: 129 return date.get_text() 130 elif start == Date.EMPTY: 131 return "" 132 elif mod == Date.MOD_SPAN: 133 d1 = self.display_cal[cal](start) 134 d2 = self.display_cal[cal](date.get_stop_date()) 135 return "%s%s %s %s %s%s" % (qual_str, u'od', d1, 136 u'do', d2, self.calendar[cal]) 137 elif mod == Date.MOD_RANGE: 138 d1 = self.display_cal[cal](start) 139 d2 = self.display_cal[cal](date.get_stop_date()) 140 return "%s%s %s %s %s%s" % (qual_str, u'medzi', 141 d1, u'a', d2, self.calendar[cal]) 142 else: 143 text = self.display_cal[date.get_calendar()](start) 144 return "%s%s%s%s" % (qual_str, self._mod_str[mod], 145 text, self.calendar[cal])
146 147 #------------------------------------------------------------------------- 148 # 149 # Register classes 150 # 151 #------------------------------------------------------------------------- 152 register_datehandler(('sk_SK', 'sk', 'SK'), DateParserSK, DateDisplaySK) 153