From c8eeede587c0c4d70a9f9b58d0f9fb96e52f5360 Mon Sep 17 00:00:00 2001 From: Espen Berg Date: Tue, 27 Nov 2007 20:14:04 +0000 Subject: [PATCH] Norwegian date handler applied svn: r9419 --- src/DateHandler/Makefile.am | 1 + src/DateHandler/_Date_nb.py | 165 ++++++++++++++++++++++++++++++++++++ src/DateHandler/__init__.py | 1 + 3 files changed, 167 insertions(+) create mode 100644 src/DateHandler/_Date_nb.py diff --git a/src/DateHandler/Makefile.am b/src/DateHandler/Makefile.am index c115ee2bb..c0a466aa6 100644 --- a/src/DateHandler/Makefile.am +++ b/src/DateHandler/Makefile.am @@ -13,6 +13,7 @@ pkgdata_PYTHON = \ _Date_es.py\ _Date_fi.py\ _Date_sv.py\ + _Date_nb.py\ _Date_nl.py\ _Date_sk.py\ _Date_pl.py\ diff --git a/src/DateHandler/_Date_nb.py b/src/DateHandler/_Date_nb.py new file mode 100644 index 000000000..bfdb6fbb8 --- /dev/null +++ b/src/DateHandler/_Date_nb.py @@ -0,0 +1,165 @@ +# -*- coding: utf-8 -*- +# +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2004-2006 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: _Date_nb.py 9101 2007-10-08 16:41:39Z dallingham $ + +""" +Norwegian-specific classes for parsing and displaying dates. +""" + +#------------------------------------------------------------------------- +# +# Python modules +# +#------------------------------------------------------------------------- +import re + +#------------------------------------------------------------------------- +# +# GRAMPS modules +# +#------------------------------------------------------------------------- +from gen.lib import Date +from _DateParser import DateParser +from _DateDisplay import DateDisplay +from _DateHandler import register_datehandler + +#------------------------------------------------------------------------- +# +# Swedish parser class +# +#------------------------------------------------------------------------- +class DateParserNb(DateParser): + """ + Converts a text string into a Date object, expecting a date + notation in the Norwegian language. If the date cannot be converted, + the text string is assigned. + """ + + # modifiers before the date + modifier_to_int = { + u'før' : Date.MOD_BEFORE, + u'innen' : Date.MOD_BEFORE, + u'etter' : Date.MOD_AFTER, + u'omkring' : Date.MOD_ABOUT, + u'ca' : Date.MOD_ABOUT + } + + bce = ["f Kr"] + + calendar_to_int = { + u'gregoriansk ' : Date.CAL_GREGORIAN, + u'g' : Date.CAL_GREGORIAN, + u'juliansk' : Date.CAL_JULIAN, + u'j' : Date.CAL_JULIAN, + u'hebraisk' : Date.CAL_HEBREW, + u'h' : Date.CAL_HEBREW, + u'islamisk' : Date.CAL_ISLAMIC, + u'muslimsk' : Date.CAL_ISLAMIC, + u'i' : Date.CAL_ISLAMIC, + u'fransk' : Date.CAL_FRENCH, + u'fransk republikansk' : Date.CAL_FRENCH, + u'f' : Date.CAL_FRENCH, + u'persisk' : Date.CAL_PERSIAN, + u'p' : Date.CAL_PERSIAN, + } + + quality_to_int = { + u'estimert' : Date.QUAL_ESTIMATED, + u'beregnet' : Date.QUAL_CALCULATED, + } + + def init_strings(self): + DateParser.init_strings(self) + self._span = re.compile(u"(fra)?\s*(?P.+)\s*(til|--|–)\s*(?P.+)", + re.IGNORECASE) + self._range = re.compile(u"(mellom)\s+(?P.+)\s+og\s+(?P.+)", + re.IGNORECASE) + +#------------------------------------------------------------------------- +# +# Norwegian display class +# +#------------------------------------------------------------------------- +class DateDisplayNb(DateDisplay): + """ + Norwegian language date display class. + """ + + formats = ( + u"ÅÅÅÅ-MM-DD (ISO)", + u"Numerisk", + u"Måned dag, år", + u"Mån Dag År", + u"Dag måned år", + u"Dag Mån År", + ) + + calendar = ( + "", + " (juliansk)", + " (hebraisk)", + " (fransk republikansk)", + " (persisk)", + " (islamisk)" + ) + + _mod_str = ("", u"før ", u"etter ", u"ca ", "", "", "") + + _qual_str = ("", u"beregnet ", u"beregnet ") + + _bce_str = "%s f Kr" + + 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 u"" + elif mod == Date.MOD_SPAN: + d1 = self.display_cal[cal](start) + d2 = self.display_cal[cal](date.get_stop_date()) + return u"%sfra %s til %s%s" % (qual_str, d1, 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 u"%smellom %s og %s%s" % (qual_str, d1, d2, + self.calendar[cal]) + else: + text = self.display_cal[date.get_calendar()](start) + return u"%s%s%s%s" % (qual_str, self._mod_str[mod], + text, self.calendar[cal]) + +#------------------------------------------------------------------------- +# +# Register classes +# +#------------------------------------------------------------------------- +register_datehandler(('nb_NO', 'nb', 'norsk'), DateParserNb, DateDisplayNb) diff --git a/src/DateHandler/__init__.py b/src/DateHandler/__init__.py index e2a175f93..d2777d135 100644 --- a/src/DateHandler/__init__.py +++ b/src/DateHandler/__init__.py @@ -34,6 +34,7 @@ import _Date_es import _Date_fi import _Date_fr import _Date_lt +import _Date_nb import _Date_nl import _Date_ru import _Date_sv