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

Source Code for Module DateHandler._Date_es

  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_es.py 9912 2008-01-22 09:17:46Z acraphae $ 
 23   
 24  """ 
 25  Spanish-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  # Spanish parser 
 48  # 
 49  #------------------------------------------------------------------------- 
50 -class DateParserES(DateParser):
51 52 modifier_to_int = { 53 u'antes de' : Date.MOD_BEFORE, 54 u'antes' : Date.MOD_BEFORE, 55 u'ant.' : Date.MOD_BEFORE, 56 u'ant' : Date.MOD_BEFORE, 57 u'después de' : Date.MOD_AFTER, 58 u'después' : Date.MOD_AFTER, 59 u'desp.' : Date.MOD_AFTER, 60 u'desp' : Date.MOD_AFTER, 61 u'aprox.' : Date.MOD_ABOUT, 62 u'aprox' : Date.MOD_ABOUT, 63 u'apr.' : Date.MOD_ABOUT, 64 u'apr' : Date.MOD_ABOUT, 65 u'circa' : Date.MOD_ABOUT, 66 u'ca.' : Date.MOD_ABOUT, 67 u'ca' : Date.MOD_ABOUT, 68 u'c.' : Date.MOD_ABOUT, 69 u'hacia' : Date.MOD_ABOUT, 70 } 71 72 calendar_to_int = { 73 u'gregoriano' : Date.CAL_GREGORIAN, 74 u'g' : Date.CAL_GREGORIAN, 75 u'juliano' : Date.CAL_JULIAN, 76 u'j' : Date.CAL_JULIAN, 77 u'hebreo' : Date.CAL_HEBREW, 78 u'h' : Date.CAL_HEBREW, 79 u'islámico' : Date.CAL_ISLAMIC, 80 u'i' : Date.CAL_ISLAMIC, 81 u'revolucionario' : Date.CAL_FRENCH, 82 u'r' : Date.CAL_FRENCH, 83 u'persa' : Date.CAL_PERSIAN, 84 u'p' : Date.CAL_PERSIAN, 85 } 86 87 quality_to_int = { 88 u'estimado' : Date.QUAL_ESTIMATED, 89 u'est.' : Date.QUAL_ESTIMATED, 90 u'est' : Date.QUAL_ESTIMATED, 91 u'calc.' : Date.QUAL_CALCULATED, 92 u'calc' : Date.QUAL_CALCULATED, 93 u'calculado' : Date.QUAL_CALCULATED, 94 } 95
96 - def init_strings(self):
97 DateParser.init_strings(self) 98 _span_1 = [u'de'] 99 _span_2 = [u'a'] 100 _range_1 = [u'entre', u'ent\.', u'ent'] 101 _range_2 = [u'y'] 102 self._span = re.compile("(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" % 103 ('|'.join(_span_1), '|'.join(_span_2)), 104 re.IGNORECASE) 105 self._range = re.compile("(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" % 106 ('|'.join(_range_1), '|'.join(_range_2)), 107 re.IGNORECASE)
108 109 #------------------------------------------------------------------------- 110 # 111 # Spanish display 112 # 113 #-------------------------------------------------------------------------
114 -class DateDisplayES(DateDisplay):
115 116 calendar = ( 117 "", u" (Juliano)", u" (Hebreo)", 118 u" (Revolucionario)", u" (Persa)", u" (Islámico)" 119 ) 120 121 _mod_str = ("", u"antes de ", u"después de ", u"hacia ", "", "", "") 122 123 _qual_str = ("", "estimado ", "calculado ") 124 125 formats = ( 126 "AAAA-MM-DD (ISO)", "Numérica", "Mes Día, Año", 127 "MES Día, Año", "Día Mes, Año", "Día MES, Año" 128 ) 129
130 - def display(self, date):
131 """ 132 Return a text string representing the date. 133 """ 134 mod = date.get_modifier() 135 cal = date.get_calendar() 136 qual = date.get_quality() 137 start = date.get_start_date() 138 139 qual_str = self._qual_str[qual] 140 141 if mod == Date.MOD_TEXTONLY: 142 return date.get_text() 143 elif start == Date.EMPTY: 144 return "" 145 elif mod == Date.MOD_SPAN: 146 d1 = self.display_cal[cal](start) 147 d2 = self.display_cal[cal](date.get_stop_date()) 148 return "%s%s %s %s %s%s" % (qual_str, u'de', d1, u'a', d2, self.calendar[cal]) 149 elif mod == Date.MOD_RANGE: 150 d1 = self.display_cal[cal](start) 151 d2 = self.display_cal[cal](date.get_stop_date()) 152 return "%s%s %s %s %s%s" % (qual_str, u'entre', d1, u'y', d2, self.calendar[cal]) 153 else: 154 text = self.display_cal[date.get_calendar()](start) 155 return "%s%s%s%s" % (qual_str, self._mod_str[mod], text, self.calendar[cal])
156 157 #------------------------------------------------------------------------- 158 # 159 # Register classes 160 # 161 #------------------------------------------------------------------------- 162 register_datehandler(('es_ES', 'es', 'spanish'), DateParserES, DateDisplayES) 163