* src/DateHadnler: Move all date parsers/displayers into new directory
svn: r6097
This commit is contained in:
353
src/DateHandler/DateDisplay.py
Normal file
353
src/DateHandler/DateDisplay.py
Normal file
@@ -0,0 +1,353 @@
|
||||
# -*- coding: iso-8859-1 -*-
|
||||
#
|
||||
# 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$
|
||||
|
||||
"""
|
||||
U.S English date display class. Should serve as the base class for all
|
||||
localized tasks.
|
||||
"""
|
||||
|
||||
__author__ = "Donald N. Allingham"
|
||||
__version__ = "$Revision$"
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# python modules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
from gettext import gettext as _
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# set up logging
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
import logging
|
||||
log = logging.getLogger(".DateDisplay")
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# GRAMPS modules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
from RelLib import Date
|
||||
import GrampsLocale
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# DateDisplay
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
class DateDisplay:
|
||||
|
||||
_months = GrampsLocale.long_months
|
||||
_MONS = GrampsLocale.short_months
|
||||
|
||||
_tformat = GrampsLocale.tformat
|
||||
|
||||
_hebrew = (
|
||||
"", "Tishri", "Heshvan", "Kislev", "Tevet", "Shevat",
|
||||
"AdarI", "AdarII", "Nisan", "Iyyar", "Sivan", "Tammuz",
|
||||
"Av", "Elul"
|
||||
)
|
||||
|
||||
_french = (
|
||||
'',
|
||||
unicode("Vend<EFBFBD>miaire",'latin-1'),
|
||||
'Brumaire',
|
||||
'Frimaire',
|
||||
unicode("Niv<EFBFBD>se",'latin-1'),
|
||||
unicode("Pluvi<EFBFBD>se",'latin-1'),
|
||||
unicode("Vent<EFBFBD>se",'latin-1'),
|
||||
'Germinal',
|
||||
unicode("Flor<EFBFBD>al",'latin-1'),
|
||||
'Prairial',
|
||||
'Messidor',
|
||||
'Thermidor',
|
||||
'Fructidor',
|
||||
'Extra'
|
||||
)
|
||||
|
||||
_persian = (
|
||||
"", "Farvardin", "Ordibehesht", "Khordad", "Tir",
|
||||
"Mordad", "Shahrivar", "Mehr", "Aban", "Azar",
|
||||
"Dey", "Bahman", "Esfand"
|
||||
)
|
||||
|
||||
_islamic = (
|
||||
"", "Muharram", "Safar", "Rabi`al-Awwal", "Rabi`ath-Thani",
|
||||
"Jumada l-Ula", "Jumada t-Tania", "Rajab", "Sha`ban",
|
||||
"Ramadan", "Shawwal", "Dhu l-Qa`da", "Dhu l-Hijja"
|
||||
)
|
||||
|
||||
formats = ("YYYY-MM-DD (ISO)",)
|
||||
|
||||
calendar = (
|
||||
""," (Julian)"," (Hebrew)"," (French Republican)",
|
||||
" (Persian)"," (Islamic)"
|
||||
)
|
||||
|
||||
_mod_str = ("","before ","after ","about ","","","")
|
||||
|
||||
_qual_str = ("","estimated ","calculated ")
|
||||
|
||||
_bce_str = "%s B.C.E."
|
||||
|
||||
def __init__(self,format=None):
|
||||
self.display_cal = [
|
||||
self._display_gregorian,
|
||||
self._display_julian,
|
||||
self._display_hebrew,
|
||||
self._display_french,
|
||||
self._display_persian,
|
||||
self._display_islamic,
|
||||
]
|
||||
|
||||
self.verify_format(format)
|
||||
if format == None:
|
||||
self.format = 0
|
||||
else:
|
||||
self.format = format
|
||||
|
||||
def set_format(self,format):
|
||||
self.format = format
|
||||
|
||||
def verify_format(self,format):
|
||||
pass
|
||||
|
||||
def quote_display(self,date):
|
||||
"""
|
||||
Similar to the display task, except that if the value is a text only
|
||||
value, it is enclosed in quotes.
|
||||
"""
|
||||
if date.get_modifier() == Date.MOD_TEXTONLY:
|
||||
return '"%s"' % self.display(date)
|
||||
else:
|
||||
return self.display(date)
|
||||
|
||||
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 or mod == Date.MOD_RANGE:
|
||||
d1 = self.display_iso(start)
|
||||
d2 = self.display_iso(date.get_stop_date())
|
||||
return "%s %s - %s%s" % (qual_str,d1,d2,self.calendar[cal])
|
||||
elif mod == Date.MOD_RANGE:
|
||||
d1 = self.display_iso(start)
|
||||
d2 = self.display_iso(date.get_stop_date())
|
||||
return "%s %s - %s%s" % (qual_str,d1,d2,self.calendar[cal])
|
||||
else:
|
||||
text = self.display_iso(start)
|
||||
return "%s%s%s%s" % (qual_str,self._mod_str[mod],text,self.calendar[cal])
|
||||
|
||||
def _slash_year(self,val,slash):
|
||||
if val < 0:
|
||||
val = - val
|
||||
|
||||
if slash:
|
||||
year = "%d/%d" % (val,(val%10)+1)
|
||||
else:
|
||||
year = "%d" % (val)
|
||||
|
||||
return year
|
||||
|
||||
def display_iso(self,date_val):
|
||||
# YYYY-MM-DD (ISO)
|
||||
year = self._slash_year(date_val[2],date_val[3])
|
||||
if date_val[0] == 0:
|
||||
if date_val[1] == 0:
|
||||
value = year
|
||||
else:
|
||||
value = "%s-%02d" % (year,date_val[1])
|
||||
else:
|
||||
value = "%s-%02d-%02d" % (year,date_val[1],date_val[0])
|
||||
if date_val[2] < 0:
|
||||
return self._bce_str % value
|
||||
else:
|
||||
return value
|
||||
|
||||
def text_display(self,date):
|
||||
"""
|
||||
Similar to the display task, except that if the value is a text only
|
||||
value, it is enclosed in quotes.
|
||||
"""
|
||||
return date.get_text()
|
||||
|
||||
|
||||
def _display_gregorian(self,date_val):
|
||||
year = self._slash_year(date_val[2],date_val[3])
|
||||
if self.format == 0:
|
||||
return self.display_iso(date_val)
|
||||
elif self.format == 1:
|
||||
if date_val[0] == 0 and date_val[1] == 0:
|
||||
value = str(date_val[2])
|
||||
else:
|
||||
value = self._tformat.replace('%m',str(date_val[1]))
|
||||
value = value.replace('%d',str(date_val[0]))
|
||||
value = value.replace('%Y',str(abs(date_val[2])))
|
||||
value = value.replace('-','/')
|
||||
elif self.format == 2:
|
||||
# Month Day, Year
|
||||
if date_val[0] == 0:
|
||||
if date_val[1] == 0:
|
||||
value = year
|
||||
else:
|
||||
value = "%s %s" % (self._months[date_val[1]],year)
|
||||
else:
|
||||
value = "%s %d, %s" % (self._months[date_val[1]],date_val[0],year)
|
||||
elif self.format == 3:
|
||||
# MON Day, Year
|
||||
if date_val[0] == 0:
|
||||
if date_val[1] == 0:
|
||||
value = year
|
||||
else:
|
||||
value = "%s %s" % (self._MONS[date_val[1]],year)
|
||||
else:
|
||||
value = "%s %d, %s" % (self._MONS[date_val[1]],date_val[0],year)
|
||||
elif self.format == 4:
|
||||
# Day Month Year
|
||||
if date_val[0] == 0:
|
||||
if date_val[1] == 0:
|
||||
value = year
|
||||
else:
|
||||
value = "%s %s" % (self._months[date_val[1]],year)
|
||||
else:
|
||||
value = "%d %s %s" % (date_val[0],self._months[date_val[1]],year)
|
||||
else:
|
||||
# Day MON Year
|
||||
if date_val[0] == 0:
|
||||
if date_val[1] == 0:
|
||||
value = year
|
||||
else:
|
||||
value = "%s %s" % (self._MONS[date_val[1]],year)
|
||||
else:
|
||||
value = "%d %s %s" % (date_val[0],self._MONS[date_val[1]],year)
|
||||
if date_val[2] < 0:
|
||||
return self._bce_str % value
|
||||
else:
|
||||
return value
|
||||
|
||||
def _display_julian(self,date_val):
|
||||
# Julian date display is the same as Gregorian
|
||||
return self._display_gregorian(date_val)
|
||||
|
||||
def _display_calendar(self,date_val,month_list):
|
||||
year = abs(date_val[2])
|
||||
if self.format == 0 or self.format == 1:
|
||||
return self.display_iso(date_val)
|
||||
else:
|
||||
if date_val[0] == 0:
|
||||
if date_val[1] == 0:
|
||||
value = year
|
||||
else:
|
||||
value = u"%s %d" % (month_list[date_val[1]],year)
|
||||
else:
|
||||
value = u"%s %d, %s" % (month_list[date_val[1]],date_val[0],year)
|
||||
if date_val[2] < 0:
|
||||
return self._bce_str % value
|
||||
else:
|
||||
return value
|
||||
|
||||
def _display_french(self,date_val):
|
||||
year = abs(date_val[2])
|
||||
if self.format == 0 or self.format == 1:
|
||||
return self.display_iso(date_val)
|
||||
else:
|
||||
if date_val[0] == 0:
|
||||
if date_val[1] == 0:
|
||||
value = year
|
||||
else:
|
||||
value = u"%s %d" % (self._french[date_val[1]],year)
|
||||
else:
|
||||
value = u"%d %s %s" % (date_val[0],self._french[date_val[1]],year)
|
||||
if date_val[2] < 0:
|
||||
return self._bce_str % value
|
||||
else:
|
||||
return value
|
||||
|
||||
def _display_hebrew(self,date_val):
|
||||
return self._display_calendar(date_val,self._hebrew)
|
||||
|
||||
def _display_persian(self,date_val):
|
||||
return self._display_calendar(date_val,self._persian)
|
||||
|
||||
def _display_islamic(self,date_val):
|
||||
return self._display_calendar(date_val,self._islamic)
|
||||
|
||||
class DateDisplayEn(DateDisplay):
|
||||
"""
|
||||
English language date display class.
|
||||
"""
|
||||
|
||||
formats = (
|
||||
"YYYY-MM-DD (ISO)", "Numerical", "Month Day, Year",
|
||||
"MON DAY, YEAR", "Day Month Year", "DAY MON YEAR"
|
||||
)
|
||||
|
||||
def __init__(self,format=None):
|
||||
"""
|
||||
Creates a DateDisplay class that converts a Date object to a string
|
||||
of the desired format. The format value must correspond to the format
|
||||
list value (DateDisplay.format[]).
|
||||
"""
|
||||
|
||||
DateDisplay.__init__(self,format)
|
||||
|
||||
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 "%sfrom %s to %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 "%sbetween %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])
|
575
src/DateHandler/DateParser.py
Normal file
575
src/DateHandler/DateParser.py
Normal file
@@ -0,0 +1,575 @@
|
||||
#
|
||||
# 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 parsing class. Serves as the base class for any localized
|
||||
date parsing class. The default, base class provides parsing for
|
||||
English.
|
||||
"""
|
||||
|
||||
__author__ = "Donald N. Allingham"
|
||||
__version__ = "$Revision$"
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# Python modules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
import re
|
||||
import calendar
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# set up logging
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
import logging
|
||||
log = logging.getLogger(".DateParser")
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# GRAMPS modules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
from RelLib import Date, DateError
|
||||
import GrampsLocale
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# Top-level module functions
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
_max_days = [ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ]
|
||||
_leap_days = [ 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ]
|
||||
|
||||
def gregorian_valid(date_tuple):
|
||||
day = date_tuple[0]
|
||||
month = date_tuple[1]
|
||||
valid = True
|
||||
try:
|
||||
if month > 12:
|
||||
valid = False
|
||||
elif calendar.isleap(date_tuple[2]):
|
||||
if day > _leap_days[month-1]:
|
||||
valid = False
|
||||
elif day > _max_days[month-1]:
|
||||
valid = False
|
||||
except:
|
||||
valid = False
|
||||
return valid
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# Parser class
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
class DateParser:
|
||||
"""
|
||||
Converts a text string into a Date object. If the date cannot be
|
||||
converted, the text string is assigned.
|
||||
"""
|
||||
|
||||
_fmt_parse = re.compile(".*%(\S).*%(\S).*%(\S).*")
|
||||
|
||||
# RFC-2822 only uses capitalized English abbreviated names, no locales.
|
||||
_rfc_days = ('Sun','Mon','Tue','Wed','Thu','Fri','Sat')
|
||||
_rfc_mons_to_int = {
|
||||
'Jan' : 1, 'Feb' : 2, 'Mar' : 3, 'Apr' : 4,
|
||||
'May' : 5, 'Jun' : 6, 'Jul' : 7, 'Aug' : 8,
|
||||
'Sep' : 9, 'Oct' : 10, 'Nov' : 11, 'Dec' : 12,
|
||||
}
|
||||
|
||||
month_to_int = GrampsLocale.month_to_int
|
||||
|
||||
# modifiers before the date
|
||||
modifier_to_int = {
|
||||
'before' : Date.MOD_BEFORE, 'bef' : Date.MOD_BEFORE,
|
||||
'bef.' : Date.MOD_BEFORE, 'after' : Date.MOD_AFTER,
|
||||
'aft' : Date.MOD_AFTER, 'aft.' : Date.MOD_AFTER,
|
||||
'about' : Date.MOD_ABOUT, 'abt.' : Date.MOD_ABOUT,
|
||||
'abt' : Date.MOD_ABOUT, 'circa' : Date.MOD_ABOUT,
|
||||
'c.' : Date.MOD_ABOUT, 'around' : Date.MOD_ABOUT,
|
||||
}
|
||||
# in some languages some of above listed modifiers are after the date,
|
||||
# in that case the subclass should put them into this dictionary instead
|
||||
modifier_after_to_int = {}
|
||||
|
||||
hebrew_to_int = {
|
||||
"tishri" : 1, "heshvan" : 2, "kislev" : 3,
|
||||
"tevet" : 4, "shevat" : 5, "adari" : 6,
|
||||
"adarii" : 7, "nisan" : 8, "iyyar" : 9,
|
||||
"sivan" : 10, "tammuz" : 11, "av" : 12,
|
||||
"elul" : 13,
|
||||
}
|
||||
|
||||
french_to_int = {
|
||||
u'vend\xc3\xa9miaire' : 1, 'brumaire' : 2,
|
||||
'frimaire' : 3, u'niv\xc3\xb4se ': 4,
|
||||
u'pluvi\xc3\xb4se' : 5, u'vent\xc3\xb4se' : 6,
|
||||
'germinal' : 7, u'flor\xc3\xa9al' : 8,
|
||||
'prairial' : 9, 'messidor' : 10,
|
||||
'thermidor' : 11, 'fructidor' : 12,
|
||||
'extra' : 13
|
||||
}
|
||||
|
||||
islamic_to_int = {
|
||||
"muharram" : 1, "muharram ul haram" : 1,
|
||||
"safar" : 2, "rabi`al-awwal" : 3,
|
||||
"rabi'l" : 3, "rabi`ul-akhir" : 4,
|
||||
"rabi`ath-thani" : 4, "rabi` ath-thani" : 4,
|
||||
"rabi`al-thaany" : 4, "rabi` al-thaany" : 4,
|
||||
"rabi' ii" : 4, "jumada l-ula" : 5,
|
||||
"jumaada-ul-awwal" : 5, "jumaada i" : 5,
|
||||
"jumada t-tania" : 6, "jumaada-ul-akhir" : 6,
|
||||
"jumaada al-thaany" : 6, "jumaada ii" : 5,
|
||||
"rajab" : 7, "sha`ban" : 8,
|
||||
"sha`aban" : 8, "ramadan" : 9,
|
||||
"ramadhan" : 9, "shawwal" : 10,
|
||||
"dhu l-qa`da" : 11, "dhu qadah" : 11,
|
||||
"thw al-qi`dah" : 11, "dhu l-hijja" : 12,
|
||||
"dhu hijja" : 12, "thw al-hijjah" : 12,
|
||||
}
|
||||
|
||||
persian_to_int = {
|
||||
"Farvardin" : 1, "Ordibehesht" : 2,
|
||||
"Khordad" : 3, "Tir" : 4,
|
||||
"Mordad" : 5, "Shahrivar" : 6,
|
||||
"Mehr" : 7, "Aban" : 8,
|
||||
"Azar" : 9, "Dey" : 10,
|
||||
"Bahman" : 11, "Esfand" : 12,
|
||||
}
|
||||
|
||||
bce = ["BC", "B\.C", "B\.C\.", "BCE", "B\.C\.E", "B\.C\.E"]
|
||||
|
||||
calendar_to_int = {
|
||||
'gregorian' : Date.CAL_GREGORIAN,
|
||||
'g' : Date.CAL_GREGORIAN,
|
||||
'julian' : Date.CAL_JULIAN,
|
||||
'j' : Date.CAL_JULIAN,
|
||||
'hebrew' : Date.CAL_HEBREW,
|
||||
'h' : Date.CAL_HEBREW,
|
||||
'islamic' : Date.CAL_ISLAMIC,
|
||||
'i' : Date.CAL_ISLAMIC,
|
||||
'french' : Date.CAL_FRENCH,
|
||||
'french republican': Date.CAL_FRENCH,
|
||||
'f' : Date.CAL_FRENCH,
|
||||
'persian' : Date.CAL_PERSIAN,
|
||||
'p' : Date.CAL_PERSIAN,
|
||||
}
|
||||
|
||||
quality_to_int = {
|
||||
'estimated' : Date.QUAL_ESTIMATED,
|
||||
'est.' : Date.QUAL_ESTIMATED,
|
||||
'est' : Date.QUAL_ESTIMATED,
|
||||
'calc.' : Date.QUAL_CALCULATED,
|
||||
'calc' : Date.QUAL_CALCULATED,
|
||||
'calculated' : Date.QUAL_CALCULATED,
|
||||
}
|
||||
|
||||
def __init__(self):
|
||||
self.init_strings()
|
||||
self.parser = {
|
||||
Date.CAL_GREGORIAN : self._parse_greg_julian,
|
||||
Date.CAL_JULIAN : self._parse_greg_julian,
|
||||
Date.CAL_FRENCH : self._parse_french,
|
||||
Date.CAL_PERSIAN : self._parse_persian,
|
||||
Date.CAL_HEBREW : self._parse_hebrew,
|
||||
Date.CAL_ISLAMIC : self._parse_islamic,
|
||||
}
|
||||
|
||||
fmt = GrampsLocale.tformat
|
||||
match = self._fmt_parse.match(fmt.lower())
|
||||
if match:
|
||||
self.dmy = (match.groups() == ('d','m','y'))
|
||||
else:
|
||||
self.dmy = True
|
||||
|
||||
def init_strings(self):
|
||||
"""
|
||||
This method compiles regular expression strings for matching dates.
|
||||
|
||||
Most of the re's in most languages can stay as is. span and range
|
||||
most likely will need to change. Whatever change is done, this method
|
||||
may be called first as DateParser.init_strings(self) so that the
|
||||
invariant expresions don't need to be repeteadly coded. All differences
|
||||
can be coded after DateParser.init_strings(self) call, that way they
|
||||
override stuff from this method. See DateParserRU() as an example.
|
||||
"""
|
||||
self._rfc_mon_str = '(' + '|'.join(self._rfc_mons_to_int.keys()) + ')'
|
||||
self._rfc_day_str = '(' + '|'.join(self._rfc_days) + ')'
|
||||
|
||||
self._bce_str = '(' + '|'.join(self.bce) + ')'
|
||||
|
||||
self._qual_str = '(' + '|'.join(
|
||||
[ key.replace('.','\.') for key in self.quality_to_int.keys() ]
|
||||
) + ')'
|
||||
keys = self.modifier_to_int.keys()
|
||||
keys.sort(lambda x, y: cmp(len(y), len(x)))
|
||||
self._mod_str = '(' + '|'.join(
|
||||
[ key.replace('.','\.') for key in keys ]
|
||||
) + ')'
|
||||
self._mod_after_str = '(' + '|'.join(
|
||||
[ key.replace('.','\.') for key in self.modifier_after_to_int.keys() ]
|
||||
) + ')'
|
||||
|
||||
# Need to reverse-sort the keys, so that April matches before Apr does.
|
||||
# Otherwise, 'april 2000' would be matched as 'apr' + garbage ('il 2000')
|
||||
_month_keys = self.month_to_int.keys()
|
||||
_month_keys.sort()
|
||||
_month_keys.reverse()
|
||||
self._mon_str = '(' + '|'.join(_month_keys) + ')'
|
||||
self._jmon_str = '(' + '|'.join(self.hebrew_to_int.keys()) + ')'
|
||||
self._fmon_str = '(' + '|'.join(self.french_to_int.keys()) + ')'
|
||||
self._pmon_str = '(' + '|'.join(self.persian_to_int.keys()) + ')'
|
||||
self._cal_str = '(' + '|'.join(self.calendar_to_int.keys()) + ')'
|
||||
self._imon_str = '(' + '|'.join(self.islamic_to_int.keys()) + ')'
|
||||
|
||||
self._bce_re = re.compile("(.+)\s+%s" % self._bce_str)
|
||||
|
||||
self._cal = re.compile("(.+)\s\(%s\)" % self._cal_str,
|
||||
re.IGNORECASE)
|
||||
self._qual = re.compile("%s\s+(.+)" % self._qual_str,
|
||||
re.IGNORECASE)
|
||||
self._span = re.compile("(from)\s+(?P<start>.+)\s+to\s+(?P<stop>.+)",
|
||||
re.IGNORECASE)
|
||||
self._range = re.compile("(bet|bet.|between)\s+(?P<start>.+)\s+and\s+(?P<stop>.+)",
|
||||
re.IGNORECASE)
|
||||
self._modifier = re.compile('%s\s+(.*)' % self._mod_str,
|
||||
re.IGNORECASE)
|
||||
self._modifier_after = re.compile('(.*)\s+%s' % self._mod_after_str,
|
||||
re.IGNORECASE)
|
||||
self._abt2 = re.compile('<(.*)>',re.IGNORECASE)
|
||||
self._text = re.compile('%s\s+(\d+)?\s*,?\s*((\d+)(/\d+)?)?\s*$' % self._mon_str,
|
||||
re.IGNORECASE)
|
||||
self._text2 = re.compile('(\d+)?\s+?%s\s*((\d+)(/\d+)?)?\s*$' % self._mon_str,
|
||||
re.IGNORECASE)
|
||||
self._jtext = re.compile('%s\s+(\d+)?\s*,?\s*((\d+)(/\d+)?)?\s*$' % self._jmon_str,
|
||||
re.IGNORECASE)
|
||||
self._jtext2 = re.compile('(\d+)?\s+?%s\s*((\d+)(/\d+)?)?\s*$' % self._jmon_str,
|
||||
re.IGNORECASE)
|
||||
self._ftext = re.compile('%s\s+(\d+)?\s*,?\s*((\d+)(/\d+)?)?\s*$' % self._fmon_str,
|
||||
re.IGNORECASE)
|
||||
self._ftext2 = re.compile('(\d+)?\s+?%s\s*((\d+)(/\d+)?)?\s*$' % self._fmon_str,
|
||||
re.IGNORECASE)
|
||||
self._ptext = re.compile('%s\s+(\d+)?\s*,?\s*((\d+)(/\d+)?)?\s*$' % self._pmon_str,
|
||||
re.IGNORECASE)
|
||||
self._ptext2 = re.compile('(\d+)?\s+?%s\s*((\d+)(/\d+)?)?\s*$' % self._pmon_str,
|
||||
re.IGNORECASE)
|
||||
self._itext = re.compile('%s\s+(\d+)?\s*,?\s*((\d+)(/\d+)?)?\s*$' % self._imon_str,
|
||||
re.IGNORECASE)
|
||||
self._itext2 = re.compile('(\d+)?\s+?%s\s*((\d+)(/\d+)?)?\s*$' % self._imon_str,
|
||||
re.IGNORECASE)
|
||||
self._numeric = re.compile("((\d+)[/\.])?((\d+)[/\.])?(\d+)\s*$")
|
||||
self._iso = re.compile("(\d+)-(\d+)-(\d+)\s*$")
|
||||
self._rfc = re.compile("(%s,)?\s+(\d|\d\d)\s+%s\s+(\d+)\s+\d\d:\d\d(:\d\d)?\s+(\+|-)\d\d\d\d"
|
||||
% (self._rfc_day_str,self._rfc_mon_str))
|
||||
|
||||
def _get_int(self,val):
|
||||
"""
|
||||
Converts the string to an integer if the value is not None. If the
|
||||
value is None, a zero is returned
|
||||
"""
|
||||
if val == None:
|
||||
return 0
|
||||
else:
|
||||
return int(val)
|
||||
|
||||
def _parse_hebrew(self,text):
|
||||
return self._parse_calendar(text,self._jtext,self._jtext2,
|
||||
self.hebrew_to_int)
|
||||
|
||||
def _parse_islamic(self,text):
|
||||
return self._parse_calendar(text,self._itext,self._itext2,
|
||||
self.islamic_to_int)
|
||||
|
||||
def _parse_persian(self,text):
|
||||
return self._parse_calendar(text,self._ptext,self._ptext2,
|
||||
self.persian_to_int)
|
||||
|
||||
def _parse_french(self,text):
|
||||
return self._parse_calendar(text,self._ftext,self._ftext2,
|
||||
self.french_to_int)
|
||||
|
||||
def _parse_greg_julian(self,text):
|
||||
return self._parse_calendar(text,self._text,self._text2,
|
||||
self.month_to_int,gregorian_valid)
|
||||
|
||||
def _parse_calendar(self,text,regex1,regex2,mmap,check=None):
|
||||
match = regex1.match(text.lower())
|
||||
if match:
|
||||
groups = match.groups()
|
||||
if groups[0] == None:
|
||||
m = 0
|
||||
else:
|
||||
m = mmap[groups[0].lower()]
|
||||
|
||||
if groups[2] == None:
|
||||
y = self._get_int(groups[1])
|
||||
d = 0
|
||||
s = None
|
||||
else:
|
||||
d = self._get_int(groups[1])
|
||||
y = int(groups[3])
|
||||
s = groups[4] != None
|
||||
value = (d,m,y,s)
|
||||
if check and not check((d,m,y)):
|
||||
value = Date.EMPTY
|
||||
return value
|
||||
|
||||
match = regex2.match(text.lower())
|
||||
if match:
|
||||
groups = match.groups()
|
||||
if groups[1] == None:
|
||||
m = 0
|
||||
else:
|
||||
m = mmap[groups[1].lower()]
|
||||
|
||||
d = self._get_int(groups[0])
|
||||
|
||||
if groups[2] == None:
|
||||
y = 0
|
||||
s = None
|
||||
else:
|
||||
y = int(groups[3])
|
||||
s = groups[4] != None
|
||||
value = (d,m,y,s)
|
||||
if check and not check((d,m,y)):
|
||||
value = Date.EMPTY
|
||||
return value
|
||||
|
||||
return Date.EMPTY
|
||||
|
||||
def _parse_subdate(self,text,subparser=None):
|
||||
"""
|
||||
Converts only the date portion of a date.
|
||||
"""
|
||||
if subparser == None:
|
||||
subparser = self._parse_greg_julian
|
||||
|
||||
if subparser == self._parse_greg_julian:
|
||||
check = gregorian_valid
|
||||
else:
|
||||
check = None
|
||||
|
||||
value = subparser(text)
|
||||
if value != Date.EMPTY:
|
||||
return value
|
||||
|
||||
match = self._iso.match(text)
|
||||
if match:
|
||||
groups = match.groups()
|
||||
y = self._get_int(groups[0])
|
||||
m = self._get_int(groups[1])
|
||||
d = self._get_int(groups[2])
|
||||
if gregorian_valid((d,m,y)):
|
||||
return (d,m,y,False)
|
||||
else:
|
||||
return Date.EMPTY
|
||||
|
||||
match = self._rfc.match(text)
|
||||
if match:
|
||||
groups = match.groups()
|
||||
d = self._get_int(groups[2])
|
||||
m = self._rfc_mons_to_int[groups[3]]
|
||||
y = self._get_int(groups[4])
|
||||
if gregorian_valid((d,m,y)):
|
||||
return (d,m,y,False)
|
||||
else:
|
||||
return Date.EMPTY
|
||||
|
||||
match = self._numeric.match(text)
|
||||
if match:
|
||||
groups = match.groups()
|
||||
if self.dmy:
|
||||
m = self._get_int(groups[3])
|
||||
d = self._get_int(groups[1])
|
||||
else:
|
||||
m = self._get_int(groups[1])
|
||||
d = self._get_int(groups[3])
|
||||
y = self._get_int(groups[4])
|
||||
value = (d,m,y,False)
|
||||
if check and not check((d,m,y)):
|
||||
value = Date.EMPTY
|
||||
return value
|
||||
|
||||
return Date.EMPTY
|
||||
|
||||
def match_calendar(self,text,cal):
|
||||
"""
|
||||
Try parsing calendar.
|
||||
|
||||
Return calendar index and the remainder of text.
|
||||
"""
|
||||
match = self._cal.match(text)
|
||||
if match:
|
||||
grps = match.groups()
|
||||
cal = self.calendar_to_int[grps[1].lower()]
|
||||
text = grps[0]
|
||||
return (text,cal)
|
||||
|
||||
def match_quality(self,text,qual):
|
||||
"""
|
||||
Try matching quality.
|
||||
|
||||
Return quality index and the remainder of text.
|
||||
"""
|
||||
match = self._qual.match(text)
|
||||
if match:
|
||||
grps = match.groups()
|
||||
qual = self.quality_to_int[grps[0].lower()]
|
||||
text = grps[1]
|
||||
return (text,qual)
|
||||
|
||||
def match_span(self,text,cal,qual,date):
|
||||
"""
|
||||
Try matching span date.
|
||||
|
||||
On success, set the date and return 1. On failure return 0.
|
||||
"""
|
||||
match = self._span.match(text)
|
||||
if match:
|
||||
text_parser = self.parser[cal]
|
||||
start = self._parse_subdate(match.group('start'),text_parser)
|
||||
stop = self._parse_subdate(match.group('stop'),text_parser)
|
||||
date.set(qual,Date.MOD_SPAN,cal,start + stop)
|
||||
return 1
|
||||
return 0
|
||||
|
||||
def match_range(self,text,cal,qual,date):
|
||||
"""
|
||||
Try matching range date.
|
||||
|
||||
On success, set the date and return 1. On failure return 0.
|
||||
"""
|
||||
match = self._range.match(text)
|
||||
if match:
|
||||
text_parser = self.parser[cal]
|
||||
start = self._parse_subdate(match.group('start'),text_parser)
|
||||
stop = self._parse_subdate(match.group('stop'),text_parser)
|
||||
date.set(qual,Date.MOD_RANGE,cal,start + stop)
|
||||
return 1
|
||||
return 0
|
||||
|
||||
def match_bce(self,text):
|
||||
"""
|
||||
Try matching BCE qualifier.
|
||||
|
||||
Return BCE (True/False) and the remainder of text.
|
||||
"""
|
||||
match = self._bce_re.match(text)
|
||||
bc = False
|
||||
if match:
|
||||
text = match.groups()[0]
|
||||
bc = True
|
||||
return (text,bc)
|
||||
|
||||
def match_modifier(self,text,cal,qual,bc,date):
|
||||
"""
|
||||
Try matching date with modifier.
|
||||
|
||||
On success, set the date and return 1. On failure return 0.
|
||||
"""
|
||||
# modifiers before the date
|
||||
match = self._modifier.match(text)
|
||||
if match:
|
||||
grps = match.groups()
|
||||
start = self._parse_subdate(grps[1])
|
||||
mod = self.modifier_to_int.get(grps[0].lower(),Date.MOD_NONE)
|
||||
if bc:
|
||||
date.set(qual,mod,cal,self.invert_year(start))
|
||||
else:
|
||||
date.set(qual,mod,cal,start)
|
||||
return True
|
||||
# modifiers after the date
|
||||
if self.modifier_after_to_int:
|
||||
match = self._modifier_after.match(text)
|
||||
if match:
|
||||
grps = match.groups()
|
||||
start = self._parse_subdate(grps[0])
|
||||
mod = self.modifier_after_to_int.get(grps[1].lower(),
|
||||
Date.MOD_NONE)
|
||||
if bc:
|
||||
date.set(qual,mod,cal,self.invert_year(start))
|
||||
else:
|
||||
date.set(qual,mod,cal,start)
|
||||
return True
|
||||
match = self._abt2.match(text)
|
||||
if match:
|
||||
grps = match.groups()
|
||||
start = self._parse_subdate(grps[0])
|
||||
mod = Date.MOD_ABOUT
|
||||
if bc:
|
||||
date.set(qual,mod,cal,self.invert_year(start))
|
||||
else:
|
||||
date.set(qual,mod,cal,start)
|
||||
return True
|
||||
return False
|
||||
|
||||
def set_date(self,date,text):
|
||||
"""
|
||||
Parses the text and sets the date according to the parsing.
|
||||
"""
|
||||
|
||||
|
||||
date.set_text_value(text)
|
||||
qual = Date.QUAL_NONE
|
||||
cal = Date.CAL_GREGORIAN
|
||||
|
||||
(text,cal) = self.match_calendar(text,cal)
|
||||
(text,qual) = self.match_quality(text,qual)
|
||||
|
||||
if self.match_span(text,cal,qual,date):
|
||||
return
|
||||
if self.match_range(text,cal,qual,date):
|
||||
return
|
||||
|
||||
(text,bc) = self.match_bce(text)
|
||||
if self.match_modifier(text,cal,qual,bc,date):
|
||||
return
|
||||
|
||||
try:
|
||||
subdate = self._parse_subdate(text,self.parser[cal])
|
||||
if subdate == Date.EMPTY and text != "":
|
||||
date.set_as_text(text)
|
||||
return
|
||||
except:
|
||||
date.set_as_text(text)
|
||||
return
|
||||
|
||||
if bc:
|
||||
date.set(qual,Date.MOD_NONE,cal,self.invert_year(subdate))
|
||||
else:
|
||||
date.set(qual,Date.MOD_NONE,cal,subdate)
|
||||
|
||||
def invert_year(self,subdate):
|
||||
return (subdate[0],subdate[1],-subdate[2],subdate[3])
|
||||
|
||||
def parse(self,text):
|
||||
"""
|
||||
Parses the text, returning a Date object.
|
||||
"""
|
||||
new_date = Date()
|
||||
try:
|
||||
self.set_date(new_date,text)
|
||||
except DateError:
|
||||
new_date.set_as_text(text)
|
||||
return new_date
|
228
src/DateHandler/Date_de.py
Normal file
228
src/DateHandler/Date_de.py
Normal file
@@ -0,0 +1,228 @@
|
||||
# -*- 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$
|
||||
|
||||
"""
|
||||
German-specific classes for parsing and displaying dates.
|
||||
"""
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# Python modules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
import re
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# GRAMPS modules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
from RelLib import Date
|
||||
from DateParser import DateParser
|
||||
from DateDisplay import DateDisplay
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# French parser
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
class DateParserDE(DateParser):
|
||||
|
||||
month_to_int = DateParser.month_to_int
|
||||
# Always add german and austrian name variants no matter what the current locale is
|
||||
month_to_int[u"januar"] = 1
|
||||
month_to_int[u"jan"] = 1
|
||||
month_to_int[u"jänner"] = 1
|
||||
month_to_int[u"jän"] = 1
|
||||
# Add other common latin, local and historical variants
|
||||
month_to_int[u"januaris"] = 1
|
||||
month_to_int[u"jenner"] = 1
|
||||
month_to_int[u"feber"] = 2
|
||||
month_to_int[u"februaris"] = 2
|
||||
month_to_int[u"merz"] = 3
|
||||
month_to_int[u"aprilis"] = 4
|
||||
month_to_int[u"maius"] = 5
|
||||
month_to_int[u"junius"] = 6
|
||||
month_to_int[u"julius"] = 7
|
||||
month_to_int[u"augst"] = 8
|
||||
month_to_int[u"7ber"] = 9
|
||||
month_to_int[u"7bris"] = 9
|
||||
month_to_int[u"8ber"] = 10
|
||||
month_to_int[u"8bris"] = 10
|
||||
month_to_int[u"9ber"] = 11
|
||||
month_to_int[u"9bris"] = 11
|
||||
month_to_int[u"10ber"] = 12
|
||||
month_to_int[u"10bris"] = 12
|
||||
month_to_int[u"xber"] = 12
|
||||
month_to_int[u"xbris"] = 12
|
||||
|
||||
modifier_to_int = {
|
||||
u'vor' : Date.MOD_BEFORE,
|
||||
u'nach' : Date.MOD_AFTER,
|
||||
u'gegen' : Date.MOD_ABOUT,
|
||||
u'um' : Date.MOD_ABOUT,
|
||||
u'etwa' : Date.MOD_ABOUT,
|
||||
u'circa' : Date.MOD_ABOUT,
|
||||
u'ca.' : Date.MOD_ABOUT,
|
||||
}
|
||||
|
||||
calendar_to_int = {
|
||||
u'Gregorianisch' : Date.CAL_GREGORIAN,
|
||||
u'Greg.' : Date.CAL_GREGORIAN,
|
||||
u'Julianisch' : Date.CAL_JULIAN,
|
||||
u'Jul.' : Date.CAL_JULIAN,
|
||||
u'Hebräisch' : Date.CAL_HEBREW,
|
||||
u'Hebr.' : Date.CAL_HEBREW,
|
||||
u'Islamisch' : Date.CAL_ISLAMIC,
|
||||
u'Isl.' : Date.CAL_ISLAMIC,
|
||||
u'Französisch Republikanisch': Date.CAL_FRENCH,
|
||||
u'Franz.' : Date.CAL_FRENCH,
|
||||
u'Persisch' : Date.CAL_PERSIAN,
|
||||
}
|
||||
|
||||
quality_to_int = {
|
||||
u'geschätzt' : Date.QUAL_ESTIMATED,
|
||||
u'gesch.' : Date.QUAL_ESTIMATED,
|
||||
u'errechnet' : Date.QUAL_CALCULATED,
|
||||
u'berechnet' : Date.QUAL_CALCULATED,
|
||||
u'ber.' : Date.QUAL_CALCULATED,
|
||||
}
|
||||
|
||||
bce = DateParser.bce + ["vor (unserer|der) Zeit(rechnung)?", "v\. (u|d)\. Z\.", "vor Christus", "vor Christi Geburt", "v\. Chr\."]
|
||||
|
||||
def init_strings(self):
|
||||
DateParser.init_strings(self)
|
||||
self._span = re.compile("(von|vom)\s+(?P<start>.+)\s+(bis)\s+(?P<stop>.+)",re.IGNORECASE)
|
||||
self._range = re.compile("zwischen\s+(?P<start>.+)\s+und\s+(?P<stop>.+)", re.IGNORECASE)
|
||||
self._text2 = re.compile('(\d+)?.?\s+?%s\s*((\d+)(/\d+)?)?' % self._mon_str,
|
||||
re.IGNORECASE)
|
||||
self._jtext2= re.compile('(\d+)?.?\s+?%s\s*((\d+)(/\d+)?)?' % self._jmon_str,
|
||||
re.IGNORECASE)
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# French display
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
class DateDisplayDE(DateDisplay):
|
||||
|
||||
calendar = (
|
||||
"", u" (Julianisch)", u" (Hebräisch)",
|
||||
u" (Französisch Republikanisch)", u" (Persisch)", u" (Islamisch)"
|
||||
)
|
||||
|
||||
_mod_str = ("",u"vor ",u"nach ",u"etwa ","","","")
|
||||
|
||||
_qual_str = ("",u"geschätzt ",u"errechnet ")
|
||||
|
||||
_bce_str = "%s v. u. Z."
|
||||
|
||||
formats = (
|
||||
"JJJJ-MM-DD (ISO)", "Numerisch", "Monat Tag Jahr",
|
||||
"MONAT Tag Jahr", "Tag. Monat Jahr", "Tag. MONAT Jahr"
|
||||
)
|
||||
|
||||
def _display_gregorian(self,date_val):
|
||||
year = self._slash_year(date_val[2],date_val[3])
|
||||
if self.format == 0:
|
||||
value = self.display_iso(date_val)
|
||||
elif self.format == 1:
|
||||
if date_val[0] == 0 and date_val[1] == 0:
|
||||
value = str(date_val[2])
|
||||
else:
|
||||
value = self._tformat.replace('%m',str(date_val[1]))
|
||||
value = value.replace('%d',str(date_val[0]))
|
||||
value = value.replace('%Y',str(date_val[2]))
|
||||
elif self.format == 2:
|
||||
# Month Day, Year
|
||||
if date_val[0] == 0:
|
||||
if date_val[1] == 0:
|
||||
value = year
|
||||
else:
|
||||
value = "%s %s" % (self._months[date_val[1]],year)
|
||||
else:
|
||||
value = "%s %d, %s" % (self._months[date_val[1]],date_val[0],year)
|
||||
elif self.format == 3:
|
||||
# MON Day, Year
|
||||
if date_val[0] == 0:
|
||||
if date_val[1] == 0:
|
||||
value = year
|
||||
else:
|
||||
value = "%s %s" % (self._MONS[date_val[1]],year)
|
||||
else:
|
||||
value = "%s %d, %s" % (self._MONS[date_val[1]],date_val[0],year)
|
||||
elif self.format == 4:
|
||||
# Day Month Year
|
||||
if date_val[0] == 0:
|
||||
if date_val[1] == 0:
|
||||
value = year
|
||||
else:
|
||||
value = "%s %s" % (self._months[date_val[1]],year)
|
||||
else:
|
||||
value = "%d. %s %s" % (date_val[0],self._months[date_val[1]],year)
|
||||
else:
|
||||
# Day MON Year
|
||||
if date_val[0] == 0:
|
||||
if date_val[1] == 0:
|
||||
value = year
|
||||
else:
|
||||
value = "%s %s" % (self._MONS[date_val[1]],year)
|
||||
else:
|
||||
value = "%d. %s %s" % (date_val[0],self._MONS[date_val[1]],year)
|
||||
return value
|
||||
|
||||
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'von',d1,u'bis',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 und %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','de_AT','de_CH',
|
||||
'de_LI','de_LU','de_BE','de'),DateParserDE, DateDisplayDE)
|
162
src/DateHandler/Date_es.py
Normal file
162
src/DateHandler/Date_es.py
Normal file
@@ -0,0 +1,162 @@
|
||||
# -*- 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$
|
||||
|
||||
"""
|
||||
Spanish-specific classes for parsing and displaying dates.
|
||||
"""
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# Python modules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
import re
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# GRAMPS modules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
from RelLib import Date
|
||||
from DateParser import DateParser
|
||||
from DateDisplay import DateDisplay
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# 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,
|
||||
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,
|
||||
}
|
||||
|
||||
calendar_to_int = {
|
||||
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,
|
||||
}
|
||||
|
||||
quality_to_int = {
|
||||
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,
|
||||
}
|
||||
|
||||
def init_strings(self):
|
||||
DateParser.init_strings(self)
|
||||
_span_1 = [u'de']
|
||||
_span_2 = [u'a']
|
||||
_range_1 = [u'ent.',u'ent',u'entre']
|
||||
_range_2 = [u'y']
|
||||
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)
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# Spanish display
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
class DateDisplayES(DateDisplay):
|
||||
|
||||
calendar = (
|
||||
"", u" (Juliano)", u" (Hebreo)",
|
||||
u" (Revolucionario)", u" (Persa)", u" (Islámico)"
|
||||
)
|
||||
|
||||
_mod_str = ("",u"antes de ",u"después de ",u"hacia ","","","")
|
||||
|
||||
_qual_str = ("","estimado ","calculado ")
|
||||
|
||||
formats = (
|
||||
"AAAA-MM-DD (ISO)", "Numérica", "Mes Día, Año",
|
||||
"MES Día, Año", "Día Mes, Año", "Día MES, Año"
|
||||
)
|
||||
|
||||
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'a',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 "%s%s %s %s %s%s" % (qual_str,u'entre',d1,u'y',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(('es_ES','es','spanish'),DateParserES, DateDisplayES)
|
185
src/DateHandler/Date_fi.py
Normal file
185
src/DateHandler/Date_fi.py
Normal file
@@ -0,0 +1,185 @@
|
||||
# -*- 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$
|
||||
|
||||
"""
|
||||
Finnish-specific classes for parsing and displaying dates.
|
||||
"""
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# Python modules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
import re
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# GRAMPS modules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
from RelLib import Date
|
||||
from DateParser import DateParser
|
||||
from DateDisplay import DateDisplay
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# Finnish parser
|
||||
#
|
||||
# This handles only dates where days and months are given as numeric, as:
|
||||
# - That's how they are normally used in Finland
|
||||
# - Parsing Finnish is much more complicated than English
|
||||
#-------------------------------------------------------------------------
|
||||
class DateParserFI(DateParser):
|
||||
|
||||
# NOTE: these need to be in lower case because the "key" comparison
|
||||
# is done as lower case. In the display method correct capitalization
|
||||
# can be used.
|
||||
|
||||
modifier_to_int = {
|
||||
# examples:
|
||||
# - ennen 1.1.2005
|
||||
# - noin 1.1.2005
|
||||
u'ennen' : Date.MOD_BEFORE,
|
||||
u'e.' : Date.MOD_BEFORE,
|
||||
u'noin' : Date.MOD_ABOUT,
|
||||
u'n.' : Date.MOD_ABOUT,
|
||||
}
|
||||
modifier_after_to_int = {
|
||||
# examples:
|
||||
# - 1.1.2005 jälkeen
|
||||
u'jälkeen' : Date.MOD_AFTER,
|
||||
u'j.' : Date.MOD_AFTER,
|
||||
}
|
||||
|
||||
bce = ["ekr", "ekr\."]
|
||||
|
||||
calendar_to_int = {
|
||||
u'gregoriaaninen' : Date.CAL_GREGORIAN,
|
||||
u'greg.' : Date.CAL_GREGORIAN,
|
||||
u'juliaaninen' : Date.CAL_JULIAN,
|
||||
u'jul.' : Date.CAL_JULIAN,
|
||||
u'heprealainen' : Date.CAL_HEBREW,
|
||||
u'hepr.' : Date.CAL_HEBREW,
|
||||
u'islamilainen' : Date.CAL_ISLAMIC,
|
||||
u'isl.' : Date.CAL_ISLAMIC,
|
||||
u'ranskan vallankumouksen aikainen': Date.CAL_FRENCH,
|
||||
u'ranskan v.' : Date.CAL_FRENCH,
|
||||
u'persialainen' : Date.CAL_PERSIAN,
|
||||
u'pers.' : Date.CAL_PERSIAN,
|
||||
}
|
||||
|
||||
quality_to_int = {
|
||||
u'arviolta' : Date.QUAL_ESTIMATED,
|
||||
u'arv.' : Date.QUAL_ESTIMATED,
|
||||
u'laskettuna' : Date.QUAL_CALCULATED,
|
||||
u'lask.' : Date.QUAL_CALCULATED,
|
||||
}
|
||||
|
||||
def init_strings(self):
|
||||
DateParser.init_strings(self)
|
||||
# date, whitespace
|
||||
self._span = re.compile("(?P<start>.+)\s+(-)\s+(?P<stop>.+)",
|
||||
re.IGNORECASE)
|
||||
self._range = re.compile("(vuosien\s*)?(?P<start>.+)\s+ja\s+(?P<stop>.+)\s+välillä",
|
||||
re.IGNORECASE)
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# Finnish display
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
class DateDisplayFI(DateDisplay):
|
||||
|
||||
calendar = ("",
|
||||
u"(Juliaaninen)",
|
||||
u"(Heprealainen)",
|
||||
u"(Ranskan v.)",
|
||||
u"(Persialainen)",
|
||||
u"(Islamilainen)")
|
||||
|
||||
_qual_str = ("", "arviolta", "laskettuna")
|
||||
|
||||
_bce_str = "%s ekr."
|
||||
|
||||
formats = (
|
||||
"VVVV-KK-PP (ISO)",
|
||||
"PP.KK.VVVV"
|
||||
)
|
||||
|
||||
def display(self,date):
|
||||
"""
|
||||
Returns a text string representing the date.
|
||||
"""
|
||||
mod = date.get_modifier()
|
||||
qual = date.get_quality()
|
||||
cal = date.get_calendar()
|
||||
start = date.get_start_date()
|
||||
|
||||
if mod == Date.MOD_TEXTONLY:
|
||||
return date.get_text()
|
||||
if start == Date.EMPTY:
|
||||
return ""
|
||||
|
||||
# select numerical date format
|
||||
self.format = 1
|
||||
|
||||
if mod == Date.MOD_SPAN:
|
||||
d1 = self.display_cal[cal](start)
|
||||
d2 = self.display_cal[cal](date.get_stop_date())
|
||||
text = "%s - %s" % (d1, d2)
|
||||
elif mod == Date.MOD_RANGE:
|
||||
stop = date.get_stop_date()
|
||||
if start[0] == 0 and start[1] == 0 and stop[0] == 0 and stop[1] == 0:
|
||||
d1 = self.display_cal[cal](start)
|
||||
d2 = self.display_cal[cal](stop)
|
||||
text = "vuosien %s ja %s välillä" % (d1, d2)
|
||||
else:
|
||||
d1 = self.display_cal[cal](start)
|
||||
d2 = self.display_cal[cal](stop)
|
||||
text = "%s ja %s välillä" % (d1, d2)
|
||||
else:
|
||||
text = self.display_cal[date.get_calendar()](start)
|
||||
if mod == Date.MOD_AFTER:
|
||||
text = text + " jälkeen"
|
||||
elif mod == Date.MOD_ABOUT:
|
||||
text = "noin " + text
|
||||
elif mod == Date.MOD_BEFORE:
|
||||
text = "ennen " + text
|
||||
|
||||
if qual:
|
||||
# prepend quality
|
||||
text = "%s %s" % (self._qual_str[qual], text)
|
||||
if cal:
|
||||
# append calendar type
|
||||
text = "%s %s" % (text, self.calendar[cal])
|
||||
|
||||
return text
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# Register classes
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
from DateHandler import register_datehandler
|
||||
register_datehandler(('fi_FI','fi','finnish'), DateParserFI, DateDisplayFI)
|
||||
|
246
src/DateHandler/Date_fr.py
Normal file
246
src/DateHandler/Date_fr.py
Normal file
@@ -0,0 +1,246 @@
|
||||
# -*- 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$
|
||||
|
||||
"""
|
||||
French-specific classes for parsing and displaying dates.
|
||||
"""
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# Python modules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
import re
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# GRAMPS modules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
from RelLib import Date
|
||||
from DateParser import DateParser
|
||||
from DateDisplay import DateDisplay
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# French parser
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
class DateParserFR(DateParser):
|
||||
|
||||
month_to_int = DateParser.month_to_int
|
||||
# Add common latin, local and historical variants (now only on east france)
|
||||
month_to_int[u"januaris"] = 1
|
||||
month_to_int[u"janer"] = 1
|
||||
month_to_int[u"jenner"] = 1
|
||||
month_to_int[u"hartmonat"] = 1
|
||||
month_to_int[u"hartung"] = 1
|
||||
month_to_int[u"eismond"] = 1
|
||||
month_to_int[u"bluviose"] = 1
|
||||
month_to_int[u"februaris"] = 2
|
||||
month_to_int[u"hornung"] = 2
|
||||
month_to_int[u"wintermonat"] = 2
|
||||
month_to_int[u"taumond"] = 2
|
||||
month_to_int[u"narrenmond"] = 2
|
||||
month_to_int[u"vendose"] = 2
|
||||
month_to_int[u"martius"] = 3
|
||||
month_to_int[u"aprilis"] = 4
|
||||
month_to_int[u"wiesenmonat"] = 5
|
||||
month_to_int[u"maius"] = 5
|
||||
month_to_int[u"junius"] = 6
|
||||
month_to_int[u"julius"] = 7
|
||||
month_to_int[u"augustus"] = 8
|
||||
month_to_int[u"september"] = 9
|
||||
month_to_int[u"7bre"] = 9
|
||||
month_to_int[u"7bris"] = 9
|
||||
month_to_int[u"october"] = 10
|
||||
month_to_int[u"8bre"] = 10
|
||||
month_to_int[u"8bris"] = 10
|
||||
month_to_int[u"nebelmonat"] = 10
|
||||
month_to_int[u"november"] = 11
|
||||
month_to_int[u"9bre"] = 11
|
||||
month_to_int[u"9bris"] = 11
|
||||
month_to_int[u"december"] = 12
|
||||
month_to_int[u"10bre"] = 12
|
||||
month_to_int[u"10bris"] = 12
|
||||
month_to_int[u"xbre"] = 12
|
||||
month_to_int[u"xbris"] = 12
|
||||
|
||||
modifier_to_int = {
|
||||
u'avant' : Date.MOD_BEFORE,
|
||||
u'av.' : Date.MOD_BEFORE,
|
||||
u'av' : Date.MOD_BEFORE,
|
||||
u'après' : Date.MOD_AFTER,
|
||||
u'ap.' : Date.MOD_AFTER,
|
||||
u'ap' : Date.MOD_AFTER,
|
||||
u'env.' : Date.MOD_ABOUT,
|
||||
u'env' : Date.MOD_ABOUT,
|
||||
u'environ': Date.MOD_ABOUT,
|
||||
u'circa' : Date.MOD_ABOUT,
|
||||
u'c.' : Date.MOD_ABOUT,
|
||||
u'ca' : Date.MOD_ABOUT,
|
||||
u'ca.' : Date.MOD_ABOUT,
|
||||
u'vers' : Date.MOD_ABOUT,
|
||||
u'~' : Date.MOD_ABOUT,
|
||||
}
|
||||
|
||||
calendar_to_int = {
|
||||
u'grégorien' : Date.CAL_GREGORIAN,
|
||||
u'g' : Date.CAL_GREGORIAN,
|
||||
u'julien' : Date.CAL_JULIAN,
|
||||
u'j' : Date.CAL_JULIAN,
|
||||
u'hébreu' : Date.CAL_HEBREW,
|
||||
u'h' : Date.CAL_HEBREW,
|
||||
u'islamique' : Date.CAL_ISLAMIC,
|
||||
u'i' : Date.CAL_ISLAMIC,
|
||||
u'révolutionnaire' : Date.CAL_FRENCH,
|
||||
u'r' : Date.CAL_FRENCH,
|
||||
u'perse' : Date.CAL_PERSIAN,
|
||||
u'p' : Date.CAL_PERSIAN,
|
||||
}
|
||||
|
||||
quality_to_int = {
|
||||
u'estimée' : Date.QUAL_ESTIMATED,
|
||||
u'est.' : Date.QUAL_ESTIMATED,
|
||||
u'est' : Date.QUAL_ESTIMATED,
|
||||
u'calculée' : Date.QUAL_CALCULATED,
|
||||
u'calc.' : Date.QUAL_CALCULATED,
|
||||
u'calc' : Date.QUAL_CALCULATED,
|
||||
u'comptée' : Date.QUAL_CALCULATED,
|
||||
u'compt' : Date.QUAL_CALCULATED,
|
||||
u'compt.' : Date.QUAL_CALCULATED,
|
||||
}
|
||||
|
||||
def init_strings(self):
|
||||
DateParser.init_strings(self)
|
||||
self._span = re.compile("(de)\s+(?P<start>.+)\s+(à)\s+(?P<stop>.+)",re.IGNORECASE)
|
||||
self._range = re.compile("(entre|ent|ent.)\s+(?P<start>.+)\s+(et)\s+(?P<stop>.+)",re.IGNORECASE)
|
||||
self._text2 =re.compile('(\d+)?.?\s+?%s\s*((\d+)(/\d+)?)?' % self._mon_str,
|
||||
re.IGNORECASE)
|
||||
self._jtext2 =re.compile('(\d+)?.?\s+?%s\s*((\d+)(/\d+)?)?' % self._mon_str,
|
||||
re.IGNORECASE)
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# French display
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
class DateDisplayFR(DateDisplay):
|
||||
|
||||
calendar = (
|
||||
"", u" (Julien)", u" (Hébreu)",
|
||||
u" (Révolutionnaire)", u" (Perse)", u" (Islamique)"
|
||||
)
|
||||
|
||||
_mod_str = ("",u"avant ",u"après ",u"vers ","","","")
|
||||
|
||||
_qual_str = ("","estimée ","calculée ","")
|
||||
|
||||
formats = (
|
||||
"AAAA-MM-DD (ISO)", "Numérique", "Mois Jour, Année",
|
||||
"MOI Jour, Année", "Jour Mois, Année", "Jour MOIS Année"
|
||||
)
|
||||
|
||||
def _display_gregorian(self,date_val):
|
||||
year = self._slash_year(date_val[2],date_val[3])
|
||||
if self.format == 0:
|
||||
value = self.display_iso(date_val)
|
||||
elif self.format == 1:
|
||||
if date_val[0] == 0 and date_val[1] == 0:
|
||||
value = str(date_val[2])
|
||||
else:
|
||||
value = self._tformat.replace('%m',str(date_val[1]))
|
||||
value = value.replace('%d',str(date_val[0]))
|
||||
value = value.replace('%Y',str(date_val[2]))
|
||||
elif self.format == 2:
|
||||
# Month Day, Year
|
||||
if date_val[0] == 0:
|
||||
if date_val[1] == 0:
|
||||
value = year
|
||||
else:
|
||||
value = "%s %s" % (self._months[date_val[1]],year)
|
||||
else:
|
||||
value = "%s %d, %s" % (self._months[date_val[1]],date_val[0],year)
|
||||
elif self.format == 3:
|
||||
# MON Day, Year
|
||||
if date_val[0] == 0:
|
||||
if date_val[1] == 0:
|
||||
value = year
|
||||
else:
|
||||
value = "%s %s" % (self._MONS[date_val[1]],year)
|
||||
else:
|
||||
value = "%s %d, %s" % (self._MONS[date_val[1]],date_val[0],year)
|
||||
elif self.format == 4:
|
||||
# Day Month Year
|
||||
if date_val[0] == 0:
|
||||
if date_val[1] == 0:
|
||||
value = year
|
||||
else:
|
||||
value = "%s %s" % (self._months[date_val[1]],year)
|
||||
else:
|
||||
value = "%d. %s %s" % (date_val[0],self._months[date_val[1]],year)
|
||||
else:
|
||||
# Day MON Year
|
||||
if date_val[0] == 0:
|
||||
if date_val[1] == 0:
|
||||
value = year
|
||||
else:
|
||||
value = "%s %s" % (self._MONS[date_val[1]],year)
|
||||
else:
|
||||
value = "%d. %s %s" % (date_val[0],self._MONS[date_val[1]],year)
|
||||
return value
|
||||
|
||||
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 "%s%s %s %s %s%s" % (qual_str,u'entre',d1,u'et',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(('fr_FR','fr','french','fr_CA','fr_BE','fr_CH'),DateParserFR,DateDisplayFR)
|
149
src/DateHandler/Date_lt.py
Normal file
149
src/DateHandler/Date_lt.py
Normal file
@@ -0,0 +1,149 @@
|
||||
# -*- 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$
|
||||
|
||||
"""
|
||||
Lithuanian-specific classes for parsing and displaying dates.
|
||||
"""
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# Python modules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
import re
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# GRAMPS modules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
import Date
|
||||
from DateParser import DateParser
|
||||
from DateDisplay import DateDisplay
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# Lithuanian parser
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
class DateParserLT(DateParser):
|
||||
|
||||
modifier_to_int = {
|
||||
u'prieš' : Date.MOD_BEFORE,
|
||||
u'po' : Date.MOD_AFTER,
|
||||
u'apie' : Date.MOD_ABOUT,
|
||||
}
|
||||
|
||||
calendar_to_int = {
|
||||
u'Grigaliaus' : Date.CAL_GREGORIAN,
|
||||
u'g' : Date.CAL_GREGORIAN,
|
||||
u'Julijaus' : Date.CAL_JULIAN,
|
||||
u'j' : Date.CAL_JULIAN,
|
||||
u'Hebrajų' : Date.CAL_HEBREW,
|
||||
u'h' : Date.CAL_HEBREW,
|
||||
u'Islamo' : Date.CAL_ISLAMIC,
|
||||
u'i' : Date.CAL_ISLAMIC,
|
||||
u'Prancuzų Respublikos': Date.CAL_FRENCH,
|
||||
u'r' : Date.CAL_FRENCH,
|
||||
u'Persų' : Date.CAL_PERSIAN,
|
||||
u'p' : Date.CAL_PERSIAN,
|
||||
}
|
||||
|
||||
quality_to_int = {
|
||||
u'apytikriai' : Date.QUAL_ESTIMATED,
|
||||
u'apskaičiuota' : Date.QUAL_CALCULATED,
|
||||
}
|
||||
|
||||
def init_strings(self):
|
||||
DateParser.init_strings(self)
|
||||
_span_1 = [u'nuo']
|
||||
_span_2 = [u'iki']
|
||||
_range_1 = [u'tarp']
|
||||
_range_2 = [u'ir']
|
||||
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)
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# Lithuanian displayer
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
class DateDisplayLT(DateDisplay):
|
||||
|
||||
calendar = (
|
||||
"", u" (Julijaus)",
|
||||
u" (Hebrajų)",
|
||||
u" (Prancuzų Respublikos)",
|
||||
u" (Persų)",
|
||||
u" (Islamo)"
|
||||
)
|
||||
|
||||
_mod_str = ("",u"iki ",
|
||||
u"po ",
|
||||
u"apie ","","","")
|
||||
|
||||
_qual_str = ("","apytikriai ","apskaičiuota ")
|
||||
|
||||
formats = (
|
||||
"YYYY-MM-DD (ISO)", "Skaitmeninis", "Mėnuo Diena, Metai",
|
||||
"Mėn DD, YYYY", "Diena Mėnuo Metai", "DD Mėn YYYY"
|
||||
)
|
||||
|
||||
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" % (qual_str,d1,u'iki',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 "%s%s %s %s %s%s" % (qual_str,u'tarp',d1,u'ir',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(('lt_LT','lt','lithuanian'),DateParserLT, DateDisplayLT)
|
242
src/DateHandler/Date_nl.py
Normal file
242
src/DateHandler/Date_nl.py
Normal file
@@ -0,0 +1,242 @@
|
||||
# -*- 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$
|
||||
|
||||
# Written by Benny Malengier
|
||||
# Last change 2005/12/05:
|
||||
# Correspond naming of dates with actual action, so for abbreviation
|
||||
# of month given by mnd. not MAAND
|
||||
# Also less possibilities
|
||||
|
||||
"""
|
||||
Dutch-specific classes for parsing and displaying dates.
|
||||
"""
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# Python modules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
import re
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# GRAMPS modules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
from RelLib import Date
|
||||
from DateParser import DateParser
|
||||
from DateDisplay import DateDisplay
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# Dutch parser
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
class DateParserNL(DateParser):
|
||||
|
||||
month_to_int = DateParser.month_to_int
|
||||
# Always add dutch and flemish name variants
|
||||
# no matter what the current locale is
|
||||
month_to_int[u"januari"] = 1
|
||||
month_to_int[u"jan"] = 1
|
||||
# Add other common latin, local and historical variants
|
||||
month_to_int[u"januaris"] = 1
|
||||
month_to_int[u"feber"] = 2
|
||||
month_to_int[u"februaris"] = 2
|
||||
month_to_int[u"merz"] = 3
|
||||
month_to_int[u"aprilis"] = 4
|
||||
month_to_int[u"maius"] = 5
|
||||
month_to_int[u"junius"] = 6
|
||||
month_to_int[u"julius"] = 7
|
||||
month_to_int[u"augst"] = 8
|
||||
month_to_int[u"7ber"] = 9
|
||||
month_to_int[u"7bris"] = 9
|
||||
month_to_int[u"8ber"] = 10
|
||||
month_to_int[u"8bris"] = 10
|
||||
month_to_int[u"9ber"] = 11
|
||||
month_to_int[u"9bris"] = 11
|
||||
month_to_int[u"10ber"] = 12
|
||||
month_to_int[u"10bris"] = 12
|
||||
month_to_int[u"xber"] = 12
|
||||
month_to_int[u"xbris"] = 12
|
||||
|
||||
modifier_to_int = {
|
||||
u'voor' : Date.MOD_BEFORE,
|
||||
u'na' : Date.MOD_AFTER,
|
||||
u'tegen' : Date.MOD_ABOUT,
|
||||
u'om' : Date.MOD_ABOUT,
|
||||
u'rond' : Date.MOD_ABOUT,
|
||||
u'circa' : Date.MOD_ABOUT,
|
||||
u'ca.' : Date.MOD_ABOUT,
|
||||
}
|
||||
|
||||
calendar_to_int = {
|
||||
u'Gregoriaans' : Date.CAL_GREGORIAN,
|
||||
u'Greg.' : Date.CAL_GREGORIAN,
|
||||
u'Juliaans' : Date.CAL_JULIAN,
|
||||
u'Jul.' : Date.CAL_JULIAN,
|
||||
u'Hebreeuws' : Date.CAL_HEBREW,
|
||||
u'Hebr.' : Date.CAL_HEBREW,
|
||||
u'Islamitisch' : Date.CAL_ISLAMIC,
|
||||
u'Isl.' : Date.CAL_ISLAMIC,
|
||||
u'Franse republiek': Date.CAL_FRENCH,
|
||||
u'Fran.' : Date.CAL_FRENCH,
|
||||
u'Persisch' : Date.CAL_PERSIAN,
|
||||
}
|
||||
|
||||
quality_to_int = {
|
||||
u'geschat' : Date.QUAL_ESTIMATED,
|
||||
u'gesch.' : Date.QUAL_ESTIMATED,
|
||||
u'berekend' : Date.QUAL_CALCULATED,
|
||||
u'ber.' : Date.QUAL_CALCULATED,
|
||||
}
|
||||
|
||||
bce = DateParser.bce + ["voor onze tijdrekening",
|
||||
"voor Christus",
|
||||
"v\. Chr\."]
|
||||
|
||||
def init_strings(self):
|
||||
DateParser.init_strings(self)
|
||||
self._span = re.compile("(van)\s+(?P<start>.+)\s+(tot)\s+(?P<stop>.+)",
|
||||
re.IGNORECASE)
|
||||
self._range = re.compile("tussen\s+(?P<start>.+)\s+en\s+(?P<stop>.+)",
|
||||
re.IGNORECASE)
|
||||
self._text2 = re.compile('(\d+)?.?\s+?%s\s*((\d+)(/\d+)?)?'
|
||||
% self._mon_str,
|
||||
re.IGNORECASE)
|
||||
self._jtext2= re.compile('(\d+)?.?\s+?%s\s*((\d+)(/\d+)?)?'
|
||||
% self._jmon_str,
|
||||
re.IGNORECASE)
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# Dutch display
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
class DateDisplayNL(DateDisplay):
|
||||
|
||||
calendar = (
|
||||
"", u" (Juliaans)", u" (Hebreeuws)",
|
||||
u" (Franse Republiek)", u" (Persisch)", u" (Islamitisch)"
|
||||
)
|
||||
|
||||
_mod_str = ("",u"voor ",u"na ",u"rond ","","","")
|
||||
|
||||
_qual_str = ("",u"geschat ",u"berekend ")
|
||||
|
||||
_bce_str = "%s v. Chr."
|
||||
|
||||
formats = (
|
||||
"JJJJ-MM-DD (ISO)", "Numerisch DD/MM/JJ", "Maand Dag, Jaar",
|
||||
"Mnd. Dag Jaar", "Dag Maand Jaar", "Dag Mnd. Jaar"
|
||||
)
|
||||
|
||||
def _display_gregorian(self,date_val):
|
||||
year = self._slash_year(date_val[2],date_val[3])
|
||||
if self.format == 0:
|
||||
return self.display_iso(date_val)
|
||||
elif self.format == 1:
|
||||
# Numeric
|
||||
if date_val[0] == 0 and date_val[1] == 0:
|
||||
value = str(date_val[2])
|
||||
else:
|
||||
value = self._tformat.replace('%m',str(date_val[1]))
|
||||
value = value.replace('%d',str(date_val[0]))
|
||||
value = value.replace('%Y',str(abs(date_val[2])))
|
||||
value = value.replace('-','/')
|
||||
elif self.format == 2:
|
||||
# Month Day, Year
|
||||
if date_val[0] == 0:
|
||||
if date_val[1] == 0:
|
||||
value = year
|
||||
else:
|
||||
value = "%s %s" % (self._months[date_val[1]],year)
|
||||
else:
|
||||
value = "%s %d, %s" % (self._months[date_val[1]],date_val[0],year)
|
||||
elif self.format == 3:
|
||||
# Mnd Day, Year
|
||||
if date_val[0] == 0:
|
||||
if date_val[1] == 0:
|
||||
value = year
|
||||
else:
|
||||
value = "%s %s" % (self._MONS[date_val[1]],year)
|
||||
else:
|
||||
value = "%s %d, %s" % (self._MONS[date_val[1]],date_val[0],year)
|
||||
elif self.format == 4:
|
||||
# Day Month Year
|
||||
if date_val[0] == 0:
|
||||
if date_val[1] == 0:
|
||||
value = year
|
||||
else:
|
||||
value = "%s %s" % (self._months[date_val[1]],year)
|
||||
else:
|
||||
value = "%d %s %s" % (date_val[0],self._months[date_val[1]],year)
|
||||
else:
|
||||
# Day Mnd Year
|
||||
if date_val[0] == 0:
|
||||
if date_val[1] == 0:
|
||||
value = year
|
||||
else:
|
||||
value = "%s %s" % (self._MONS[date_val[1]],year)
|
||||
else:
|
||||
value = "%d %s %s" % (date_val[0],self._MONS[date_val[1]],year)
|
||||
if date_val[2] < 0:
|
||||
return self._bce_str % value
|
||||
else:
|
||||
return value
|
||||
|
||||
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'van',d1,u'tot',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 "%stussen %s en %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(('nl_NL','dutch','nl_BE','nl'),
|
||||
DateParserNL, DateDisplayNL)
|
171
src/DateHandler/Date_ru.py
Normal file
171
src/DateHandler/Date_ru.py
Normal file
@@ -0,0 +1,171 @@
|
||||
# -*- 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$
|
||||
|
||||
"""
|
||||
Russian-specific classes for parsing and displaying dates.
|
||||
"""
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# Python modules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
import re
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# GRAMPS modules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
from RelLib import Date
|
||||
from DateParser import DateParser
|
||||
from DateDisplay import DateDisplay
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# Russian parser
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
class DateParserRU(DateParser):
|
||||
|
||||
modifier_to_int = {
|
||||
u'до' : Date.MOD_BEFORE,
|
||||
u'по' : Date.MOD_BEFORE,
|
||||
u'после' : Date.MOD_AFTER,
|
||||
u'п.' : Date.MOD_AFTER,
|
||||
u'п' : Date.MOD_AFTER,
|
||||
u'с' : Date.MOD_AFTER,
|
||||
u'ок' : Date.MOD_ABOUT,
|
||||
u'ок.' : Date.MOD_ABOUT,
|
||||
u'около' : Date.MOD_ABOUT,
|
||||
u'примерно' : Date.MOD_ABOUT,
|
||||
u'прим' : Date.MOD_ABOUT,
|
||||
u'прим.' : Date.MOD_ABOUT,
|
||||
u'приблизительно' : Date.MOD_ABOUT,
|
||||
u'приб.' : Date.MOD_ABOUT,
|
||||
u'прибл.' : Date.MOD_ABOUT,
|
||||
u'приб' : Date.MOD_ABOUT,
|
||||
u'прибл' : Date.MOD_ABOUT,
|
||||
}
|
||||
|
||||
calendar_to_int = {
|
||||
u'григорианский' : Date.CAL_GREGORIAN,
|
||||
u'г' : Date.CAL_GREGORIAN,
|
||||
u'юлианский' : Date.CAL_JULIAN,
|
||||
u'ю' : Date.CAL_JULIAN,
|
||||
u'еврейский' : Date.CAL_HEBREW,
|
||||
u'е' : Date.CAL_HEBREW,
|
||||
u'исламский' : Date.CAL_ISLAMIC,
|
||||
u'и' : Date.CAL_ISLAMIC,
|
||||
u'республиканский': Date.CAL_FRENCH,
|
||||
u'р' : Date.CAL_FRENCH,
|
||||
u'персидский' : Date.CAL_PERSIAN,
|
||||
u'п' : Date.CAL_PERSIAN,
|
||||
}
|
||||
|
||||
quality_to_int = {
|
||||
u'оценено' : Date.QUAL_ESTIMATED,
|
||||
u'оцен.' : Date.QUAL_ESTIMATED,
|
||||
u'оц.' : Date.QUAL_ESTIMATED,
|
||||
u'оцен' : Date.QUAL_ESTIMATED,
|
||||
u'оц' : Date.QUAL_ESTIMATED,
|
||||
u'вычислено' : Date.QUAL_CALCULATED,
|
||||
u'вычисл.' : Date.QUAL_CALCULATED,
|
||||
u'выч.' : Date.QUAL_CALCULATED,
|
||||
u'вычисл' : Date.QUAL_CALCULATED,
|
||||
u'выч' : Date.QUAL_CALCULATED,
|
||||
}
|
||||
|
||||
def init_strings(self):
|
||||
DateParser.init_strings(self)
|
||||
_span_1 = [u'с',u'от']
|
||||
_span_2 = [u'по',u'до']
|
||||
_range_1 = [u'между',u'меж',u'меж.']
|
||||
_range_2 = [u'и']
|
||||
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)
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# Russian displayer
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
class DateDisplayRU(DateDisplay):
|
||||
|
||||
calendar = (
|
||||
"", u" (юлианский)",
|
||||
u" (еврейский)",
|
||||
u" (республиканский)",
|
||||
u" (персидский)",
|
||||
u" (исламский)"
|
||||
)
|
||||
|
||||
_mod_str = ("",u"до ",
|
||||
u"после ",
|
||||
u"около ","","","")
|
||||
|
||||
_qual_str = ("","оцен ","вычисл ")
|
||||
|
||||
formats = (
|
||||
"ГГГГ-ММ-ДД (ISO)", "Численный", "Месяц День, Год",
|
||||
"МЕС ДД, ГГГГГ", "День Месяц, Год", "ДД МЕС, ГГГГГ"
|
||||
)
|
||||
|
||||
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" % (qual_str,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 "%s%s %s %s %s%s" % (qual_str,u'между',d1,u'и',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(('ru_RU','ru','russian'),DateParserRU, DateDisplayRU)
|
168
src/DateHandler/Date_sv.py
Normal file
168
src/DateHandler/Date_sv.py
Normal file
@@ -0,0 +1,168 @@
|
||||
# -*- 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$
|
||||
|
||||
"""
|
||||
Swedish-specific classes for parsing and displaying dates.
|
||||
"""
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# Python modules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
import re
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# GRAMPS modules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
from RelLib import Date
|
||||
from DateParser import DateParser
|
||||
from DateDisplay import DateDisplay
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# Swedish parser class
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
class DateParserSv(DateParser):
|
||||
"""
|
||||
Converts a text string into a Date object, expecting a date
|
||||
notation in the swedish language. If the date cannot be converted,
|
||||
the text string is assigned.
|
||||
"""
|
||||
|
||||
# modifiers before the date
|
||||
modifier_to_int = {
|
||||
u'före' : Date.MOD_BEFORE,
|
||||
u'innan' : Date.MOD_BEFORE,
|
||||
u'efter' : Date.MOD_AFTER,
|
||||
u'omkring' : 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'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,
|
||||
}
|
||||
|
||||
quality_to_int = {
|
||||
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,
|
||||
}
|
||||
|
||||
def init_strings(self):
|
||||
DateParser.init_strings(self)
|
||||
self._span = re.compile(u"(från)\s+(?P<start>.+)\s+till\s+(?P<stop>.+)",
|
||||
re.IGNORECASE)
|
||||
self._range = re.compile(u"(mellan)\s+(?P<start>.+)\s+och\s+(?P<stop>.+)",
|
||||
re.IGNORECASE)
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# Swedish display class
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
class DateDisplaySv(DateDisplay):
|
||||
"""
|
||||
Swedish language date display class.
|
||||
"""
|
||||
|
||||
formats = (
|
||||
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",
|
||||
)
|
||||
|
||||
calendar = (
|
||||
"",
|
||||
" (juliansk)",
|
||||
" (hebreisk)",
|
||||
" (fransk republikansk)",
|
||||
" (persisk)",
|
||||
" (islamisk)"
|
||||
)
|
||||
|
||||
_mod_str = ("",u"före ",u"efter ",u"omkring ","","","")
|
||||
|
||||
_qual_str = ("",u"uppskattat ",u"beräknat ")
|
||||
|
||||
_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 ""
|
||||
elif mod == Date.MOD_SPAN:
|
||||
d1 = self.display_cal[cal](start)
|
||||
d2 = self.display_cal[cal](date.get_stop_date())
|
||||
return u"%sfrån %s till %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"%smellan %s och %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(('sv_SE','sv','svensk'),DateParserSv, DateDisplaySv)
|
25
src/DateHandler/Makefile.am
Normal file
25
src/DateHandler/Makefile.am
Normal file
@@ -0,0 +1,25 @@
|
||||
# This is the src/plugins level Makefile for Gramps
|
||||
# We could use GNU make's ':=' syntax for nice wildcard use,
|
||||
# but that is not necessarily portable.
|
||||
# If not using GNU make, then list all .py files individually
|
||||
|
||||
pkgdatadir = $(datadir)/@PACKAGE@/dates
|
||||
|
||||
pkgdata_PYTHON = \
|
||||
Date_de.py\
|
||||
Date_ru.py\
|
||||
Date_lt.py\
|
||||
Date_fr.py\
|
||||
Date_es.py\
|
||||
Date_fi.py\
|
||||
Date_sv.py\
|
||||
Date_nl.py
|
||||
|
||||
pkgpyexecdir = @pkgpyexecdir@/dates
|
||||
pkgpythondir = @pkgpythondir@/dates
|
||||
|
||||
GRAMPS_PY_MODPATH = ".."
|
||||
|
||||
pycheck:
|
||||
(export PYTHONPATH=$(GRAMPS_PY_MODPATH); \
|
||||
pychecker $(pkgdata_PYTHON));
|
196
src/DateHandler/__init__.py
Normal file
196
src/DateHandler/__init__.py
Normal file
@@ -0,0 +1,196 @@
|
||||
#
|
||||
# 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$
|
||||
|
||||
"""
|
||||
Class handling language-specific selection for date parser and displayer.
|
||||
"""
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# Standard python modules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
import os
|
||||
import locale
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# set up logging
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
import logging
|
||||
log = logging.getLogger(".DateHandler")
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# GRAMPS modules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
import DateParser
|
||||
import DateDisplay
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# Constants
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
_lang = locale.getlocale(locale.LC_TIME)[0]
|
||||
if _lang:
|
||||
_lang_short = _lang.split('_')[0]
|
||||
else:
|
||||
_lang_short = "C"
|
||||
|
||||
_lang_to_parser = {
|
||||
'C' : DateParser.DateParser,
|
||||
'en' : DateParser.DateParser,
|
||||
}
|
||||
|
||||
_lang_to_display = {
|
||||
'C' : DateDisplay.DateDisplayEn,
|
||||
'en' : DateDisplay.DateDisplayEn,
|
||||
'zh_CN' : DateDisplay.DateDisplay,
|
||||
'zh_TW' : DateDisplay.DateDisplay,
|
||||
'zh_SG' : DateDisplay.DateDisplay,
|
||||
'zh_HK' : DateDisplay.DateDisplay,
|
||||
'ja_JP' : DateDisplay.DateDisplay,
|
||||
'ko_KR' : DateDisplay.DateDisplay,
|
||||
}
|
||||
|
||||
def get_date_formats():
|
||||
"""
|
||||
Returns the lists supported formats for date parsers and displayers
|
||||
"""
|
||||
try:
|
||||
return _lang_to_display[_lang].formats
|
||||
except:
|
||||
return _lang_to_display["C"].formats
|
||||
|
||||
def set_format(value):
|
||||
try:
|
||||
displayer.set_format(value)
|
||||
except:
|
||||
pass
|
||||
|
||||
def register_datehandler(locales,parse_class,display_class):
|
||||
"""
|
||||
Registers the passed date parser class and date displayer
|
||||
classes with the specfied language locales.
|
||||
|
||||
@param locales: tuple of strings containing language codes.
|
||||
The character encoding is not included, so the langauge
|
||||
should be in the form of fr_FR, not fr_FR.utf8
|
||||
@type locales: tuple
|
||||
@param parse_class: Class to be associated with parsing
|
||||
@type parse_class: DateParse
|
||||
@param display_class: Class to be associated with displaying
|
||||
@type display_class: DateDisplay
|
||||
"""
|
||||
for lang_str in locales:
|
||||
_lang_to_parser[lang_str] = parse_class
|
||||
_lang_to_display[lang_str] = display_class
|
||||
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# Import localized date classes
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
from PluginMgr import load_plugins
|
||||
from const import datesDir
|
||||
load_plugins(datesDir)
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# Initialize global parser
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
|
||||
try:
|
||||
if _lang_to_parser.has_key(_lang):
|
||||
parser = _lang_to_parser[_lang]()
|
||||
else:
|
||||
parser = _lang_to_parser[_lang_short]()
|
||||
except:
|
||||
print "Date parser for",_lang,"not available, using default"
|
||||
parser = _lang_to_parser["C"]()
|
||||
|
||||
try:
|
||||
import Config
|
||||
val = Config.get_date_format(_lang_to_display[_lang].formats)
|
||||
except:
|
||||
try:
|
||||
val = Config.get_date_format(_lang_to_display["C"].formats)
|
||||
except:
|
||||
val = 0
|
||||
|
||||
try:
|
||||
if _lang_to_display.has_key(_lang):
|
||||
displayer = _lang_to_display[_lang](val)
|
||||
else:
|
||||
displayer = _lang_to_display[_lang_short](val)
|
||||
except:
|
||||
print "Date displayer for",_lang,"not available, using default"
|
||||
displayer = _lang_to_display["C"](val)
|
||||
|
||||
|
||||
#--------------------------------------------------------------
|
||||
#
|
||||
# Convenience functions
|
||||
#
|
||||
#--------------------------------------------------------------
|
||||
|
||||
def set_date(date_base, text) :
|
||||
"""
|
||||
Sets the date of the DateBase instance.
|
||||
|
||||
The date is parsed into a L{Date} instance.
|
||||
|
||||
@param date: String representation of a date. The locale specific
|
||||
L{DateParser} is used to parse the string into a GRAMPS L{Date}
|
||||
object.
|
||||
@type date: str
|
||||
"""
|
||||
parser.set_date(date_base.get_date_object(),text)
|
||||
|
||||
def get_date(date_base) :
|
||||
"""
|
||||
Returns a string representation of the date of the DateBase instance.
|
||||
|
||||
This representation is based off the default date display format
|
||||
determined by the locale's L{DateDisplay} instance.
|
||||
@return: Returns a string representing the DateBase date
|
||||
@rtype: str
|
||||
"""
|
||||
return displayer.display(date_base.get_date_object())
|
||||
|
||||
def get_quote_date(self) :
|
||||
"""
|
||||
Returns a string representation of the date of the DateBase instance.
|
||||
|
||||
This representation is based off the default date display format
|
||||
determined by the locale's L{DateDisplay} instance. The date is
|
||||
enclosed in quotes if the L{Date} is not a valid date.
|
||||
|
||||
@return: Returns a string representing the DateBase date
|
||||
@rtype: str
|
||||
"""
|
||||
return displayer.quote_display(date_base.get_date_object())
|
Reference in New Issue
Block a user