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

Source Code for Module DateHandler._Date_lt

  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_lt.py 9912 2008-01-22 09:17:46Z acraphae $ 
 23   
 24  """ 
 25  Lithuanian-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  # Lithuanian parser 
 48  # 
 49  #------------------------------------------------------------------------- 
50 -class DateParserLT(DateParser):
51 52 modifier_to_int = { 53 u'prieš' : Date.MOD_BEFORE, 54 u'po' : Date.MOD_AFTER, 55 u'apie' : Date.MOD_ABOUT, 56 } 57 58 calendar_to_int = { 59 u'grigaliaus' : Date.CAL_GREGORIAN, 60 u'g' : Date.CAL_GREGORIAN, 61 u'julijaus' : Date.CAL_JULIAN, 62 u'j' : Date.CAL_JULIAN, 63 u'hebrajų' : Date.CAL_HEBREW, 64 u'h' : Date.CAL_HEBREW, 65 u'islamo' : Date.CAL_ISLAMIC, 66 u'i' : Date.CAL_ISLAMIC, 67 u'prancuzų respublikos': Date.CAL_FRENCH, 68 u'r' : Date.CAL_FRENCH, 69 u'persų' : Date.CAL_PERSIAN, 70 u'p' : Date.CAL_PERSIAN, 71 } 72 73 quality_to_int = { 74 u'apytikriai' : Date.QUAL_ESTIMATED, 75 u'apskaičiuota' : Date.QUAL_CALCULATED, 76 } 77
78 - def init_strings(self):
79 DateParser.init_strings(self) 80 _span_1 = [u'nuo'] 81 _span_2 = [u'iki'] 82 _range_1 = [u'tarp'] 83 _range_2 = [u'ir'] 84 self._span = re.compile( 85 "(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" % 86 ('|'.join(_span_1), '|'.join(_span_2)), 87 re.IGNORECASE) 88 self._range = re.compile( 89 "(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" % 90 ('|'.join(_range_1), '|'.join(_range_2)), 91 re.IGNORECASE)
92 93 #------------------------------------------------------------------------- 94 # 95 # Lithuanian displayer 96 # 97 #-------------------------------------------------------------------------
98 -class DateDisplayLT(DateDisplay):
99 100 calendar = ( 101 u"", u" (julijaus)", 102 u" (hebrajų)", 103 u" (prancuzų respublikos)", 104 u" (persų)", 105 u" (islamo)" 106 ) 107 108 _mod_str = (u"", 109 u"prieš ", 110 u"po ", 111 u"apie ", 112 u"", u"", u"") 113 114 _qual_str = (u"", u"apytikriai ", u"apskaičiuota ") 115 116 formats = ( 117 "YYYY-MM-DD (ISO)", "Skaitmeninis", "Mėnuo Diena, Metai", 118 "Mėn DD, YYYY", "Diena Mėnuo Metai", "DD Mėn YYYY" 119 ) 120
121 - def display(self, date):
122 """ 123 Return a text string representing the date. 124 """ 125 mod = date.get_modifier() 126 cal = date.get_calendar() 127 qual = date.get_quality() 128 start = date.get_start_date() 129 130 qual_str = self._qual_str[qual] 131 132 if mod == Date.MOD_TEXTONLY: 133 return date.get_text() 134 elif start == Date.EMPTY: 135 return "" 136 elif mod == Date.MOD_SPAN: 137 d1 = self.display_cal[cal](start) 138 d2 = self.display_cal[cal](date.get_stop_date()) 139 return "%s%s %s %s %s%s" % (qual_str, u'nuo', d1, u'iki', 140 d2, self.calendar[cal]) 141 elif mod == Date.MOD_RANGE: 142 d1 = self.display_cal[cal](start) 143 d2 = self.display_cal[cal](date.get_stop_date()) 144 return "%s%s %s %s %s%s" % (qual_str, u'tarp', d1, u'ir', 145 d2, self.calendar[cal]) 146 else: 147 text = self.display_cal[date.get_calendar()](start) 148 return "%s%s%s%s" % (qual_str, self._mod_str[mod], text, 149 self.calendar[cal])
150 151 #------------------------------------------------------------------------- 152 # 153 # Register classes 154 # 155 #------------------------------------------------------------------------- 156 register_datehandler(('lt_LT', 'lt', 'lithuanian'), DateParserLT, DateDisplayLT) 157