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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 20# 21 22# Catalan Version, 2008 23 24""" 25Catalan-specific classes for parsing and displaying dates. 26""" 27 28#------------------------------------------------------------------------- 29# 30# Python modules 31# 32#------------------------------------------------------------------------- 33import re 34 35#------------------------------------------------------------------------- 36# 37# Gramps modules 38# 39#------------------------------------------------------------------------- 40from ..lib.date import Date 41from ._dateparser import DateParser 42from ._datedisplay import DateDisplay 43from ._datehandler import register_datehandler 44 45#------------------------------------------------------------------------- 46# 47# Catalan parser 48# 49#------------------------------------------------------------------------- 50class DateParserCA(DateParser): 51 52 modifier_to_int = { 53 'abans de' : Date.MOD_BEFORE, 54 'abans' : Date.MOD_BEFORE, 55 'ab.' : Date.MOD_BEFORE, 56 'després de' : Date.MOD_AFTER, 57 'després' : Date.MOD_AFTER, 58 'desp.' : Date.MOD_AFTER, 59 'desp' : Date.MOD_AFTER, 60 'aprox.' : Date.MOD_ABOUT, 61 'aprox' : Date.MOD_ABOUT, 62 'circa' : Date.MOD_ABOUT, 63 'ca.' : Date.MOD_ABOUT, 64 'ca' : Date.MOD_ABOUT, 65 'c.' : Date.MOD_ABOUT, 66 'cap a' : Date.MOD_ABOUT, 67 'al voltant' : Date.MOD_ABOUT, 68 'al voltant de': Date.MOD_ABOUT, 69 } 70 71 calendar_to_int = { 72 'gregorià' : Date.CAL_GREGORIAN, 73 'g' : Date.CAL_GREGORIAN, 74 'julià' : Date.CAL_JULIAN, 75 'j' : Date.CAL_JULIAN, 76 'hebreu' : Date.CAL_HEBREW, 77 'h' : Date.CAL_HEBREW, 78 'islàmic' : Date.CAL_ISLAMIC, 79 'i' : Date.CAL_ISLAMIC, 80 'revolucionari': Date.CAL_FRENCH, 81 'r' : Date.CAL_FRENCH, 82 'persa' : Date.CAL_PERSIAN, 83 'p' : Date.CAL_PERSIAN, 84 'swedish' : Date.CAL_SWEDISH, 85 's' : Date.CAL_SWEDISH, 86 } 87 88 quality_to_int = { 89 'estimat' : Date.QUAL_ESTIMATED, 90 'est.' : Date.QUAL_ESTIMATED, 91 'est' : Date.QUAL_ESTIMATED, 92 'calc.' : Date.QUAL_CALCULATED, 93 'calc' : Date.QUAL_CALCULATED, 94 'calculat' : Date.QUAL_CALCULATED, 95 } 96 97 def init_strings(self): 98 DateParser.init_strings(self) 99 _span_1 = ['des de'] 100 _span_2 = ['fins a'] 101 _range_1 = ['entre', r'ent\.', 'ent'] 102 _range_2 = ['i'] 103 self._span = re.compile( 104 r"(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" % 105 ('|'.join(_span_1), '|'.join(_span_2)), re.IGNORECASE) 106 self._range = re.compile( 107 r"(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" % 108 ('|'.join(_range_1), '|'.join(_range_2)), re.IGNORECASE) 109 110#------------------------------------------------------------------------- 111# 112# Catalan display 113# 114#------------------------------------------------------------------------- 115class DateDisplayCA(DateDisplay): 116 """ 117 Catalan language date display class. 118 """ 119 long_months = ( "", "Gener", "Febrer", "Març", "Abril", "Maig", 120 "Juny", "Juliol", "Agost", "Setembre", "Octubre", 121 "Novembre", "Desembre" ) 122 123 short_months = ( "", "Gen", "Feb", "Mar", "Abr", "Mai", "Jun", 124 "Jul", "Ago", "Set", "Oct", "Nov", "Des" ) 125 126 calendar = ( 127 "", "Julià", "Hebreu", 128 "Revolucionari", "Persa", "Islàmic", 129 "Suec" 130 ) 131 132 _mod_str = ("", "abans de ", "després de ", "cap a ", "", "", "") 133 134 _qual_str = ("", "estimat ", "calculat ") 135 136 french = ( 137 '', 138 "Vendemiari", 139 'Brumari', 140 'Frimari', 141 "Nivós", 142 "Pluviós", 143 "Ventós", 144 'Germinal', 145 "Floreal", 146 'Pradial', 147 'Messidor', 148 'Termidor', 149 'Fructidor', 150 'Extra', 151 ) 152 153 formats = ( 154 "AAAA-MM-DD (ISO)", "Numèrica", "Mes Dia, Any", 155 "MES Dia, Any", "Dia Mes, Any", "Dia MES, Any" 156 ) 157 # this must agree with DateDisplayEn's "formats" definition 158 # (since no locale-specific _display_gregorian exists, here) 159 160 def display(self, date): 161 """ 162 Return a text string representing the date. 163 """ 164 mod = date.get_modifier() 165 cal = date.get_calendar() 166 qual = date.get_quality() 167 start = date.get_start_date() 168 newyear = date.get_new_year() 169 170 qual_str = self._qual_str[qual] 171 172 if mod == Date.MOD_TEXTONLY: 173 return date.get_text() 174 elif start == Date.EMPTY: 175 return "" 176 elif mod == Date.MOD_SPAN: 177 d1 = self.display_cal[cal](start) 178 d2 = self.display_cal[cal](date.get_stop_date()) 179 scal = self.format_extras(cal, newyear) 180 return "%s%s %s %s %s%s" % (qual_str, 'des de', d1, 'fins a', d2, scal) 181 elif mod == Date.MOD_RANGE: 182 d1 = self.display_cal[cal](start) 183 d2 = self.display_cal[cal](date.get_stop_date()) 184 scal = self.format_extras(cal, newyear) 185 return "%s%s %s %s %s%s" % (qual_str, 'entre', d1, 'i', d2, scal) 186 else: 187 text = self.display_cal[date.get_calendar()](start) 188 scal = self.format_extras(cal, newyear) 189 return "%s%s%s%s" % (qual_str, self._mod_str[mod], text, scal) 190 191#------------------------------------------------------------------------- 192# 193# Register classes 194# 195#------------------------------------------------------------------------- 196register_datehandler( 197 ('ca_ES', 'ca', 'català', 'Catalan', 198 'ca_FR', 'ca_AD', 'ca_IT', ('%d/%m/%Y',)), 199 DateParserCA, DateDisplayCA) 200