2004-12-15 20:04:34 +05:30
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
2006-02-04 03:33:53 +05:30
|
|
|
# Copyright (C) 2004-2006 Donald N. Allingham
|
2004-12-15 20:04:34 +05:30
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
2007-06-27 10:20:33 +05:30
|
|
|
# This program is distributed in the hope that it will be useful,
|
2004-12-15 20:04:34 +05:30
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
#
|
|
|
|
|
2008-02-24 19:25:55 +05:30
|
|
|
# $Id:_Date_es.py 9912 2008-01-22 09:17:46Z acraphae $
|
2004-12-15 20:04:34 +05:30
|
|
|
|
|
|
|
"""
|
|
|
|
Spanish-specific classes for parsing and displaying dates.
|
|
|
|
"""
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Python modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import re
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GRAMPS modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2007-10-08 22:11:39 +05:30
|
|
|
from gen.lib import Date
|
2006-03-11 10:28:58 +05:30
|
|
|
from _DateParser import DateParser
|
|
|
|
from _DateDisplay import DateDisplay
|
|
|
|
from _DateHandler import register_datehandler
|
2004-12-15 20:04:34 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Spanish parser
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class DateParserES(DateParser):
|
|
|
|
|
|
|
|
modifier_to_int = {
|
|
|
|
u'antes de' : Date.MOD_BEFORE,
|
|
|
|
u'antes' : Date.MOD_BEFORE,
|
|
|
|
u'ant.' : Date.MOD_BEFORE,
|
|
|
|
u'ant' : Date.MOD_BEFORE,
|
2007-06-27 10:20:33 +05:30
|
|
|
u'después de' : Date.MOD_AFTER,
|
|
|
|
u'después' : Date.MOD_AFTER,
|
|
|
|
u'desp.' : Date.MOD_AFTER,
|
|
|
|
u'desp' : Date.MOD_AFTER,
|
|
|
|
u'aprox.' : Date.MOD_ABOUT,
|
|
|
|
u'aprox' : Date.MOD_ABOUT,
|
|
|
|
u'apr.' : Date.MOD_ABOUT,
|
|
|
|
u'apr' : Date.MOD_ABOUT,
|
|
|
|
u'circa' : Date.MOD_ABOUT,
|
|
|
|
u'ca.' : Date.MOD_ABOUT,
|
|
|
|
u'ca' : Date.MOD_ABOUT,
|
|
|
|
u'c.' : Date.MOD_ABOUT,
|
|
|
|
u'hacia' : Date.MOD_ABOUT,
|
2004-12-15 20:04:34 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
calendar_to_int = {
|
2007-06-27 10:20:33 +05:30
|
|
|
u'gregoriano' : Date.CAL_GREGORIAN,
|
|
|
|
u'g' : Date.CAL_GREGORIAN,
|
|
|
|
u'juliano' : Date.CAL_JULIAN,
|
|
|
|
u'j' : Date.CAL_JULIAN,
|
|
|
|
u'hebreo' : Date.CAL_HEBREW,
|
|
|
|
u'h' : Date.CAL_HEBREW,
|
|
|
|
u'islámico' : Date.CAL_ISLAMIC,
|
|
|
|
u'i' : Date.CAL_ISLAMIC,
|
|
|
|
u'revolucionario' : Date.CAL_FRENCH,
|
|
|
|
u'r' : Date.CAL_FRENCH,
|
|
|
|
u'persa' : Date.CAL_PERSIAN,
|
|
|
|
u'p' : Date.CAL_PERSIAN,
|
2009-01-20 21:08:29 +05:30
|
|
|
u'swedish' : Date.CAL_SWEDISH,
|
|
|
|
u's' : Date.CAL_SWEDISH,
|
2004-12-15 20:04:34 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
quality_to_int = {
|
2007-06-27 10:20:33 +05:30
|
|
|
u'estimado' : Date.QUAL_ESTIMATED,
|
|
|
|
u'est.' : Date.QUAL_ESTIMATED,
|
|
|
|
u'est' : Date.QUAL_ESTIMATED,
|
|
|
|
u'calc.' : Date.QUAL_CALCULATED,
|
|
|
|
u'calc' : Date.QUAL_CALCULATED,
|
|
|
|
u'calculado' : Date.QUAL_CALCULATED,
|
2004-12-15 20:04:34 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
def init_strings(self):
|
|
|
|
DateParser.init_strings(self)
|
|
|
|
_span_1 = [u'de']
|
|
|
|
_span_2 = [u'a']
|
2007-06-27 10:20:33 +05:30
|
|
|
_range_1 = [u'entre', u'ent\.', u'ent']
|
2004-12-15 20:04:34 +05:30
|
|
|
_range_2 = [u'y']
|
2007-06-27 10:20:33 +05:30
|
|
|
self._span = re.compile("(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" %
|
|
|
|
('|'.join(_span_1), '|'.join(_span_2)),
|
|
|
|
re.IGNORECASE)
|
|
|
|
self._range = re.compile("(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" %
|
|
|
|
('|'.join(_range_1), '|'.join(_range_2)),
|
|
|
|
re.IGNORECASE)
|
2004-12-15 20:04:34 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Spanish display
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class DateDisplayES(DateDisplay):
|
2009-10-28 08:55:57 +05:30
|
|
|
"""
|
|
|
|
Spanish language date display class.
|
|
|
|
"""
|
|
|
|
# TODO: Translate these month strings:
|
2009-10-28 17:51:37 +05:30
|
|
|
long_months = ( u"", u"enero", u"febrero", u"marzo", u"abril", u"mayo",
|
2009-10-28 08:55:57 +05:30
|
|
|
u"junio", u"julio", u"agosto", u"septiembre", u"octubre",
|
|
|
|
u"noviembre", u"diciembre" )
|
|
|
|
|
2009-10-28 17:51:37 +05:30
|
|
|
short_months = ( u"", u"enero", u"feb.", u"marzo", u"abr.", u"mayo",
|
|
|
|
u"jun.", u"jul.", u"agosto", u"set.", u"oct.", u"nov.",
|
|
|
|
u"dic" )
|
2004-12-15 20:04:34 +05:30
|
|
|
|
|
|
|
calendar = (
|
|
|
|
"", u" (Juliano)", u" (Hebreo)",
|
2009-01-20 21:08:29 +05:30
|
|
|
u" (Revolucionario)", u" (Persa)", u" (Islámico)",
|
|
|
|
u" (Swedish)"
|
2004-12-15 20:04:34 +05:30
|
|
|
)
|
|
|
|
|
2007-06-27 10:20:33 +05:30
|
|
|
_mod_str = ("", u"antes de ", u"después de ", u"hacia ", "", "", "")
|
2005-01-19 10:43:09 +05:30
|
|
|
|
2007-06-27 10:20:33 +05:30
|
|
|
_qual_str = ("", "estimado ", "calculado ")
|
2005-01-19 10:43:09 +05:30
|
|
|
|
|
|
|
formats = (
|
2007-06-27 10:20:33 +05:30
|
|
|
"AAAA-MM-DD (ISO)", "Numérica", "Mes Día, Año",
|
2005-01-19 10:43:09 +05:30
|
|
|
"MES Día, Año", "Día Mes, Año", "Día MES, Año"
|
|
|
|
)
|
2004-12-15 20:04:34 +05:30
|
|
|
|
2007-06-27 10:20:33 +05:30
|
|
|
def display(self, date):
|
2004-12-15 20:04:34 +05:30
|
|
|
"""
|
2008-02-24 19:25:55 +05:30
|
|
|
Return a text string representing the date.
|
2005-01-19 10:45:30 +05:30
|
|
|
"""
|
2004-12-15 20:04:34 +05:30
|
|
|
mod = date.get_modifier()
|
|
|
|
cal = date.get_calendar()
|
|
|
|
qual = date.get_quality()
|
|
|
|
start = date.get_start_date()
|
|
|
|
|
|
|
|
qual_str = self._qual_str[qual]
|
|
|
|
|
|
|
|
if mod == Date.MOD_TEXTONLY:
|
|
|
|
return date.get_text()
|
|
|
|
elif start == Date.EMPTY:
|
|
|
|
return ""
|
|
|
|
elif mod == Date.MOD_SPAN:
|
|
|
|
d1 = self.display_cal[cal](start)
|
|
|
|
d2 = self.display_cal[cal](date.get_stop_date())
|
2007-06-27 10:20:33 +05:30
|
|
|
return "%s%s %s %s %s%s" % (qual_str, u'de', d1, u'a', d2, self.calendar[cal])
|
2004-12-15 20:04:34 +05:30
|
|
|
elif mod == Date.MOD_RANGE:
|
|
|
|
d1 = self.display_cal[cal](start)
|
|
|
|
d2 = self.display_cal[cal](date.get_stop_date())
|
2007-06-27 10:20:33 +05:30
|
|
|
return "%s%s %s %s %s%s" % (qual_str, u'entre', d1, u'y', d2, self.calendar[cal])
|
2004-12-15 20:04:34 +05:30
|
|
|
else:
|
|
|
|
text = self.display_cal[date.get_calendar()](start)
|
2007-06-27 10:20:33 +05:30
|
|
|
return "%s%s%s%s" % (qual_str, self._mod_str[mod], text, self.calendar[cal])
|
2004-12-15 20:04:34 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Register classes
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2008-11-13 14:33:05 +05:30
|
|
|
register_datehandler(('es_ES', 'es', 'spanish', 'Spanish'), DateParserES, DateDisplayES)
|