2007-11-28 01:44:04 +05:30
|
|
|
|
# -*- 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
|
|
|
|
|
#
|
|
|
|
|
|
2008-01-22 14:47:46 +05:30
|
|
|
|
# $Id$
|
2007-11-28 01:44:04 +05:30
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
|
#
|
2008-05-04 13:25:01 +05:30
|
|
|
|
# Norwegian parser class
|
2007-11-28 01:44:04 +05:30
|
|
|
|
#
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
|
class DateParserNb(DateParser):
|
|
|
|
|
"""
|
2008-02-24 19:25:55 +05:30
|
|
|
|
Convert a text string into a Date object, expecting a date
|
2007-11-28 01:44:04 +05:30
|
|
|
|
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,
|
2009-01-20 21:08:29 +05:30
|
|
|
|
u'svensk' : Date.CAL_SWEDISH,
|
|
|
|
|
u's' : Date.CAL_SWEDISH,
|
2007-11-28 01:44:04 +05:30
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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<start>.+)\s*(til|--|–)\s*(?P<stop>.+)",
|
|
|
|
|
re.IGNORECASE)
|
|
|
|
|
self._range = re.compile(u"(mellom)\s+(?P<start>.+)\s+og\s+(?P<stop>.+)",
|
|
|
|
|
re.IGNORECASE)
|
|
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
|
#
|
|
|
|
|
# Norwegian display class
|
|
|
|
|
#
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
|
class DateDisplayNb(DateDisplay):
|
|
|
|
|
"""
|
|
|
|
|
Norwegian language date display class.
|
|
|
|
|
"""
|
2009-10-28 08:55:57 +05:30
|
|
|
|
# TODO: Translate these month strings:
|
2009-10-28 17:51:37 +05:30
|
|
|
|
long_months = ( u"", u"January", u"February", u"March", u"April", u"May",
|
2009-10-28 08:55:57 +05:30
|
|
|
|
u"June", u"July", u"August", u"September", u"October",
|
|
|
|
|
u"November", u"December" )
|
|
|
|
|
|
2009-10-28 17:51:37 +05:30
|
|
|
|
short_months = ( u"", u"Jan", u"Feb", u"Mar", u"Apr", u"May", u"Jun",
|
|
|
|
|
u"Jul", u"Aug", u"Sep", u"Oct", u"Nov", u"Dec" )
|
2007-11-28 01:44:04 +05:30
|
|
|
|
|
|
|
|
|
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)",
|
2009-01-20 21:08:29 +05:30
|
|
|
|
" (islamisk)",
|
|
|
|
|
" (svensk)"
|
2007-11-28 01:44:04 +05:30
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
_mod_str = ("", u"før ", u"etter ", u"ca ", "", "", "")
|
|
|
|
|
|
|
|
|
|
_qual_str = ("", u"beregnet ", u"beregnet ")
|
|
|
|
|
|
|
|
|
|
_bce_str = "%s f Kr"
|
|
|
|
|
|
|
|
|
|
def display(self, date):
|
|
|
|
|
"""
|
2008-02-24 19:25:55 +05:30
|
|
|
|
Return a text string representing the date.
|
2007-11-28 01:44:04 +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 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
|
|
|
|
|
#
|
|
|
|
|
#-------------------------------------------------------------------------
|
2008-11-13 14:33:05 +05:30
|
|
|
|
register_datehandler(('nb_NO', 'nb', 'norsk', 'Norwegian'), DateParserNb, DateDisplayNb)
|