2005-12-06 12:08:09 +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
|
2005-12-06 12:08:09 +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,
|
2005-12-06 12:08:09 +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
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
# $Id$
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
Swedish-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
|
2005-12-06 12:08:09 +05:30
|
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
|
#
|
|
|
|
|
# Swedish parser class
|
|
|
|
|
#
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
|
class DateParserSv(DateParser):
|
|
|
|
|
"""
|
|
|
|
|
Converts a text string into a Date object, expecting a date
|
2007-06-27 10:20:33 +05:30
|
|
|
|
notation in the swedish language. If the date cannot be converted,
|
2005-12-06 12:08:09 +05:30
|
|
|
|
the text string is assigned.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
# modifiers before the date
|
|
|
|
|
modifier_to_int = {
|
2007-06-27 10:20:33 +05:30
|
|
|
|
u'före' : Date.MOD_BEFORE,
|
|
|
|
|
u'innan' : Date.MOD_BEFORE,
|
|
|
|
|
u'efter' : Date.MOD_AFTER,
|
|
|
|
|
u'omkring' : Date.MOD_ABOUT,
|
|
|
|
|
u'ca' : Date.MOD_ABOUT,
|
2006-12-21 18:34:02 +05:30
|
|
|
|
u'c:a' : Date.MOD_ABOUT
|
2005-12-06 12:08:09 +05:30
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bce = ["f Kr"]
|
|
|
|
|
|
|
|
|
|
calendar_to_int = {
|
2007-06-27 10:20:33 +05:30
|
|
|
|
u'gregoriansk ' : Date.CAL_GREGORIAN,
|
|
|
|
|
u'g' : Date.CAL_GREGORIAN,
|
|
|
|
|
u'juliansk' : Date.CAL_JULIAN,
|
|
|
|
|
u'j' : Date.CAL_JULIAN,
|
|
|
|
|
u'hebreisk' : 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,
|
2005-12-06 12:08:09 +05:30
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
quality_to_int = {
|
2007-06-27 10:20:33 +05:30
|
|
|
|
u'uppskattat' : Date.QUAL_ESTIMATED,
|
|
|
|
|
u'uppskattad' : Date.QUAL_ESTIMATED,
|
|
|
|
|
u'bedömt' : Date.QUAL_ESTIMATED,
|
|
|
|
|
u'bedömd' : Date.QUAL_ESTIMATED,
|
|
|
|
|
u'beräknat' : Date.QUAL_CALCULATED,
|
|
|
|
|
u'beräknad' : Date.QUAL_CALCULATED,
|
2005-12-06 12:08:09 +05:30
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
def init_strings(self):
|
|
|
|
|
DateParser.init_strings(self)
|
2007-06-27 10:20:33 +05:30
|
|
|
|
self._span = re.compile(u"(från)?\s*(?P<start>.+)\s*(till|--|–)\s*(?P<stop>.+)",
|
2005-12-06 12:08:09 +05:30
|
|
|
|
re.IGNORECASE)
|
2007-06-27 10:20:33 +05:30
|
|
|
|
self._range = re.compile(u"(mellan)\s+(?P<start>.+)\s+och\s+(?P<stop>.+)",
|
2005-12-06 12:08:09 +05:30
|
|
|
|
re.IGNORECASE)
|
|
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
|
#
|
|
|
|
|
# Swedish display class
|
|
|
|
|
#
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
|
class DateDisplaySv(DateDisplay):
|
|
|
|
|
"""
|
|
|
|
|
Swedish language date display class.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
formats = (
|
2007-06-27 10:20:33 +05:30
|
|
|
|
u"YYYY-MM-DD (ISO)",
|
|
|
|
|
u"Numerisk",
|
|
|
|
|
u"Månad dag, år",
|
|
|
|
|
u"MÅN DAG ÅR",
|
|
|
|
|
u"Dag månad år",
|
|
|
|
|
u"DAG MÅN ÅR",
|
2005-12-06 12:08:09 +05:30
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
calendar = (
|
2007-06-27 10:20:33 +05:30
|
|
|
|
"",
|
|
|
|
|
" (juliansk)",
|
|
|
|
|
" (hebreisk)",
|
|
|
|
|
" (fransk republikansk)",
|
|
|
|
|
" (persisk)",
|
2005-12-06 12:08:09 +05:30
|
|
|
|
" (islamisk)"
|
|
|
|
|
)
|
|
|
|
|
|
2007-06-27 10:20:33 +05:30
|
|
|
|
_mod_str = ("", u"före ", u"efter ", u"c:a ", "", "", "")
|
2005-12-06 12:08:09 +05:30
|
|
|
|
|
2007-06-27 10:20:33 +05:30
|
|
|
|
_qual_str = ("", u"uppskattat ", u"beräknat ")
|
2005-12-06 12:08:09 +05:30
|
|
|
|
|
|
|
|
|
_bce_str = "%s f Kr"
|
|
|
|
|
|
2007-06-27 10:20:33 +05:30
|
|
|
|
def display(self, date):
|
2005-12-06 12:08:09 +05:30
|
|
|
|
"""
|
|
|
|
|
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:
|
2006-05-02 02:41:26 +05:30
|
|
|
|
return u""
|
2005-12-06 12:08:09 +05:30
|
|
|
|
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 u"%sfrån %s till %s%s" % (qual_str, d1, d2, self.calendar[cal])
|
2005-12-06 12:08:09 +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 u"%smellan %s och %s%s" % (qual_str, d1, d2,
|
2005-12-06 12:08:09 +05:30
|
|
|
|
self.calendar[cal])
|
|
|
|
|
else:
|
|
|
|
|
text = self.display_cal[date.get_calendar()](start)
|
2007-06-27 10:20:33 +05:30
|
|
|
|
return u"%s%s%s%s" % (qual_str, self._mod_str[mod],
|
|
|
|
|
text, self.calendar[cal])
|
2005-12-06 12:08:09 +05:30
|
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
|
#
|
|
|
|
|
# Register classes
|
|
|
|
|
#
|
|
|
|
|
#-------------------------------------------------------------------------
|
2007-06-27 10:20:33 +05:30
|
|
|
|
register_datehandler(('sv_SE', 'sv', 'svensk'), DateParserSv, DateDisplaySv)
|