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

Source Code for Module DateHandler._Date_pt

  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  # Portuguese version translated by Duarte Loreto <happyguy_pt@hotmail.com>, 2007. 
 22  # Based on the Spanish file. 
 23   
 24  # $Id: _Date_pt.py 10103 2008-02-24 13:55:55Z acraphae $ 
 25   
 26  """ 
 27  Portuguese-specific classes for parsing and displaying dates. 
 28  """ 
 29   
 30  #------------------------------------------------------------------------- 
 31  # 
 32  # Python modules 
 33  # 
 34  #------------------------------------------------------------------------- 
 35  import re 
 36   
 37  #------------------------------------------------------------------------- 
 38  # 
 39  # GRAMPS modules 
 40  # 
 41  #------------------------------------------------------------------------- 
 42  from gen.lib import Date 
 43  from _DateParser import DateParser 
 44  from _DateDisplay import DateDisplay 
 45  from _DateHandler import register_datehandler 
 46   
 47  #------------------------------------------------------------------------- 
 48  # 
 49  # Portuguese parser 
 50  # 
 51  #------------------------------------------------------------------------- 
52 -class DateParserPT(DateParser):
53 54 modifier_to_int = { 55 u'antes de' : Date.MOD_BEFORE, 56 u'antes' : Date.MOD_BEFORE, 57 u'ant.' : Date.MOD_BEFORE, 58 u'ant' : Date.MOD_BEFORE, 59 u'após' : Date.MOD_AFTER, 60 u'aprox.' : Date.MOD_ABOUT, 61 u'aprox' : Date.MOD_ABOUT, 62 u'apr.' : Date.MOD_ABOUT, 63 u'apr' : Date.MOD_ABOUT, 64 u'cerca de' : Date.MOD_ABOUT, 65 u'ca.' : Date.MOD_ABOUT, 66 u'ca' : Date.MOD_ABOUT, 67 u'c.' : Date.MOD_ABOUT, 68 u'até' : Date.MOD_ABOUT, 69 } 70 71 calendar_to_int = { 72 u'gregoriano' : Date.CAL_GREGORIAN, 73 u'g' : Date.CAL_GREGORIAN, 74 u'juliano' : Date.CAL_JULIAN, 75 u'j' : Date.CAL_JULIAN, 76 u'hebreu' : Date.CAL_HEBREW, 77 u'h' : Date.CAL_HEBREW, 78 u'islâmico' : Date.CAL_ISLAMIC, 79 u'i' : Date.CAL_ISLAMIC, 80 u'revolucionário' : Date.CAL_FRENCH, 81 u'r' : Date.CAL_FRENCH, 82 u'persa' : Date.CAL_PERSIAN, 83 u'p' : Date.CAL_PERSIAN, 84 } 85 86 quality_to_int = { 87 u'estimado' : Date.QUAL_ESTIMATED, 88 u'est.' : Date.QUAL_ESTIMATED, 89 u'est' : Date.QUAL_ESTIMATED, 90 u'calc.' : Date.QUAL_CALCULATED, 91 u'calc' : Date.QUAL_CALCULATED, 92 u'calculado' : Date.QUAL_CALCULATED, 93 } 94
95 - def init_strings(self):
96 DateParser.init_strings(self) 97 _span_1 = [u'de'] 98 _span_2 = [u'a'] 99 _range_1 = [u'entre',u'ent\.',u'ent'] 100 _range_2 = [u'e'] 101 self._span = re.compile("(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" % 102 ('|'.join(_span_1),'|'.join(_span_2)), 103 re.IGNORECASE) 104 self._range = re.compile("(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" % 105 ('|'.join(_range_1),'|'.join(_range_2)), 106 re.IGNORECASE)
107 108 #------------------------------------------------------------------------- 109 # 110 # Portuguese display 111 # 112 #-------------------------------------------------------------------------
113 -class DateDisplayPT(DateDisplay):
114 115 calendar = ( 116 "", u" (Juliano)", u" (Hebreu)", 117 u" (Revolucionário)", u" (Persa)", u" (Islâmico)" 118 ) 119 120 _mod_str = ("",u"antes de ",u"depois de ",u"até ","","","") 121 122 _qual_str = ("","estimado ","calculado ") 123 124 formats = ( 125 "AAAA-MM-DD (ISO)", "Numérica", "Mês Dia, Ano", 126 "MÊS Dia, Ano", "Dia Mês, Ano", "Dia MÊS, Ano" 127 ) 128
129 - def display(self,date):
130 """ 131 Return a text string representing the date. 132 """ 133 mod = date.get_modifier() 134 cal = date.get_calendar() 135 qual = date.get_quality() 136 start = date.get_start_date() 137 138 qual_str = self._qual_str[qual] 139 140 if mod == Date.MOD_TEXTONLY: 141 return date.get_text() 142 elif start == Date.EMPTY: 143 return "" 144 elif mod == Date.MOD_SPAN: 145 d1 = self.display_cal[cal](start) 146 d2 = self.display_cal[cal](date.get_stop_date()) 147 return "%s%s %s %s %s%s" % (qual_str, u'de', d1, u'a', d2,self.calendar[cal]) 148 elif mod == Date.MOD_RANGE: 149 d1 = self.display_cal[cal](start) 150 d2 = self.display_cal[cal](date.get_stop_date()) 151 return "%s%s %s %s %s%s" % (qual_str, u'entre', d1, u'e', d2, self.calendar[cal]) 152 else: 153 text = self.display_cal[date.get_calendar()](start) 154 return "%s%s%s%s" % (qual_str, self._mod_str[mod], text, self.calendar[cal])
155 156 #------------------------------------------------------------------------- 157 # 158 # Register classes 159 # 160 #------------------------------------------------------------------------- 161 register_datehandler(('pt', 'pt_PT', 'pt_PT.UTF-8', 'pt_BR', 'pt_BR.UTF-8', 'pt', 'portuguese'), DateParserPT, DateDisplayPT) 162