From 210a6df39c75605db4f321e0e233672a5f967fad Mon Sep 17 00:00:00 2001 From: Don Allingham Date: Wed, 11 May 2005 16:19:01 +0000 Subject: [PATCH] * src/dates/Date_de.py: first pass at a German date handler svn: r4552 --- gramps2/ChangeLog | 3 + gramps2/src/dates/Date_de.py | 131 ++++++++++++++++++++++++++++++++++ gramps2/src/dates/Makefile.am | 1 + 3 files changed, 135 insertions(+) create mode 100644 gramps2/src/dates/Date_de.py diff --git a/gramps2/ChangeLog b/gramps2/ChangeLog index 6a2399b2d..f1caa5587 100644 --- a/gramps2/ChangeLog +++ b/gramps2/ChangeLog @@ -1,3 +1,6 @@ +2005-05-11 Don Allingham + * src/dates/Date_de.py: first pass at a German date handler + 2005-05-11 Martin Hawlisch * src/DateHandler.py: Fallback to "C" locale instead of the ISO format. This currently basically falls back to en, but this could diff --git a/gramps2/src/dates/Date_de.py b/gramps2/src/dates/Date_de.py new file mode 100644 index 000000000..9b9a6da7c --- /dev/null +++ b/gramps2/src/dates/Date_de.py @@ -0,0 +1,131 @@ +# -*- coding: utf-8 -*- +# +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2004-2005 Donald N. Allingham +# +# 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. +# +# This program is distributed in the hope that it will be useful, +# 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 +# + +# $Id$ + +""" +German-specific classes for parsing and displaying dates. +""" + +#------------------------------------------------------------------------- +# +# Python modules +# +#------------------------------------------------------------------------- +import re + +#------------------------------------------------------------------------- +# +# GRAMPS modules +# +#------------------------------------------------------------------------- +import Date +from DateParser import DateParser +from DateDisplay import DateDisplay + +#------------------------------------------------------------------------- +# +# French parser +# +#------------------------------------------------------------------------- +class DateParserDE(DateParser): + + modifier_to_int = { + u'vor' : Date.MOD_BEFORE, + u'nach' : Date.MOD_AFTER, + u'über' : Date.MOD_ABOUT, + u'um' : Date.MOD_ABOUT, + } + + calendar_to_int = { + u'Gregorianisch' : Date.CAL_GREGORIAN, + u'Julianisch' : Date.CAL_JULIAN, + u'Hebräisch' : Date.CAL_HEBREW, + u'Islamisch' : Date.CAL_ISLAMIC, + u'Französischer Republikaner': Date.CAL_FRENCH, + u'Persisch' : Date.CAL_PERSIAN, + } + + quality_to_int = { + u'geschätzt' : Date.QUAL_ESTIMATED, + u'errechnet' : Date.QUAL_CALCULATED, + } + + def init_strings(self): + DateParser.init_strings(self) + self._span = re.compile("(von|vom)\s+(.+)\s+bis\s+(.+)",re.IGNORECASE) + self._range = re.compile("zwischen\s+(.+)\s+and\s+(.+)", re.IGNORECASE) + +#------------------------------------------------------------------------- +# +# French display +# +#------------------------------------------------------------------------- +class DateDisplayDE(DateDisplay): + + calendar = ( + "", u" (Julianisch)", u" (Hebräisch)", + u" (Französischer Republikaner)", u" (Persisch)", u" (Islamisch)" + ) + + _mod_str = ("",u"avant ",u"après ",u"vers ","","","") + + _qual_str = ("","calculated ","estimated ") + + formats = ( + "JJJJ-MM-DD (ISO)", "Numerisch", "Monat Tag Jahr", + "MICH Tag Jahr", "Tag Monat Jahr", "Tag MONAT Jahr" + ) + + def display(self,date): + """ + Returns a text string representing the date. + """ + 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()) + return "%s%s %s %s %s%s" % (qual_str,u'de',d1,u'à',d2,self.calendar[cal]) + elif mod == Date.MOD_RANGE: + d1 = self.display_cal[cal](start) + d2 = self.display_cal[cal](date.get_stop_date()) + return "%szwischen %s and %s%s" % (qual_str,d1,d2,self.calendar[cal]) + else: + text = self.display_cal[date.get_calendar()](start) + return "%s%s%s%s" % (qual_str,self._mod_str[mod],text,self.calendar[cal]) + +#------------------------------------------------------------------------- +# +# Register classes +# +#------------------------------------------------------------------------- +from DateHandler import register_datehandler +register_datehandler(('de_DE','german'),DateParserDE, DateDisplayDE) diff --git a/gramps2/src/dates/Makefile.am b/gramps2/src/dates/Makefile.am index d4a8b1e4c..08f7bb5bb 100644 --- a/gramps2/src/dates/Makefile.am +++ b/gramps2/src/dates/Makefile.am @@ -6,6 +6,7 @@ pkgdatadir = $(datadir)/@PACKAGE@/dates pkgdata_PYTHON = \ + Date_de.py\ Date_ru.py\ Date_fr.py\ Date_es.py\