Add support for open spans

This commit is contained in:
Jan Skarvall
2020-09-13 17:18:06 +02:00
committed by Nick Hall
parent 1af35153d9
commit 70520be80c
42 changed files with 9448 additions and 6621 deletions
+166 -97
View File
@@ -23,29 +23,29 @@
Arabic-specific classes for parsing and displaying dates.
"""
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# Python modules
#
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
import re
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# Gramps modules
#
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
from ..lib.date import Date
from ._dateparser import DateParser
from ._datedisplay import DateDisplay
from ._datehandler import register_datehandler
from ..const import ARABIC_COMMA
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# Arabic parser class
#
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
class DateParserAR(DateParser):
"""
Convert a text string into a Date object. If the date cannot be
@@ -54,117 +54,183 @@ class DateParserAR(DateParser):
# modifiers before the date
modifier_to_int = {
'قبل' : Date.MOD_BEFORE,
'قبل' : Date.MOD_BEFORE,
'قبل.' : Date.MOD_BEFORE,
'بعد' : Date.MOD_AFTER,
'بعد' : Date.MOD_AFTER,
'بعد.' : Date.MOD_AFTER,
'حوالي' : Date.MOD_ABOUT,
'حوالي.' : Date.MOD_ABOUT,
'حوالي' : Date.MOD_ABOUT,
'حوالي' : Date.MOD_ABOUT,
'حوالي.' : Date.MOD_ABOUT,
'حوالي' : Date.MOD_ABOUT,
}
"قبل": Date.MOD_BEFORE,
"قبل": Date.MOD_BEFORE,
"قبل.": Date.MOD_BEFORE,
"بعد": Date.MOD_AFTER,
"بعد": Date.MOD_AFTER,
"بعد.": Date.MOD_AFTER,
"حوالي": Date.MOD_ABOUT,
"حوالي.": Date.MOD_ABOUT,
"حوالي": Date.MOD_ABOUT,
"حوالي": Date.MOD_ABOUT,
"حوالي.": Date.MOD_ABOUT,
"حوالي": Date.MOD_ABOUT,
"from": Date.MOD_FROM,
"to": Date.MOD_TO,
}
islamic_to_int = {
"محرّم" : 1, "محرّم الحرام" : 1,
"صفر" : 2, "ربيع الأول" : 3,
"ربيع 1" : 3, "ربيع الأخير" : 4,
"ربيع الثاني" : 4, "ربيع الثاني" : 4,
"ربيع الثاني" : 4, "ربيع الثاني" : 4,
"ربيع 2" : 4, "جمادى الأولى" : 5,
"جمادى الأول" : 5, "جمادى 1" : 5,
"جمادى الثانية" : 6, "جمادى الأخير" : 6,
"جمادى الثاني" : 6, "جمادى 2" : 5,
"رجب" : 7, "شعبان" : 8,
"شعبان" : 8, "رمضان" : 9,
"رمضان" : 9, "شوال" : 10,
"ذو القعدة" : 11, "ذو القعدة" : 11,
"ذو القعدة" : 11, "ذو الحجة" : 12,
"ذو الحجة" : 12, "ذو الحجة" : 12,
}
"محرّم": 1,
"محرّم الحرام": 1,
"صفر": 2,
"ربيع الأول": 3,
"ربيع 1": 3,
"ربيع الأخير": 4,
"ربيع الثاني": 4,
"ربيع الثاني": 4,
"ربيع الثاني": 4,
"ربيع الثاني": 4,
"ربيع 2": 4,
"جمادى الأولى": 5,
"جمادى الأول": 5,
"جمادى 1": 5,
"جمادى الثانية": 6,
"جمادى الأخير": 6,
"جمادى الثاني": 6,
"جمادى 2": 5,
"رجب": 7,
"شعبان": 8,
"شعبان": 8,
"رمضان": 9,
"رمضان": 9,
"شوال": 10,
"ذو القعدة": 11,
"ذو القعدة": 11,
"ذو القعدة": 11,
"ذو الحجة": 12,
"ذو الحجة": 12,
"ذو الحجة": 12,
}
bce = ["قبل الميلاد", "قبل الميلاد", "قبل الميلاد", "قبل الميلاد", "قبل الميلاد", "قبل الميلاد" ]
bce = [
"قبل الميلاد",
"قبل الميلاد",
"قبل الميلاد",
"قبل الميلاد",
"قبل الميلاد",
"قبل الميلاد",
]
calendar_to_int = {
'غريغوري' : Date.CAL_GREGORIAN,
'غريغوري' : Date.CAL_GREGORIAN,
'يوليوسي' : Date.CAL_JULIAN,
'يوليوسي' : Date.CAL_JULIAN,
'عبري' : Date.CAL_HEBREW,
'عبري' : Date.CAL_HEBREW,
'إسلامي' : Date.CAL_ISLAMIC,
'إسلامي' : Date.CAL_ISLAMIC,
'فرنسي' : Date.CAL_FRENCH,
'فرنسي جمهوري': Date.CAL_FRENCH,
'فرنسي' : Date.CAL_FRENCH,
'فارسي' : Date.CAL_PERSIAN,
'فارسي' : Date.CAL_PERSIAN,
'سويدي' : Date.CAL_SWEDISH,
'سويدي' : Date.CAL_SWEDISH,
}
"غريغوري": Date.CAL_GREGORIAN,
"غريغوري": Date.CAL_GREGORIAN,
"يوليوسي": Date.CAL_JULIAN,
"يوليوسي": Date.CAL_JULIAN,
"عبري": Date.CAL_HEBREW,
"عبري": Date.CAL_HEBREW,
"إسلامي": Date.CAL_ISLAMIC,
"إسلامي": Date.CAL_ISLAMIC,
"فرنسي": Date.CAL_FRENCH,
"فرنسي جمهوري": Date.CAL_FRENCH,
"فرنسي": Date.CAL_FRENCH,
"فارسي": Date.CAL_PERSIAN,
"فارسي": Date.CAL_PERSIAN,
"سويدي": Date.CAL_SWEDISH,
"سويدي": Date.CAL_SWEDISH,
}
quality_to_int = {
'متوقع' : Date.QUAL_ESTIMATED,
'متوقع.' : Date.QUAL_ESTIMATED,
'متوقع' : Date.QUAL_ESTIMATED,
'محسوب.' : Date.QUAL_CALCULATED,
'محسوب' : Date.QUAL_CALCULATED,
'محسوب' : Date.QUAL_CALCULATED,
}
"متوقع": Date.QUAL_ESTIMATED,
"متوقع.": Date.QUAL_ESTIMATED,
"متوقع": Date.QUAL_ESTIMATED,
"محسوب.": Date.QUAL_CALCULATED,
"محسوب": Date.QUAL_CALCULATED,
"محسوب": Date.QUAL_CALCULATED,
}
def init_strings(self):
"""
This method compiles regular expression strings for matching dates.
"""
DateParser.init_strings(self)
_span_1 = ['من']
_span_2 = ['إلى']
_range_1 = ['بين']
_range_2 = ['و']
_span_1 = ["من"]
_span_2 = ["إلى"]
_range_1 = ["بين"]
_range_2 = ["و"]
self._span = re.compile(
r"(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" %
('|'.join(_span_1), '|'.join(_span_2)), re.IGNORECASE)
r"(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)"
% ("|".join(_span_1), "|".join(_span_2)),
re.IGNORECASE,
)
self._range = re.compile(
r"(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" %
('|'.join(_range_1), '|'.join(_range_2)), re.IGNORECASE)
r"(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)"
% ("|".join(_range_1), "|".join(_range_2)),
re.IGNORECASE,
)
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# Arabic display
#
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
class DateDisplayAR(DateDisplay):
"""
Arabic language date display class.
"""
# this is used to display the 12 gregorian months
long_months = ( "", "كانون الثاني", "شباط", "آذار", "نيسان", "أيار",
"حزيران", "تموز", "آب", "أيلول", "تشرين الأول",
"تشرين الثاني", "كانون الأول" )
short_months = ( "", "كانون2", "شباط", "آذار", "نيسان", "أيار", "حزيران",
"تموز", "آب", "أيلول", "تشرين1", "تشرين2", "كانون1" )
# this is used to display the 12 gregorian months
long_months = (
"",
"كانون الثاني",
"شباط",
"آذار",
"نيسان",
"أيار",
"حزيران",
"تموز",
"آب",
"أيلول",
"تشرين الأول",
"تشرين الثاني",
"كانون الأول",
)
short_months = (
"",
"كانون2",
"شباط",
"آذار",
"نيسان",
"أيار",
"حزيران",
"تموز",
"آب",
"أيلول",
"تشرين1",
"تشرين2",
"كانون1",
)
islamic = (
"", "محرّم", "صفر", "ربيع الأول", "ربيع الثاني",
"جمادى الأولى", "جمادى الثانية", "رجب", "شعبان",
"رمضان", "شوال", "ذو القعدة", "ذو الحجة"
)
"",
"محرّم",
"صفر",
"ربيع الأول",
"ربيع الثاني",
"جمادى الأولى",
"جمادى الثانية",
"رجب",
"شعبان",
"رمضان",
"شوال",
"ذو القعدة",
"ذو الحجة",
)
formats = (
"YYYY-MM-DD (قياسي)", "عددي", "شهر يوم, سنة",
"شهر يوم, سنة", "يوم شهر سنة", "يوم شهر سنة"
)
# this must agree with DateDisplayEn's "formats" definition
# (since no locale-specific _display_gregorian exists, here)
"YYYY-MM-DD (قياسي)",
"عددي",
"شهر يوم, سنة",
"شهر يوم, سنة",
"يوم شهر سنة",
"يوم شهر سنة",
)
# this must agree with DateDisplayEn's "formats" definition
# (since no locale-specific _display_gregorian exists, here)
calendar = (
"", "يوليوسي", "عبري", "فرنسي",
"فارسي", "إسلامي", "سويدي"
)
calendar = ("", "يوليوسي", "عبري", "فرنسي", "فارسي", "إسلامي", "سويدي")
_mod_str = ("", "قبل ", "بعد ", "حوالي ", "", "", "")
@@ -192,12 +258,12 @@ class DateDisplayAR(DateDisplay):
d1 = self.display_cal[cal](start)
d2 = self.display_cal[cal](date.get_stop_date())
scal = self.format_extras(cal, newyear)
return "%s%s %s %s %s%s" % (qual_str, 'من', d1, 'إلى', d2, scal)
return "%s%s %s %s %s%s" % (qual_str, "من", d1, "إلى", d2, scal)
elif mod == Date.MOD_RANGE:
d1 = self.display_cal[cal](start)
d2 = self.display_cal[cal](date.get_stop_date())
scal = self.format_extras(cal, newyear)
return "%s%s %s %s %s%s" % (qual_str, 'بين', d1, 'و', d2, scal)
return "%s%s %s %s %s%s" % (qual_str, "بين", d1, "و", d2, scal)
else:
text = self.display_cal[date.get_calendar()](start)
scal = self.format_extras(cal, newyear)
@@ -208,27 +274,30 @@ class DateDisplayAR(DateDisplay):
numerical -- for Arabic dates
"""
value = DateDisplay.dd_dformat01(self, date_val)
return value.replace(',', ARABIC_COMMA)
return value.replace(",", ARABIC_COMMA)
def dd_dformat02(self, date_val, inflect, long_months):
"""
month_name day, year -- for Arabic dates
"""
value = DateDisplay.dd_dformat02(self, date_val, inflect, long_months)
return value.replace(',', ARABIC_COMMA)
return value.replace(",", ARABIC_COMMA)
def dd_dformat03(self, date_val, inflect, short_months):
"""
month_abbreviation day, year -- for Arabic dates
"""
value = DateDisplay.dd_dformat03(self, date_val, inflect, short_months)
return value.replace(',', ARABIC_COMMA)
return value.replace(",", ARABIC_COMMA)
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# Register classes
#
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
register_datehandler(
('ar_EG', 'ar_AR', 'ar', 'Arabic', 'arabic', ('%d %b, %Y',)),
DateParserAR, DateDisplayAR)
("ar_EG", "ar_AR", "ar", "Arabic", "arabic", ("%d %b, %Y",)),
DateParserAR,
DateDisplayAR,
)
+189 -147
View File
@@ -23,172 +23,202 @@
Bulgarian-specific classes for parsing and displaying dates.
"""
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# Python modules
#
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
import re
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# Gramps modules
#
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
from ..lib.date import Date
from ._dateparser import DateParser
from ._datedisplay import DateDisplay
from ._datehandler import register_datehandler
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# Bulgarian parser
#
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
class DateParserBG(DateParser):
modifier_to_int = {
'преди' : Date.MOD_BEFORE,
'пр.' : Date.MOD_BEFORE,
'пр' : Date.MOD_BEFORE,
'след' : Date.MOD_AFTER,
'сл.' : Date.MOD_AFTER,
'сл' : Date.MOD_AFTER,
'ок' : Date.MOD_ABOUT,
'ок.' : Date.MOD_ABOUT,
'около' : Date.MOD_ABOUT,
'примерно' : Date.MOD_ABOUT,
'прим' : Date.MOD_ABOUT,
'прим.' : Date.MOD_ABOUT,
'приблизително' : Date.MOD_ABOUT,
'приб.' : Date.MOD_ABOUT,
'прибл.' : Date.MOD_ABOUT,
'приб' : Date.MOD_ABOUT,
'прибл' : Date.MOD_ABOUT,
}
"преди": Date.MOD_BEFORE,
"пр.": Date.MOD_BEFORE,
"пр": Date.MOD_BEFORE,
"след": Date.MOD_AFTER,
"сл.": Date.MOD_AFTER,
"сл": Date.MOD_AFTER,
"ок": Date.MOD_ABOUT,
"ок.": Date.MOD_ABOUT,
"около": Date.MOD_ABOUT,
"примерно": Date.MOD_ABOUT,
"прим": Date.MOD_ABOUT,
"прим.": Date.MOD_ABOUT,
"приблизително": Date.MOD_ABOUT,
"приб.": Date.MOD_ABOUT,
"прибл.": Date.MOD_ABOUT,
"приб": Date.MOD_ABOUT,
"прибл": Date.MOD_ABOUT,
"from": Date.MOD_FROM,
"to": Date.MOD_TO,
}
calendar_to_int = {
'григориански' : Date.CAL_GREGORIAN,
'г' : Date.CAL_GREGORIAN,
'юлиански' : Date.CAL_JULIAN,
'ю' : Date.CAL_JULIAN,
'еврейски' : Date.CAL_HEBREW,
'е' : Date.CAL_HEBREW,
'ислямски' : Date.CAL_ISLAMIC,
'и' : Date.CAL_ISLAMIC,
'френски републикански' : Date.CAL_FRENCH,
'републикански' : Date.CAL_FRENCH,
'фр.реп.' : Date.CAL_FRENCH,
'р' : Date.CAL_FRENCH,
'френски' : Date.CAL_FRENCH,
'фр.' : Date.CAL_FRENCH,
'персийски' : Date.CAL_PERSIAN,
'п' : Date.CAL_PERSIAN,
}
"григориански": Date.CAL_GREGORIAN,
"г": Date.CAL_GREGORIAN,
"юлиански": Date.CAL_JULIAN,
"ю": Date.CAL_JULIAN,
"еврейски": Date.CAL_HEBREW,
"е": Date.CAL_HEBREW,
"ислямски": Date.CAL_ISLAMIC,
"и": Date.CAL_ISLAMIC,
"френски републикански": Date.CAL_FRENCH,
"републикански": Date.CAL_FRENCH,
"фр.реп.": Date.CAL_FRENCH,
"р": Date.CAL_FRENCH,
"френски": Date.CAL_FRENCH,
"фр.": Date.CAL_FRENCH,
"персийски": Date.CAL_PERSIAN,
"п": Date.CAL_PERSIAN,
}
quality_to_int = {
'приблизително' : Date.QUAL_ESTIMATED,
'прибл.' : Date.QUAL_ESTIMATED,
'изчислено' : Date.QUAL_CALCULATED,
'изчисл.' : Date.QUAL_CALCULATED,
'изч.' : Date.QUAL_CALCULATED,
}
"приблизително": Date.QUAL_ESTIMATED,
"прибл.": Date.QUAL_ESTIMATED,
"изчислено": Date.QUAL_CALCULATED,
"изчисл.": Date.QUAL_CALCULATED,
"изч.": Date.QUAL_CALCULATED,
}
hebrew_to_int = {
"тишрей":1,
"мархешван":2,
"кислев":3,
"тевет":4,
"шват":5,
"адар":6,
"адар бет":7,
"нисан":8,
"ияр":9,
"сиван":10,
"тамуз":11,
"ав":12,
"eлул":13,
"тишрей": 1,
"мархешван": 2,
"кислев": 3,
"тевет": 4,
"шват": 5,
"адар": 6,
"адар бет": 7,
"нисан": 8,
"ияр": 9,
"сиван": 10,
"тамуз": 11,
"ав": 12,
"eлул": 13,
}
islamic_to_int = {
"мухаррам":1,
"саффар":2,
"рабиу-л-ауал":3,
"рабиу-с-сани":4,
"джумадал-уля":5,
"джумада-с-сания":6,
"раджаб":7,
"шаабан":8,
"рамадан":9,
"шауал":10,
"зу-л-кида":11,
"зул-л-хиджа":12,
}
"мухаррам": 1,
"саффар": 2,
"рабиу-л-ауал": 3,
"рабиу-с-сани": 4,
"джумадал-уля": 5,
"джумада-с-сания": 6,
"раджаб": 7,
"шаабан": 8,
"рамадан": 9,
"шауал": 10,
"зу-л-кида": 11,
"зул-л-хиджа": 12,
}
persian_to_int = {
"фарвардин":1,
"урдбихищ":2,
"хурдад":3,
"тир":4,
"мурдад":5,
"шахривар":6,
"михр":7,
"абан":8,
"азар":9,
"дай":10,
"бахман":11,
"исфаидармуз":12,
}
"фарвардин": 1,
"урдбихищ": 2,
"хурдад": 3,
"тир": 4,
"мурдад": 5,
"шахривар": 6,
"михр": 7,
"абан": 8,
"азар": 9,
"дай": 10,
"бахман": 11,
"исфаидармуз": 12,
}
french_to_int = {
"вандемер":1,
"брюмер":2,
"фример":3,
"нивоз":4,
"плювиоз":5,
"вантоз":6,
"жерминал":7,
"флореал":8,
"прериал":9,
"месидор":10,
"термидор":11,
"фрюктидор":12,
"допълнителен":13,
}
"вандемер": 1,
"брюмер": 2,
"фример": 3,
"нивоз": 4,
"плювиоз": 5,
"вантоз": 6,
"жерминал": 7,
"флореал": 8,
"прериал": 9,
"месидор": 10,
"термидор": 11,
"фрюктидор": 12,
"допълнителен": 13,
}
bce = [
'преди Христа', 'пр. Хр.', 'пр.Хр.'
] + DateParser.bce
bce = ["преди Христа", "пр. Хр.", "пр.Хр."] + DateParser.bce
def init_strings(self):
DateParser.init_strings(self)
_span_1 = ['от']
_span_2 = ['до']
_range_1 = ['между']
_range_2 = ['и']
_span_1 = ["от"]
_span_2 = ["до"]
_range_1 = ["между"]
_range_2 = ["и"]
self._span = re.compile(
r"(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" %
('|'.join(_span_1), '|'.join(_span_2)), re.IGNORECASE)
r"(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)"
% ("|".join(_span_1), "|".join(_span_2)),
re.IGNORECASE,
)
self._range = re.compile(
r"(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" %
('|'.join(_range_1), '|'.join(_range_2)), re.IGNORECASE)
r"(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)"
% ("|".join(_range_1), "|".join(_range_2)),
re.IGNORECASE,
)
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# Bulgarian displayer
#
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
class DateDisplayBG(DateDisplay):
"""
Bulgarian language date display class.
"""
long_months = ( "", "януари", "февруари", "март", "април", "май",
"юни", "юли", "август", "септември", "октомври",
"ноември", "декември" )
short_months = ( "", "яну", "февр", "март", "апр", "май", "юни",
"юли", "авг", "септ", "окт", "ное", "дек" )
long_months = (
"",
"януари",
"февруари",
"март",
"април",
"май",
"юни",
"юли",
"август",
"септември",
"октомври",
"ноември",
"декември",
)
short_months = (
"",
"яну",
"февр",
"март",
"апр",
"май",
"юни",
"юли",
"авг",
"септ",
"окт",
"ное",
"дек",
)
calendar = (
"",
@@ -197,8 +227,8 @@ class DateDisplayBG(DateDisplay):
"републикански",
"персийски",
"ислямски",
"шведски"
)
"шведски",
)
_mod_str = ("", "преди ", "след ", "около ", "", "", "")
@@ -207,12 +237,18 @@ class DateDisplayBG(DateDisplay):
_bce_str = "%s пр. Хр."
formats = (
"ГГГГ-ММ-ДД (ISO)", "Числов", "Месец Ден, Година", "Мес. Ден, Година", "Ден Месец Година", "Ден Мес. Година"
)
# this must agree with DateDisplayEn's "formats" definition
# (since no locale-specific _display_gregorian exists, here)
"ГГГГ-ММ-ДД (ISO)",
"Числов",
"Месец Ден, Година",
"Мес. Ден, Година",
"Ден Месец Година",
"Ден Мес. Година",
)
# this must agree with DateDisplayEn's "formats" definition
# (since no locale-specific _display_gregorian exists, here)
hebrew = ( "",
hebrew = (
"",
"Тишрей",
"Мархешван",
"Кислев",
@@ -226,9 +262,10 @@ class DateDisplayBG(DateDisplay):
"Тамуз",
"Ав",
"Елул",
)
)
islamic = ( "",
islamic = (
"",
"Мухаррам",
"Саффар",
"Рабиу-л-ауал",
@@ -241,9 +278,10 @@ class DateDisplayBG(DateDisplay):
"Шауал",
"Зу-л-кида",
"Зул-л-хиджа",
)
)
persian = ( "",
persian = (
"",
"Фарвардин",
"Урдбихищ",
"Хурдад",
@@ -256,9 +294,10 @@ class DateDisplayBG(DateDisplay):
"Дай",
"Бахман",
"Исфаидармуз",
)
)
french = ( "",
french = (
"",
"Вандемер",
"Брюмер",
"Фример",
@@ -271,8 +310,8 @@ class DateDisplayBG(DateDisplay):
"Мессидор",
"Термидор",
"Фрюктидор",
"Допълнителен"
)
"Допълнителен",
)
def display(self, date):
"""
@@ -294,12 +333,12 @@ class DateDisplayBG(DateDisplay):
d1 = self.display_cal[cal](start)
d2 = self.display_cal[cal](date.get_stop_date())
scal = self.format_extras(cal, newyear)
return "%s%s %s %s %s%s" % (qual_str, 'от', d1, 'до', d2, scal)
return "%s%s %s %s %s%s" % (qual_str, "от", d1, "до", d2, scal)
elif mod == Date.MOD_RANGE:
d1 = self.display_cal[cal](start)
d2 = self.display_cal[cal](date.get_stop_date())
scal = self.format_extras(cal, newyear)
return "%s%s %s %s %s%s" % (qual_str, 'между', d1, 'и', d2, scal)
return "%s%s %s %s %s%s" % (qual_str, "между", d1, "и", d2, scal)
else:
text = self.display_cal[date.get_calendar()](start)
scal = self.format_extras(cal, newyear)
@@ -315,21 +354,24 @@ class DateDisplayBG(DateDisplay):
if date_val[0] == date_val[1] == 0:
return str(date_val[2])
else:
value = self.dhformat.replace('%m', str(date_val[1]))
value = self.dhformat.replace("%m", str(date_val[1]))
# some locales have %b for the month, e.g. ar_EG, is_IS, nb_NO
value = value.replace('%b', str(date_val[1]))
if date_val[0] == 0: # ignore the zero day and its delimiter
i_day = value.find('%e') # Bulgarian uses %e and not %d
value = value.replace(value[i_day:i_day+3], '')
value = value.replace('%e', str(date_val[0]))
value = value.replace('%Y', str(abs(date_val[2])))
return value.replace('-', '/')
value = value.replace("%b", str(date_val[1]))
if date_val[0] == 0: # ignore the zero day and its delimiter
i_day = value.find("%e") # Bulgarian uses %e and not %d
value = value.replace(value[i_day : i_day + 3], "")
value = value.replace("%e", str(date_val[0]))
value = value.replace("%Y", str(abs(date_val[2])))
return value.replace("-", "/")
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# Register classes
#
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
register_datehandler(
('bg_BG', 'bg', 'bulgarian', 'Bulgarian', ('%e.%m.%Y',)),
DateParserBG, DateDisplayBG)
("bg_BG", "bg", "bulgarian", "Bulgarian", ("%e.%m.%Y",)),
DateParserBG,
DateDisplayBG,
)
+122 -87
View File
@@ -25,137 +25,170 @@
Catalan-specific classes for parsing and displaying dates.
"""
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# Python modules
#
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
import re
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# Gramps modules
#
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
from ..lib.date import Date
from ._dateparser import DateParser
from ._datedisplay import DateDisplay
from ._datehandler import register_datehandler
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# Catalan parser
#
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
class DateParserCA(DateParser):
modifier_to_int = {
'abans de' : Date.MOD_BEFORE,
'abans' : Date.MOD_BEFORE,
'ab.' : Date.MOD_BEFORE,
'després de' : Date.MOD_AFTER,
'després' : Date.MOD_AFTER,
'desp.' : Date.MOD_AFTER,
'desp' : Date.MOD_AFTER,
'aprox.' : Date.MOD_ABOUT,
'aprox' : Date.MOD_ABOUT,
'circa' : Date.MOD_ABOUT,
'ca.' : Date.MOD_ABOUT,
'ca' : Date.MOD_ABOUT,
'c.' : Date.MOD_ABOUT,
'cap a' : Date.MOD_ABOUT,
'al voltant' : Date.MOD_ABOUT,
'al voltant de': Date.MOD_ABOUT,
}
"abans de": Date.MOD_BEFORE,
"abans": Date.MOD_BEFORE,
"ab.": Date.MOD_BEFORE,
"després de": Date.MOD_AFTER,
"després": Date.MOD_AFTER,
"desp.": Date.MOD_AFTER,
"desp": Date.MOD_AFTER,
"aprox.": Date.MOD_ABOUT,
"aprox": Date.MOD_ABOUT,
"circa": Date.MOD_ABOUT,
"ca.": Date.MOD_ABOUT,
"ca": Date.MOD_ABOUT,
"c.": Date.MOD_ABOUT,
"cap a": Date.MOD_ABOUT,
"al voltant": Date.MOD_ABOUT,
"al voltant de": Date.MOD_ABOUT,
"from": Date.MOD_FROM,
"to": Date.MOD_TO,
}
calendar_to_int = {
'gregorià' : Date.CAL_GREGORIAN,
'g' : Date.CAL_GREGORIAN,
'julià' : Date.CAL_JULIAN,
'j' : Date.CAL_JULIAN,
'hebreu' : Date.CAL_HEBREW,
'h' : Date.CAL_HEBREW,
'islàmic' : Date.CAL_ISLAMIC,
'i' : Date.CAL_ISLAMIC,
'revolucionari': Date.CAL_FRENCH,
'r' : Date.CAL_FRENCH,
'persa' : Date.CAL_PERSIAN,
'p' : Date.CAL_PERSIAN,
'swedish' : Date.CAL_SWEDISH,
's' : Date.CAL_SWEDISH,
}
"gregorià": Date.CAL_GREGORIAN,
"g": Date.CAL_GREGORIAN,
"julià": Date.CAL_JULIAN,
"j": Date.CAL_JULIAN,
"hebreu": Date.CAL_HEBREW,
"h": Date.CAL_HEBREW,
"islàmic": Date.CAL_ISLAMIC,
"i": Date.CAL_ISLAMIC,
"revolucionari": Date.CAL_FRENCH,
"r": Date.CAL_FRENCH,
"persa": Date.CAL_PERSIAN,
"p": Date.CAL_PERSIAN,
"swedish": Date.CAL_SWEDISH,
"s": Date.CAL_SWEDISH,
}
quality_to_int = {
'estimat' : Date.QUAL_ESTIMATED,
'est.' : Date.QUAL_ESTIMATED,
'est' : Date.QUAL_ESTIMATED,
'calc.' : Date.QUAL_CALCULATED,
'calc' : Date.QUAL_CALCULATED,
'calculat' : Date.QUAL_CALCULATED,
}
"estimat": Date.QUAL_ESTIMATED,
"est.": Date.QUAL_ESTIMATED,
"est": Date.QUAL_ESTIMATED,
"calc.": Date.QUAL_CALCULATED,
"calc": Date.QUAL_CALCULATED,
"calculat": Date.QUAL_CALCULATED,
}
def init_strings(self):
DateParser.init_strings(self)
_span_1 = ['des de']
_span_2 = ['fins a']
_range_1 = ['entre', r'ent\.', 'ent']
_range_2 = ['i']
_span_1 = ["des de"]
_span_2 = ["fins a"]
_range_1 = ["entre", r"ent\.", "ent"]
_range_2 = ["i"]
self._span = re.compile(
r"(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" %
('|'.join(_span_1), '|'.join(_span_2)), re.IGNORECASE)
r"(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)"
% ("|".join(_span_1), "|".join(_span_2)),
re.IGNORECASE,
)
self._range = re.compile(
r"(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" %
('|'.join(_range_1), '|'.join(_range_2)), re.IGNORECASE)
r"(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)"
% ("|".join(_range_1), "|".join(_range_2)),
re.IGNORECASE,
)
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# Catalan display
#
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
class DateDisplayCA(DateDisplay):
"""
Catalan language date display class.
"""
long_months = ( "", "Gener", "Febrer", "Març", "Abril", "Maig",
"Juny", "Juliol", "Agost", "Setembre", "Octubre",
"Novembre", "Desembre" )
short_months = ( "", "Gen", "Feb", "Mar", "Abr", "Mai", "Jun",
"Jul", "Ago", "Set", "Oct", "Nov", "Des" )
long_months = (
"",
"Gener",
"Febrer",
"Març",
"Abril",
"Maig",
"Juny",
"Juliol",
"Agost",
"Setembre",
"Octubre",
"Novembre",
"Desembre",
)
calendar = (
"", "Julià", "Hebreu",
"Revolucionari", "Persa", "Islàmic",
"Suec"
)
short_months = (
"",
"Gen",
"Feb",
"Mar",
"Abr",
"Mai",
"Jun",
"Jul",
"Ago",
"Set",
"Oct",
"Nov",
"Des",
)
calendar = ("", "Julià", "Hebreu", "Revolucionari", "Persa", "Islàmic", "Suec")
_mod_str = ("", "abans de ", "després de ", "cap a ", "", "", "")
_qual_str = ("", "estimat ", "calculat ")
french = (
'',
"",
"Vendemiari",
'Brumari',
'Frimari',
"Brumari",
"Frimari",
"Nivós",
"Pluviós",
"Ventós",
'Germinal',
"Germinal",
"Floreal",
'Pradial',
'Messidor',
'Termidor',
'Fructidor',
'Extra',
)
"Pradial",
"Messidor",
"Termidor",
"Fructidor",
"Extra",
)
formats = (
"AAAA-MM-DD (ISO)", "Numèrica", "Mes Dia, Any",
"MES Dia, Any", "Dia Mes, Any", "Dia MES, Any"
)
# this must agree with DateDisplayEn's "formats" definition
# (since no locale-specific _display_gregorian exists, here)
"AAAA-MM-DD (ISO)",
"Numèrica",
"Mes Dia, Any",
"MES Dia, Any",
"Dia Mes, Any",
"Dia MES, Any",
)
# this must agree with DateDisplayEn's "formats" definition
# (since no locale-specific _display_gregorian exists, here)
def display(self, date):
"""
@@ -177,23 +210,25 @@ class DateDisplayCA(DateDisplay):
d1 = self.display_cal[cal](start)
d2 = self.display_cal[cal](date.get_stop_date())
scal = self.format_extras(cal, newyear)
return "%s%s %s %s %s%s" % (qual_str, 'des de', d1, 'fins a', d2, scal)
return "%s%s %s %s %s%s" % (qual_str, "des de", d1, "fins a", d2, scal)
elif mod == Date.MOD_RANGE:
d1 = self.display_cal[cal](start)
d2 = self.display_cal[cal](date.get_stop_date())
scal = self.format_extras(cal, newyear)
return "%s%s %s %s %s%s" % (qual_str, 'entre', d1, 'i', d2, scal)
return "%s%s %s %s %s%s" % (qual_str, "entre", d1, "i", d2, scal)
else:
text = self.display_cal[date.get_calendar()](start)
scal = self.format_extras(cal, newyear)
return "%s%s%s%s" % (qual_str, self._mod_str[mod], text, scal)
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# Register classes
#
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
register_datehandler(
('ca_ES', 'ca', 'català', 'Catalan',
'ca_FR', 'ca_AD', 'ca_IT', ('%d/%m/%Y',)),
DateParserCA, DateDisplayCA)
("ca_ES", "ca", "català", "Catalan", "ca_FR", "ca_AD", "ca_IT", ("%d/%m/%Y",)),
DateParserCA,
DateDisplayCA,
)
+41 -33
View File
@@ -23,72 +23,80 @@
Czech-specific classes for parsing and displaying dates.
"""
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# Python modules
#
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
import re
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# Gramps modules
#
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
from ..lib.date import Date
from ._dateparser import DateParser
from ._datedisplay import DateDisplay
from ._datehandler import register_datehandler
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# Czech parser
#
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
class DateParserCZ(DateParser):
"""
Converts a text string into a Date object
"""
modifier_to_int = {
'před': Date.MOD_BEFORE,
'kolem': Date.MOD_ABOUT,
'po': Date.MOD_AFTER,
"před": Date.MOD_BEFORE,
"kolem": Date.MOD_ABOUT,
"po": Date.MOD_AFTER,
"from": Date.MOD_FROM,
"to": Date.MOD_TO,
}
quality_to_int = {
'přibližně' : Date.QUAL_ESTIMATED,
'odhadem' : Date.QUAL_ESTIMATED,
'odh.' : Date.QUAL_ESTIMATED,
'vypočteno' : Date.QUAL_CALCULATED,
'vypočtené' : Date.QUAL_CALCULATED,
'vyp.' : Date.QUAL_CALCULATED,
"přibližně": Date.QUAL_ESTIMATED,
"odhadem": Date.QUAL_ESTIMATED,
"odh.": Date.QUAL_ESTIMATED,
"vypočteno": Date.QUAL_CALCULATED,
"vypočtené": Date.QUAL_CALCULATED,
"vyp.": Date.QUAL_CALCULATED,
}
bce = ["před naším letopočtem", "před Kristem",
". n. l.", "př. Kr."] + DateParser.bce
bce = [
"ed naším letopočtem",
"před Kristem",
"př. n. l.",
"př. Kr.",
] + DateParser.bce
def dhformat_changed(self):
""" Allow overriding so a subclass can modify it """
"""Allow overriding so a subclass can modify it"""
# bug 9739 grampslocale.py gets '%-d.%-m.%Y' -- makes it be '%/d.%/m.%Y'
self.dhformat = self.dhformat.replace('/', '') # so counteract that
self.dhformat = self.dhformat.replace("/", "") # so counteract that
def init_strings(self):
DateParser.init_strings(self)
self._text2 = re.compile(r'(\d+)?\.?\s+?%s\.?\s*((\d+)(/\d+)?)?\s*$'
% self._mon_str, re.IGNORECASE)
self._text2 = re.compile(
r"(\d+)?\.?\s+?%s\.?\s*((\d+)(/\d+)?)?\s*$" % self._mon_str, re.IGNORECASE
)
self._span = re.compile(
r"(od)\s+(?P<start>.+)\s+(do)\s+(?P<stop>.+)",
re.IGNORECASE)
r"(od)\s+(?P<start>.+)\s+(do)\s+(?P<stop>.+)", re.IGNORECASE
)
self._range = re.compile(
r"(mezi)\s+(?P<start>.+)\s+(a)\s+(?P<stop>.+)",
re.IGNORECASE)
r"(mezi)\s+(?P<start>.+)\s+(a)\s+(?P<stop>.+)", re.IGNORECASE
)
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# Czech display
#
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
class DateDisplayCZ(DateDisplay):
"""
Czech language date display class.
@@ -97,17 +105,17 @@ class DateDisplayCZ(DateDisplay):
display = DateDisplay.display_formatted
def formats_changed(self):
""" Allow overriding so a subclass can modify """
"""Allow overriding so a subclass can modify"""
# bug 9537 grampslocale.py gets '%-d.%-m.%Y' -- makes it be '%/d.%/m.%Y'
self.dhformat = self.dhformat.replace('/', '') # so counteract that
self.dhformat = self.dhformat.replace("/", "") # so counteract that
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# Register classes
#
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
register_datehandler(
("cs_CZ", "cs", "CS", "Czech", ('%-d.%-m.%Y',)),
DateParserCZ, DateDisplayCZ)
("cs_CZ", "cs", "CS", "Czech", ("%-d.%-m.%Y",)), DateParserCZ, DateDisplayCZ
)
+85 -57
View File
@@ -23,28 +23,28 @@
Danish-specific classes for parsing and displaying dates.
"""
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# Python modules
#
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
import re
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# Gramps modules
#
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
from ..lib.date import Date
from ._dateparser import DateParser
from ._datedisplay import DateDisplay
from ._datehandler import register_datehandler
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# Danish parser class
#
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
class DateParserDa(DateParser):
"""
Convert a text string into a Date object, expecting a date
@@ -54,65 +54,94 @@ class DateParserDa(DateParser):
# modifiers before the date
modifier_to_int = {
'før' : Date.MOD_BEFORE,
'inden' : Date.MOD_BEFORE,
'efter' : Date.MOD_AFTER,
'omkring' : Date.MOD_ABOUT,
'ca.' : Date.MOD_ABOUT
}
"før": Date.MOD_BEFORE,
"inden": Date.MOD_BEFORE,
"efter": Date.MOD_AFTER,
"omkring": Date.MOD_ABOUT,
"ca.": Date.MOD_ABOUT,
"from": Date.MOD_FROM,
"to": Date.MOD_TO,
}
bce = ["f Kr"]
calendar_to_int = {
'gregoriansk ' : Date.CAL_GREGORIAN,
'g' : Date.CAL_GREGORIAN,
'juliansk tidsregning': Date.CAL_JULIAN,
'juliansk' : Date.CAL_JULIAN,
'j' : Date.CAL_JULIAN,
'hebraisk' : Date.CAL_HEBREW,
'h' : Date.CAL_HEBREW,
'islamisk' : Date.CAL_ISLAMIC,
'muslimsk' : Date.CAL_ISLAMIC,
'i' : Date.CAL_ISLAMIC,
'fransk' : Date.CAL_FRENCH,
'fransk republikansk' : Date.CAL_FRENCH,
'f' : Date.CAL_FRENCH,
'persisk' : Date.CAL_PERSIAN,
'p' : Date.CAL_PERSIAN,
'svensk' : Date.CAL_SWEDISH,
's' : Date.CAL_SWEDISH,
}
"gregoriansk ": Date.CAL_GREGORIAN,
"g": Date.CAL_GREGORIAN,
"juliansk tidsregning": Date.CAL_JULIAN,
"juliansk": Date.CAL_JULIAN,
"j": Date.CAL_JULIAN,
"hebraisk": Date.CAL_HEBREW,
"h": Date.CAL_HEBREW,
"islamisk": Date.CAL_ISLAMIC,
"muslimsk": Date.CAL_ISLAMIC,
"i": Date.CAL_ISLAMIC,
"fransk": Date.CAL_FRENCH,
"fransk republikansk": Date.CAL_FRENCH,
"f": Date.CAL_FRENCH,
"persisk": Date.CAL_PERSIAN,
"p": Date.CAL_PERSIAN,
"svensk": Date.CAL_SWEDISH,
"s": Date.CAL_SWEDISH,
}
quality_to_int = {
'estimeret' : Date.QUAL_ESTIMATED,
'anslået' : Date.QUAL_ESTIMATED,
'beregnet' : Date.QUAL_CALCULATED,
}
"estimeret": Date.QUAL_ESTIMATED,
"anslået": Date.QUAL_ESTIMATED,
"beregnet": Date.QUAL_CALCULATED,
}
def init_strings(self):
DateParser.init_strings(self)
self._span = re.compile(
r"(fra)?\s*(?P<start>.+)\s*(til|--|)\s*(?P<stop>.+)",
re.IGNORECASE)
r"(fra)?\s*(?P<start>.+)\s*(til|--|)\s*(?P<stop>.+)", re.IGNORECASE
)
self._range = re.compile(
r"(mellem)\s+(?P<start>.+)\s+og\s+(?P<stop>.+)", re.IGNORECASE)
r"(mellem)\s+(?P<start>.+)\s+og\s+(?P<stop>.+)", re.IGNORECASE
)
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# Danish display class
#
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
class DateDisplayDa(DateDisplay):
"""
Danish language date display class.
"""
long_months = ( "", "januar", "februar", "marts", "april", "maj",
"juni", "juli", "august", "september", "oktober",
"november", "december" )
long_months = (
"",
"januar",
"februar",
"marts",
"april",
"maj",
"juni",
"juli",
"august",
"september",
"oktober",
"november",
"december",
)
short_months = ( "", "jan", "feb", "mar", "apr", "maj", "jun",
"jul", "aug", "sep", "okt", "nov", "dec" )
short_months = (
"",
"jan",
"feb",
"mar",
"apr",
"maj",
"jun",
"jul",
"aug",
"sep",
"okt",
"nov",
"dec",
)
formats = (
"ÅÅÅÅ-MM-DD (ISO)",
@@ -121,9 +150,9 @@ class DateDisplayDa(DateDisplay):
"Md Dag År",
"Dag måned år",
"Dag md År",
)
# this must agree with DateDisplayEn's "formats" definition
# (since no locale-specific _display_gregorian exists, here)
)
# this must agree with DateDisplayEn's "formats" definition
# (since no locale-specific _display_gregorian exists, here)
calendar = (
"",
@@ -132,8 +161,8 @@ class DateDisplayDa(DateDisplay):
"fransk republikansk",
"persisk",
"islamisk",
"svensk"
)
"svensk",
)
_mod_str = ("", "før ", "efter ", "ca. ", "", "", "")
@@ -166,19 +195,18 @@ class DateDisplayDa(DateDisplay):
d1 = self.display_cal[cal](start)
d2 = self.display_cal[cal](date.get_stop_date())
scal = self.format_extras(cal, newyear)
return "%smellem %s og %s%s" % (qual_str, d1, d2,
scal)
return "%smellem %s og %s%s" % (qual_str, d1, d2, scal)
else:
text = self.display_cal[date.get_calendar()](start)
scal = self.format_extras(cal, newyear)
return "%s%s%s%s" % (qual_str, self._mod_str[mod],
text, scal)
return "%s%s%s%s" % (qual_str, self._mod_str[mod], text, scal)
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# Register classes
#
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
register_datehandler(
('da_DK', 'da', 'dansk', 'Danish', ('%d-%m-%Y',)),
DateParserDa, DateDisplayDa)
("da_DK", "da", "dansk", "Danish", ("%d-%m-%Y",)), DateParserDa, DateDisplayDa
)
+114 -77
View File
@@ -23,28 +23,28 @@
German-specific classes for parsing and displaying dates.
"""
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# Python modules
#
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
import re
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# Gramps modules
#
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
from ..lib.date import Date
from ._dateparser import DateParser
from ._datedisplay import DateDisplay
from ._datehandler import register_datehandler
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# German parser
#
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
class DateParserDE(DateParser):
month_to_int = DateParser.month_to_int
@@ -208,72 +208,90 @@ class DateParserDE(DateParser):
month_to_int["wendeling"] = 11
modifier_to_int = {
'vor' : Date.MOD_BEFORE,
'nach' : Date.MOD_AFTER,
'gegen' : Date.MOD_ABOUT,
'um' : Date.MOD_ABOUT,
'etwa' : Date.MOD_ABOUT,
'circa' : Date.MOD_ABOUT,
'ca.' : Date.MOD_ABOUT,
}
"vor": Date.MOD_BEFORE,
"nach": Date.MOD_AFTER,
"gegen": Date.MOD_ABOUT,
"um": Date.MOD_ABOUT,
"etwa": Date.MOD_ABOUT,
"circa": Date.MOD_ABOUT,
"ca.": Date.MOD_ABOUT,
"from": Date.MOD_FROM,
"to": Date.MOD_TO,
}
calendar_to_int = {
'gregorianisch' : Date.CAL_GREGORIAN,
'greg.' : Date.CAL_GREGORIAN,
'julianisch' : Date.CAL_JULIAN,
'jul.' : Date.CAL_JULIAN,
'hebräisch' : Date.CAL_HEBREW,
'hebr.' : Date.CAL_HEBREW,
'islamisch' : Date.CAL_ISLAMIC,
'isl.' : Date.CAL_ISLAMIC,
'französisch republikanisch': Date.CAL_FRENCH,
'franz.' : Date.CAL_FRENCH,
'persisch' : Date.CAL_PERSIAN,
'schwedisch' : Date.CAL_SWEDISH,
's' : Date.CAL_SWEDISH,
}
"gregorianisch": Date.CAL_GREGORIAN,
"greg.": Date.CAL_GREGORIAN,
"julianisch": Date.CAL_JULIAN,
"jul.": Date.CAL_JULIAN,
"hebräisch": Date.CAL_HEBREW,
"hebr.": Date.CAL_HEBREW,
"islamisch": Date.CAL_ISLAMIC,
"isl.": Date.CAL_ISLAMIC,
"französisch republikanisch": Date.CAL_FRENCH,
"franz.": Date.CAL_FRENCH,
"persisch": Date.CAL_PERSIAN,
"schwedisch": Date.CAL_SWEDISH,
"s": Date.CAL_SWEDISH,
}
quality_to_int = {
'geschätzt' : Date.QUAL_ESTIMATED,
'gesch.' : Date.QUAL_ESTIMATED,
'errechnet' : Date.QUAL_CALCULATED,
'berechnet' : Date.QUAL_CALCULATED,
'ber.' : Date.QUAL_CALCULATED,
}
"geschätzt": Date.QUAL_ESTIMATED,
"gesch.": Date.QUAL_ESTIMATED,
"errechnet": Date.QUAL_CALCULATED,
"berechnet": Date.QUAL_CALCULATED,
"ber.": Date.QUAL_CALCULATED,
}
bce = ["vor unserer Zeitrechnung", "vor unserer Zeit",
"vor der Zeitrechnung", "vor der Zeit",
"v. u. Z.", "v. d. Z.", "v.u.Z.", "v.d.Z.",
"vor Christi Geburt", "vor Christus", "v. Chr."] + DateParser.bce
bce = [
"vor unserer Zeitrechnung",
"vor unserer Zeit",
"vor der Zeitrechnung",
"vor der Zeit",
"v. u. Z.",
"v. d. Z.",
"v.u.Z.",
"v.d.Z.",
"vor Christi Geburt",
"vor Christus",
"v. Chr.",
] + DateParser.bce
def init_strings(self):
DateParser.init_strings(self)
self._span = re.compile(
r"(von|vom)\s+(?P<start>.+)\s+(bis)\s+(?P<stop>.+)", re.IGNORECASE)
r"(von|vom)\s+(?P<start>.+)\s+(bis)\s+(?P<stop>.+)", re.IGNORECASE
)
self._range = re.compile(
r"zwischen\s+(?P<start>.+)\s+und\s+(?P<stop>.+)", re.IGNORECASE)
r"zwischen\s+(?P<start>.+)\s+und\s+(?P<stop>.+)", re.IGNORECASE
)
self._text2 = re.compile(
r'(\d+)?.?\s+?%s\s*((\d+)(/\d+)?)?' % self._mon_str,
re.IGNORECASE)
r"(\d+)?.?\s+?%s\s*((\d+)(/\d+)?)?" % self._mon_str, re.IGNORECASE
)
self._jtext2 = re.compile(
r'(\d+)?.?\s+?%s\s*((\d+)(/\d+)?)?' % self._jmon_str,
re.IGNORECASE)
r"(\d+)?.?\s+?%s\s*((\d+)(/\d+)?)?" % self._jmon_str, re.IGNORECASE
)
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# German display
#
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
class DateDisplayDE(DateDisplay):
"""
German language date display class.
"""
calendar = (
"", "julianisch", "hebräisch",
"französisch republikanisch", "persisch", "islamisch",
"schwedisch"
)
"",
"julianisch",
"hebräisch",
"französisch republikanisch",
"persisch",
"islamisch",
"schwedisch",
)
_mod_str = ("", "vor ", "nach ", "etwa ", "", "", "")
@@ -282,11 +300,15 @@ class DateDisplayDE(DateDisplay):
_bce_str = "%s v. u. Z."
formats = (
"JJJJ-MM-DD (ISO)", "Numerisch", "Monat Tag Jahr",
"MONAT Tag Jahr", "Tag. Monat Jahr", "Tag. MONAT Jahr",
"Numerisch mit führenden Nullen"
)
# this definition must agree with its "_display_gregorian" method
"JJJJ-MM-DD (ISO)",
"Numerisch",
"Monat Tag Jahr",
"MONAT Tag Jahr",
"Tag. Monat Jahr",
"Tag. MONAT Jahr",
"Numerisch mit führenden Nullen",
)
# this definition must agree with its "_display_gregorian" method
def _display_gregorian(self, date_val, **kwargs):
"""
@@ -304,9 +326,9 @@ class DateDisplayDE(DateDisplay):
if date_val[0] == date_val[1] == 0:
value = str(date_val[2])
else:
value = self.dhformat.replace('%m', str(date_val[1]))
value = value.replace('%d', str(date_val[0]))
value = value.replace('%Y', str(date_val[2]))
value = self.dhformat.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_name day, year
if date_val[0] == 0:
@@ -315,8 +337,7 @@ class DateDisplayDE(DateDisplay):
else:
value = "%s %s" % (self.long_months[date_val[1]], year)
else:
value = "%s %d, %s" % (self.long_months[date_val[1]],
date_val[0], year)
value = "%s %d, %s" % (self.long_months[date_val[1]], date_val[0], year)
elif self.format == 3:
# month_abbreviation day, year
if date_val[0] == 0:
@@ -325,8 +346,11 @@ class DateDisplayDE(DateDisplay):
else:
value = "%s %s" % (self.short_months[date_val[1]], year)
else:
value = "%s %d, %s" % (self.short_months[date_val[1]],
date_val[0], year)
value = "%s %d, %s" % (
self.short_months[date_val[1]],
date_val[0],
year,
)
elif self.format == 4:
# day. month_name year
if date_val[0] == 0:
@@ -335,8 +359,7 @@ class DateDisplayDE(DateDisplay):
else:
value = "%s %s" % (self.long_months[date_val[1]], year)
else:
value = "%d. %s %s" % (date_val[0],
self.long_months[date_val[1]], year)
value = "%d. %s %s" % (date_val[0], self.long_months[date_val[1]], year)
elif self.format == 6:
# day.month_number.year with leading zeros
if date_val[3]:
@@ -345,10 +368,9 @@ class DateDisplayDE(DateDisplay):
if date_val[0] == date_val[1] == 0:
value = str(date_val[2])
else:
value = self.dhformat.replace('%m', str(date_val[1])
.zfill(2))
value = value.replace('%d', str(date_val[0]).zfill(2))
value = value.replace('%Y', str(date_val[2]))
value = self.dhformat.replace("%m", str(date_val[1]).zfill(2))
value = value.replace("%d", str(date_val[0]).zfill(2))
value = value.replace("%Y", str(date_val[2]))
else:
# day. month_abbreviation year
if date_val[0] == 0:
@@ -357,8 +379,11 @@ class DateDisplayDE(DateDisplay):
else:
value = "%s %s" % (self.short_months[date_val[1]], year)
else:
value = "%d. %s %s" % (date_val[0],
self.short_months[date_val[1]], year)
value = "%d. %s %s" % (
date_val[0],
self.short_months[date_val[1]],
year,
)
if date_val[2] < 0:
return self._bce_str % value
else:
@@ -384,7 +409,7 @@ class DateDisplayDE(DateDisplay):
d1 = self.display_cal[cal](start)
d2 = self.display_cal[cal](date.get_stop_date())
scal = self.format_extras(cal, newyear)
return "%s%s %s %s %s%s" % (qual_str, 'von', d1, 'bis', d2, scal)
return "%s%s %s %s %s%s" % (qual_str, "von", d1, "bis", d2, scal)
elif mod == Date.MOD_RANGE:
d1 = self.display_cal[cal](start)
d2 = self.display_cal[cal](date.get_stop_date())
@@ -395,13 +420,25 @@ class DateDisplayDE(DateDisplay):
scal = self.format_extras(cal, newyear)
return "%s%s%s%s" % (qual_str, self._mod_str[mod], text, scal)
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# Register classes
#
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
register_datehandler(
('de_DE', 'german', 'German', 'de_CH',
'de_LI', 'de_LU', 'de_BE', 'de', ('%d.%m.%Y',)),
DateParserDE, DateDisplayDE)
register_datehandler( ('de_AT', ('%d.%m.%Y',)), DateParserDE, DateDisplayDE)
(
"de_DE",
"german",
"German",
"de_CH",
"de_LI",
"de_LU",
"de_BE",
"de",
("%d.%m.%Y",),
),
DateParserDE,
DateDisplayDE,
)
register_datehandler(("de_AT", ("%d.%m.%Y",)), DateParserDE, DateDisplayDE)
+122 -86
View File
@@ -24,28 +24,28 @@
Greek-specific classes for parsing and displaying dates.
"""
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# Python modules
#
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
import re
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# Gramps modules
#
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
from ..lib.date import Date
from ._dateparser import DateParser
from ._datedisplay import DateDisplay
from ._datehandler import register_datehandler
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# Greek parser class
#
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
class DateParserEL(DateParser):
"""
Convert a text string into a Date object. If the date cannot be
@@ -54,94 +54,126 @@ class DateParserEL(DateParser):
# modifiers before the date
modifier_to_int = {
'προ του' : Date.MOD_BEFORE,
'πριν το' : Date.MOD_BEFORE,
'πριν από τις' : Date.MOD_BEFORE,
'πριν από την' : Date.MOD_BEFORE,
'πριν από το' : Date.MOD_BEFORE,
'πριν από τον' : Date.MOD_BEFORE,
'προ' : Date.MOD_BEFORE,
'πρ.' : Date.MOD_BEFORE,
'μετά το' : Date.MOD_AFTER,
'μετά από τις' : Date.MOD_AFTER,
'μετά από την' : Date.MOD_AFTER,
'μετά από το' : Date.MOD_AFTER,
'μετά από τον' : Date.MOD_AFTER,
'μετά' : Date.MOD_AFTER,
'μετ.' : Date.MOD_AFTER,
'γύρω στο' : Date.MOD_ABOUT,
'γύρω στον' : Date.MOD_ABOUT,
'γύρω στις' : Date.MOD_ABOUT,
'περίπου το' : Date.MOD_ABOUT,
'περ.' : Date.MOD_ABOUT,
'γυρ.' : Date.MOD_ABOUT,
'~' : Date.MOD_ABOUT,
}
"προ του": Date.MOD_BEFORE,
"πριν το": Date.MOD_BEFORE,
"πριν από τις": Date.MOD_BEFORE,
"πριν από την": Date.MOD_BEFORE,
"πριν από το": Date.MOD_BEFORE,
"πριν από τον": Date.MOD_BEFORE,
"προ": Date.MOD_BEFORE,
"πρ.": Date.MOD_BEFORE,
"μετά το": Date.MOD_AFTER,
"μετά από τις": Date.MOD_AFTER,
"μετά από την": Date.MOD_AFTER,
"μετά από το": Date.MOD_AFTER,
"μετά από τον": Date.MOD_AFTER,
"μετά": Date.MOD_AFTER,
"μετ.": Date.MOD_AFTER,
"γύρω στο": Date.MOD_ABOUT,
"γύρω στον": Date.MOD_ABOUT,
"γύρω στις": Date.MOD_ABOUT,
"περίπου το": Date.MOD_ABOUT,
"περ.": Date.MOD_ABOUT,
"γυρ.": Date.MOD_ABOUT,
"~": Date.MOD_ABOUT,
"from": Date.MOD_FROM,
"to": Date.MOD_TO,
}
bce = ["π.Χ.", "π.Κ.Χ.", "π.Κ.Ε.", "π.Χ" ]
bce = ["π.Χ.", "π.Κ.Χ.", "π.Κ.Ε.", "π.Χ"]
calendar_to_int = {
'γρηγοριανό' : Date.CAL_GREGORIAN,
'γ' : Date.CAL_GREGORIAN,
'ιουλιανό' : Date.CAL_JULIAN,
'ι' : Date.CAL_JULIAN,
'εβραϊκό' : Date.CAL_HEBREW,
'ε' : Date.CAL_HEBREW,
'ισλαμικό' : Date.CAL_ISLAMIC,
'ισλ' : Date.CAL_ISLAMIC,
'γαλλικό' : Date.CAL_FRENCH,
'γαλλικής δημοκρατίας': Date.CAL_FRENCH,
'γ' : Date.CAL_FRENCH,
'περσικό' : Date.CAL_PERSIAN,
'π' : Date.CAL_PERSIAN,
'σουηδικό' : Date.CAL_SWEDISH,
'σ' : Date.CAL_SWEDISH,
}
"γρηγοριανό": Date.CAL_GREGORIAN,
"γ": Date.CAL_GREGORIAN,
"ιουλιανό": Date.CAL_JULIAN,
"ι": Date.CAL_JULIAN,
"εβραϊκό": Date.CAL_HEBREW,
"ε": Date.CAL_HEBREW,
"ισλαμικό": Date.CAL_ISLAMIC,
"ισλ": Date.CAL_ISLAMIC,
"γαλλικό": Date.CAL_FRENCH,
"γαλλικής δημοκρατίας": Date.CAL_FRENCH,
"γ": Date.CAL_FRENCH,
"περσικό": Date.CAL_PERSIAN,
"π": Date.CAL_PERSIAN,
"σουηδικό": Date.CAL_SWEDISH,
"σ": Date.CAL_SWEDISH,
}
quality_to_int = {
'κατʼ εκτίμηση' : Date.QUAL_ESTIMATED,
'εκτιμώμενη' : Date.QUAL_ESTIMATED,
'εκτ.' : Date.QUAL_ESTIMATED,
'εκτ' : Date.QUAL_ESTIMATED,
'υπολογ' : Date.QUAL_CALCULATED,
'υπολογ.' : Date.QUAL_CALCULATED,
'υπολογισμένη' : Date.QUAL_CALCULATED,
'με υπολογισμό' : Date.QUAL_CALCULATED,
}
"κατʼ εκτίμηση": Date.QUAL_ESTIMATED,
"εκτιμώμενη": Date.QUAL_ESTIMATED,
"εκτ.": Date.QUAL_ESTIMATED,
"εκτ": Date.QUAL_ESTIMATED,
"υπολογ": Date.QUAL_CALCULATED,
"υπολογ.": Date.QUAL_CALCULATED,
"υπολογισμένη": Date.QUAL_CALCULATED,
"με υπολογισμό": Date.QUAL_CALCULATED,
}
def init_strings(self):
"""
This method compiles regular expression strings for matching dates.
"""
DateParser.init_strings(self)
_span_1 = ['από']
_span_2 = ['έως']
_range_1 = ['μετ', r'μετ\.', 'μεταξύ']
_range_2 = ['και']
_span_1 = ["από"]
_span_2 = ["έως"]
_range_1 = ["μετ", r"μετ\.", "μεταξύ"]
_range_2 = ["και"]
self._span = re.compile(
r"(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" %
('|'.join(_span_1), '|'.join(_span_2)), re.IGNORECASE)
r"(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)"
% ("|".join(_span_1), "|".join(_span_2)),
re.IGNORECASE,
)
self._range = re.compile(
r"(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" %
('|'.join(_range_1), '|'.join(_range_2)), re.IGNORECASE)
r"(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)"
% ("|".join(_range_1), "|".join(_range_2)),
re.IGNORECASE,
)
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# Greek display
#
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
class DateDisplayEL(DateDisplay):
"""
Greek language date display class.
"""
# this is used to display the 12 gregorian months
long_months = ( "", "Ιανουάριος", "Φεβρουάριος", "Μάρτιος",
"Απρίλιος", "Μάιος", "Ιούνιος",
"Ιούλιος", "Αύγουστος", "Σεπτέμβριος",
"Οκτώβριος", "Νοέμβριος", "Δεκέμβριος" )
short_months = ( "", "Ιαν", "Φεβ", "Μαρ", "Απρ", "Μάι", "Ιουν",
"Ιουλ", "Αύγ", "Σεπ", "Οκτ", "Νοε", "Δεκ" )
# this is used to display the 12 gregorian months
long_months = (
"",
"Ιανουάριος",
"Φεβρουάριος",
"Μάρτιος",
"Απρίλιος",
"Μάιος",
"Ιούνιος",
"Ιούλιος",
"Αύγουστος",
"Σεπτέμβριος",
"Οκτώβριος",
"Νοέμβριος",
"Δεκέμβριος",
)
short_months = (
"",
"Ιαν",
"Φεβ",
"Μαρ",
"Απρ",
"Μάι",
"Ιουν",
"Ιουλ",
"Αύγ",
"Σεπ",
"Οκτ",
"Νοε",
"Δεκ",
)
_mod_str = ("", "προ του ", "μετά το ", "γύρω στο ", "", "", "")
@@ -150,10 +182,13 @@ class DateDisplayEL(DateDisplay):
_bce_str = "%s π.Χ."
formats = (
"ΕΕΕΕ-ΜΜ-ΗΗ (ISO)", "ΗΗ-ΜΜ-ΕΕΕΕ", "ΗΗ/ΜΜ/ΕΕΕΕ",
"ΗΗ Μήνας ΕΕΕΕ", "ΗΗ Μήν ΕΕΕΕ"
)
# this definition must agree with its "_display_gregorian" method
"ΕΕΕΕ-ΜΜ-ΗΗ (ISO)",
"ΗΗ-ΜΜ-ΕΕΕΕ",
"ΗΗ/ΜΜ/ΕΕΕΕ",
"ΗΗ Μήνας ΕΕΕΕ",
"ΗΗ Μήν ΕΕΕΕ",
)
# this definition must agree with its "_display_gregorian" method
def _display_gregorian(self, date_val, **kwargs):
"""
@@ -189,8 +224,7 @@ class DateDisplayEL(DateDisplay):
else:
value = "%s %s" % (self.long_months[date_val[1]], year)
else:
value = "%d %s %s" % (date_val[0],
self.long_months[date_val[1]], year)
value = "%d %s %s" % (date_val[0], self.long_months[date_val[1]], year)
else:
# day month_abbreviation year
if date_val[0] == 0:
@@ -199,8 +233,7 @@ class DateDisplayEL(DateDisplay):
else:
value = "%s %s" % (self.short_months[date_val[1]], year)
else:
value = "%d %s %s" % (date_val[0],
self.short_months[date_val[1]], year)
value = "%d %s %s" % (date_val[0], self.short_months[date_val[1]], year)
if date_val[2] < 0:
return self._bce_str % value
else:
@@ -226,22 +259,25 @@ class DateDisplayEL(DateDisplay):
d1 = self.display_cal[cal](start)
d2 = self.display_cal[cal](date.get_stop_date())
scal = self.format_extras(cal, newyear)
return "%s%s %s %s %s%s" % (qual_str, 'από', d1, 'έως', d2, scal)
return "%s%s %s %s %s%s" % (qual_str, "από", d1, "έως", d2, scal)
elif mod == Date.MOD_RANGE:
d1 = self.display_cal[cal](start)
d2 = self.display_cal[cal](date.get_stop_date())
scal = self.format_extras(cal, newyear)
return "%s%s %s %s %s%s" % (qual_str, 'μεταξύ', d1, 'και', d2, scal)
return "%s%s %s %s %s%s" % (qual_str, "μεταξύ", d1, "και", d2, scal)
else:
text = self.display_cal[date.get_calendar()](start)
scal = self.format_extras(cal, newyear)
return "%s%s%s%s" % (qual_str, self._mod_str[mod], text, scal)
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# Register classes
#
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
register_datehandler(
('el_GR', 'el_CY', 'el', 'Greek', 'greek', ('%d/%m/%Y',)),
DateParserEL, DateDisplayEL)
("el_GR", "el_CY", "el", "Greek", "greek", ("%d/%m/%Y",)),
DateParserEL,
DateDisplayEL,
)
+79 -71
View File
@@ -23,102 +23,105 @@
Spanish-specific classes for parsing and displaying dates.
"""
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# Python modules
#
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
import re
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# Gramps modules
#
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
from ..lib.date import Date
from ._dateparser import DateParser
from ._datedisplay import DateDisplay
from ._datehandler import register_datehandler
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# Spanish parser
#
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
class DateParserES(DateParser):
modifier_to_int = {
'antes de' : Date.MOD_BEFORE,
'antes' : Date.MOD_BEFORE,
'ant.' : Date.MOD_BEFORE,
'ant' : Date.MOD_BEFORE,
'después de' : Date.MOD_AFTER,
'después' : Date.MOD_AFTER,
'desp.' : Date.MOD_AFTER,
'desp' : Date.MOD_AFTER,
'aprox.' : Date.MOD_ABOUT,
'aprox' : Date.MOD_ABOUT,
'apr.' : Date.MOD_ABOUT,
'apr' : Date.MOD_ABOUT,
'circa' : Date.MOD_ABOUT,
'ca.' : Date.MOD_ABOUT,
'ca' : Date.MOD_ABOUT,
'c.' : Date.MOD_ABOUT,
'hacia' : Date.MOD_ABOUT,
}
"antes de": Date.MOD_BEFORE,
"antes": Date.MOD_BEFORE,
"ant.": Date.MOD_BEFORE,
"ant": Date.MOD_BEFORE,
"después de": Date.MOD_AFTER,
"después": Date.MOD_AFTER,
"desp.": Date.MOD_AFTER,
"desp": Date.MOD_AFTER,
"aprox.": Date.MOD_ABOUT,
"aprox": Date.MOD_ABOUT,
"apr.": Date.MOD_ABOUT,
"apr": Date.MOD_ABOUT,
"circa": Date.MOD_ABOUT,
"ca.": Date.MOD_ABOUT,
"ca": Date.MOD_ABOUT,
"c.": Date.MOD_ABOUT,
"hacia": Date.MOD_ABOUT,
"from": Date.MOD_FROM,
"to": Date.MOD_TO,
}
calendar_to_int = {
'gregoriano' : Date.CAL_GREGORIAN,
'g' : Date.CAL_GREGORIAN,
'juliano' : Date.CAL_JULIAN,
'j' : Date.CAL_JULIAN,
'hebreo' : Date.CAL_HEBREW,
'h' : Date.CAL_HEBREW,
'islámico' : Date.CAL_ISLAMIC,
'i' : Date.CAL_ISLAMIC,
'revolucionario' : Date.CAL_FRENCH,
'r' : Date.CAL_FRENCH,
'persa' : Date.CAL_PERSIAN,
'p' : Date.CAL_PERSIAN,
'swedish' : Date.CAL_SWEDISH,
's' : Date.CAL_SWEDISH,
}
"gregoriano": Date.CAL_GREGORIAN,
"g": Date.CAL_GREGORIAN,
"juliano": Date.CAL_JULIAN,
"j": Date.CAL_JULIAN,
"hebreo": Date.CAL_HEBREW,
"h": Date.CAL_HEBREW,
"islámico": Date.CAL_ISLAMIC,
"i": Date.CAL_ISLAMIC,
"revolucionario": Date.CAL_FRENCH,
"r": Date.CAL_FRENCH,
"persa": Date.CAL_PERSIAN,
"p": Date.CAL_PERSIAN,
"swedish": Date.CAL_SWEDISH,
"s": Date.CAL_SWEDISH,
}
quality_to_int = {
'estimado' : Date.QUAL_ESTIMATED,
'est.' : Date.QUAL_ESTIMATED,
'est' : Date.QUAL_ESTIMATED,
'calc.' : Date.QUAL_CALCULATED,
'calc' : Date.QUAL_CALCULATED,
'calculado' : Date.QUAL_CALCULATED,
}
"estimado": Date.QUAL_ESTIMATED,
"est.": Date.QUAL_ESTIMATED,
"est": Date.QUAL_ESTIMATED,
"calc.": Date.QUAL_CALCULATED,
"calc": Date.QUAL_CALCULATED,
"calculado": Date.QUAL_CALCULATED,
}
def init_strings(self):
DateParser.init_strings(self)
_span_1 = ['de']
_span_2 = ['a']
_range_1 = ['entre', r'ent\.', 'ent']
_range_2 = ['y']
_span_1 = ["de"]
_span_2 = ["a"]
_range_1 = ["entre", r"ent\.", "ent"]
_range_2 = ["y"]
self._span = re.compile(
r"(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" %
('|'.join(_span_1), '|'.join(_span_2)), re.IGNORECASE)
r"(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)"
% ("|".join(_span_1), "|".join(_span_2)),
re.IGNORECASE,
)
self._range = re.compile(
r"(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" %
('|'.join(_range_1), '|'.join(_range_2)), re.IGNORECASE)
r"(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)"
% ("|".join(_range_1), "|".join(_range_2)),
re.IGNORECASE,
)
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# Spanish display
#
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
class DateDisplayES(DateDisplay):
"""
Spanish language date display class.
"""
# TODO: Translate these month strings:
long_months = ( "", "enero", "febrero", "marzo", "abril", "mayo",
"junio", "julio", "agosto", "septiembre", "octubre",
"noviembre", "diciembre" )
short_months = ( "", "ene", "feb", "mar", "abr", "may",
"jun", "jul", "ago", "sep", "oct", "nov",
@@ -135,11 +138,15 @@ class DateDisplayES(DateDisplay):
_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"
)
# this must agree with DateDisplayEn's "formats" definition
# (since no locale-specific _display_gregorian exists, here)
"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",
)
# this must agree with DateDisplayEn's "formats" definition
# (since no locale-specific _display_gregorian exists, here)
def display(self, date):
"""
@@ -161,22 +168,23 @@ class DateDisplayES(DateDisplay):
d1 = self.display_cal[cal](start)
d2 = self.display_cal[cal](date.get_stop_date())
scal = self.format_extras(cal, newyear)
return "%s%s %s %s %s%s" % (qual_str, 'de', d1, 'a', d2, scal)
return "%s%s %s %s %s%s" % (qual_str, "de", d1, "a", d2, scal)
elif mod == Date.MOD_RANGE:
d1 = self.display_cal[cal](start)
d2 = self.display_cal[cal](date.get_stop_date())
scal = self.format_extras(cal, newyear)
return "%s%s %s %s %s%s" % (qual_str, 'entre', d1, 'y', d2, scal)
return "%s%s %s %s %s%s" % (qual_str, "entre", d1, "y", d2, scal)
else:
text = self.display_cal[date.get_calendar()](start)
scal = self.format_extras(cal, newyear)
return "%s%s%s%s" % (qual_str, self._mod_str[mod], text, scal)
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# Register classes
#
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
register_datehandler(
('es_ES', 'es', 'spanish', 'Spanish', ('%d/%m/%Y',)),
DateParserES, DateDisplayES)
("es_ES", "es", "spanish", "Spanish", ("%d/%m/%Y",)), DateParserES, DateDisplayES
)
+64 -60
View File
@@ -23,31 +23,31 @@
Finnish-specific classes for parsing and displaying dates.
"""
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# Python modules
#
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
import re
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# Gramps modules
#
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
from ..lib.date import Date
from ._dateparser import DateParser
from ._datedisplay import DateDisplay
from ._datehandler import register_datehandler
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# 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
@@ -58,76 +58,79 @@ class DateParserFI(DateParser):
# examples:
# - ennen 1.1.2005
# - noin 1.1.2005
'ennen' : Date.MOD_BEFORE,
'e.' : Date.MOD_BEFORE,
'noin' : Date.MOD_ABOUT,
'n.' : Date.MOD_ABOUT,
}
"ennen": Date.MOD_BEFORE,
"e.": Date.MOD_BEFORE,
"noin": Date.MOD_ABOUT,
"n.": Date.MOD_ABOUT,
"from": Date.MOD_FROM,
"to": Date.MOD_TO,
}
modifier_after_to_int = {
# examples:
# - 1.1.2005 jälkeen
'jälkeen' : Date.MOD_AFTER,
'j.' : Date.MOD_AFTER,
}
"jälkeen": Date.MOD_AFTER,
"j.": Date.MOD_AFTER,
}
bce = ["ekr.", "ekr"]
calendar_to_int = {
'gregoriaaninen' : Date.CAL_GREGORIAN,
'greg.' : Date.CAL_GREGORIAN,
'juliaaninen' : Date.CAL_JULIAN,
'jul.' : Date.CAL_JULIAN,
'heprealainen' : Date.CAL_HEBREW,
'hepr.' : Date.CAL_HEBREW,
'islamilainen' : Date.CAL_ISLAMIC,
'isl.' : Date.CAL_ISLAMIC,
'ranskan vallankumouksen aikainen': Date.CAL_FRENCH,
'ranskan v.' : Date.CAL_FRENCH,
'persialainen' : Date.CAL_PERSIAN,
'pers.' : Date.CAL_PERSIAN,
'svensk' : Date.CAL_SWEDISH,
's' : Date.CAL_SWEDISH,
}
"gregoriaaninen": Date.CAL_GREGORIAN,
"greg.": Date.CAL_GREGORIAN,
"juliaaninen": Date.CAL_JULIAN,
"jul.": Date.CAL_JULIAN,
"heprealainen": Date.CAL_HEBREW,
"hepr.": Date.CAL_HEBREW,
"islamilainen": Date.CAL_ISLAMIC,
"isl.": Date.CAL_ISLAMIC,
"ranskan vallankumouksen aikainen": Date.CAL_FRENCH,
"ranskan v.": Date.CAL_FRENCH,
"persialainen": Date.CAL_PERSIAN,
"pers.": Date.CAL_PERSIAN,
"svensk": Date.CAL_SWEDISH,
"s": Date.CAL_SWEDISH,
}
quality_to_int = {
'arviolta' : Date.QUAL_ESTIMATED,
'arv.' : Date.QUAL_ESTIMATED,
'laskettuna' : Date.QUAL_CALCULATED,
'lask.' : Date.QUAL_CALCULATED,
}
"arviolta": Date.QUAL_ESTIMATED,
"arv.": Date.QUAL_ESTIMATED,
"laskettuna": Date.QUAL_CALCULATED,
"lask.": Date.QUAL_CALCULATED,
}
def init_strings(self):
DateParser.init_strings(self)
self._text2 = re.compile(r'(\d+)?\.?\s+?%s\.?\s*((\d+)(/\d+)?)?\s*$'
% self._mon_str, re.IGNORECASE)
self._span = re.compile(r"(?P<start>.+)\s+(-)\s+(?P<stop>.+)",
re.IGNORECASE)
self._text2 = re.compile(
r"(\d+)?\.?\s+?%s\.?\s*((\d+)(/\d+)?)?\s*$" % self._mon_str, re.IGNORECASE
)
self._span = re.compile(r"(?P<start>.+)\s+(-)\s+(?P<stop>.+)", re.IGNORECASE)
self._range = re.compile(
r"(vuosien\s*)?(?P<start>.+)\s+ja\s+(?P<stop>.+)\s+välillä",
re.IGNORECASE)
r"(vuosien\s*)?(?P<start>.+)\s+ja\s+(?P<stop>.+)\s+välillä", re.IGNORECASE
)
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# Finnish display
#
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
class DateDisplayFI(DateDisplay):
"""
Finnish language date display class.
"""
_bce_str = "%s ekr."
formats = (
"VVVV-KK-PP (ISO)",
"PP.KK.VVVV",
"Päivä Kuukausi Vuosi" # Day, full month name, year
)
# this definition must agree with its "_display_calendar" method
"Päivä Kuukausi Vuosi", # Day, full month name, year
)
# this definition must agree with its "_display_calendar" method
display = DateDisplay.display_formatted
def _display_calendar(self, date_val, long_months, short_months = None,
inflect=""):
def _display_calendar(self, date_val, long_months, short_months=None, inflect=""):
# this must agree with its locale-specific "formats" definition
if short_months is None:
@@ -159,25 +162,26 @@ class DateDisplayFI(DateDisplay):
return year
else:
if inflect:
return self.format_long_month_year(date_val[1], year,
inflect, long_months)
return self.format_long_month_year(
date_val[1], year, inflect, long_months
)
else:
return "{long_month.f[IN]} {year}".format(
long_month = long_months[date_val[1]],
year = year)
long_month=long_months[date_val[1]], year=year
)
else:
if not hasattr(long_months[date_val[1]], 'f'): # not a Lexeme
return self.dd_dformat01(date_val) # maybe the month is zero
if not hasattr(long_months[date_val[1]], "f"): # not a Lexeme
return self.dd_dformat01(date_val) # maybe the month is zero
return "{day:d}. {long_month.f[P]} {year}".format(
day = date_val[0],
long_month = long_months[date_val[1]],
year = year)
day=date_val[0], long_month=long_months[date_val[1]], year=year
)
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# Register classes
#
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
register_datehandler(
('fi_FI', 'fi', 'finnish', 'Finnish', ('%d.%m.%Y',)),
DateParserFI, DateDisplayFI)
("fi_FI", "fi", "finnish", "Finnish", ("%d.%m.%Y",)), DateParserFI, DateDisplayFI
)
+188 -164
View File
@@ -25,29 +25,29 @@
French-specific classes for parsing and displaying dates.
"""
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# Python modules
#
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
import re
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# Gramps modules
#
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
from ..lib.date import Date
from ._dateparser import DateParser
from ._datedisplay import DateDisplay
from ._datehandler import register_datehandler
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# French parser
#
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
class DateParserFR(DateParser):
"""
Convert a text string into a Date object. If the date cannot be
@@ -57,39 +57,45 @@ class DateParserFR(DateParser):
month_to_int = DateParser.month_to_int
modifier_to_int = {
'avant' : Date.MOD_BEFORE,
'av.' : Date.MOD_BEFORE,
#u'av' : Date.MOD_BEFORE, # Broke Hebrew "Av" month name
#u'<' : Date.MOD_BEFORE, # Worrying about XML/HTML parsing
'après' : Date.MOD_AFTER,
'ap.' : Date.MOD_AFTER,
'ap' : Date.MOD_AFTER,
#u'>' : Date.MOD_AFTER, # Worrying about XML/HTML parsing
'environ' : Date.MOD_ABOUT,
'env.' : Date.MOD_ABOUT,
'env' : Date.MOD_ABOUT,
'circa' : Date.MOD_ABOUT,
'ca.' : Date.MOD_ABOUT,
'ca' : Date.MOD_ABOUT,
'c.' : Date.MOD_ABOUT,
'vers' : Date.MOD_ABOUT,
'~' : Date.MOD_ABOUT,
}
"avant": Date.MOD_BEFORE,
"av.": Date.MOD_BEFORE,
# u'av' : Date.MOD_BEFORE, # Broke Hebrew "Av" month name
# u'<' : Date.MOD_BEFORE, # Worrying about XML/HTML parsing
"après": Date.MOD_AFTER,
"ap.": Date.MOD_AFTER,
"ap": Date.MOD_AFTER,
# u'>' : Date.MOD_AFTER, # Worrying about XML/HTML parsing
"environ": Date.MOD_ABOUT,
"env.": Date.MOD_ABOUT,
"env": Date.MOD_ABOUT,
"circa": Date.MOD_ABOUT,
"ca.": Date.MOD_ABOUT,
"ca": Date.MOD_ABOUT,
"c.": Date.MOD_ABOUT,
"vers": Date.MOD_ABOUT,
"~": Date.MOD_ABOUT,
"from": Date.MOD_FROM,
"to": Date.MOD_TO,
}
quality_to_int = {
'estimée': Date.QUAL_ESTIMATED,
'est.' : Date.QUAL_ESTIMATED,
'est' : Date.QUAL_ESTIMATED,
'calculée': Date.QUAL_CALCULATED,
'calc.' : Date.QUAL_CALCULATED,
'calc' : Date.QUAL_CALCULATED,
'comptée' : Date.QUAL_CALCULATED,
'compt.' : Date.QUAL_CALCULATED,
'compt' : Date.QUAL_CALCULATED,
}
"estimée": Date.QUAL_ESTIMATED,
"est.": Date.QUAL_ESTIMATED,
"est": Date.QUAL_ESTIMATED,
"calculée": Date.QUAL_CALCULATED,
"calc.": Date.QUAL_CALCULATED,
"calc": Date.QUAL_CALCULATED,
"comptée": Date.QUAL_CALCULATED,
"compt.": Date.QUAL_CALCULATED,
"compt": Date.QUAL_CALCULATED,
}
bce = ["avant le calendrier", "avant notre ère", "avant JC",
"avant J.C"] + DateParser.bce
bce = [
"avant le calendrier",
"avant notre ère",
"avant JC",
"avant J.C",
] + DateParser.bce
def init_strings(self):
"""
@@ -104,126 +110,139 @@ class DateParserFR(DateParser):
"""
DateParser.init_strings(self)
DateParser.calendar_to_int.update({
'révolutionnaire' : Date.CAL_FRENCH,
'r' : Date.CAL_FRENCH,
'perse' : Date.CAL_PERSIAN,
})
DateParser.calendar_to_int.update(
{
"révolutionnaire": Date.CAL_FRENCH,
"r": Date.CAL_FRENCH,
"perse": Date.CAL_PERSIAN,
}
)
DateParser.month_to_int.update({
"januaris" : 1,
"januarii" : 1,
"januarius" : 1,
"janer" : 1,
"jänner" : 1,
"jenner" : 1,
"hartmonat" : 1,
"hartung" : 1,
"horn" : 1,
"eismond" : 1,
"februaris" : 2,
"februarii" : 2,
"februarius" : 2,
"hornig" : 2,
"hornung" : 2,
"wintermonat" : 2,
"taumond" : 2,
"narrenmond" : 2,
"martii" : 3,
"martius" : 3,
"lenzing" : 3,
"aprilis" : 4,
"ostermond" : 4,
"maius" : 5,
"maii" : 5,
"maien" : 5,
"bluviose" : 5,
"wonnemond" : 5,
"wiesenmonat" : 5,
"junius" : 6,
"junii" : 6,
"vendose" : 6,
"brachet" : 6,
"julius" : 7,
"julii" : 7,
"heuet" : 7,
"heuert" : 7,
"augustus" : 8,
"augusti" : 8,
"ernting" : 8,
"septembris" : 9,
"7bre" : 9,
"7bris" : 9,
"september" : 9,
"scheidling" : 9,
"october" : 10,
"octobris" : 10,
"8bre" : 10,
"8bris" : 10,
"gilbhard" : 10,
"november" : 11,
"novembris" : 11,
"9bre" : 11,
"9bris" : 11,
"nebelmonat" : 11,
"nebelung" : 11,
"december" : 12,
"decembris" : 12,
"10bre" : 12,
"10bris" : 12,
"xbre" : 12,
"xbris" : 12,
"julmond" : 12,
"christmond" : 12,
})
DateParser.month_to_int.update(
{
"januaris": 1,
"januarii": 1,
"januarius": 1,
"janer": 1,
"jänner": 1,
"jenner": 1,
"hartmonat": 1,
"hartung": 1,
"horn": 1,
"eismond": 1,
"februaris": 2,
"februarii": 2,
"februarius": 2,
"hornig": 2,
"hornung": 2,
"wintermonat": 2,
"taumond": 2,
"narrenmond": 2,
"martii": 3,
"martius": 3,
"lenzing": 3,
"aprilis": 4,
"ostermond": 4,
"maius": 5,
"maii": 5,
"maien": 5,
"bluviose": 5,
"wonnemond": 5,
"wiesenmonat": 5,
"junius": 6,
"junii": 6,
"vendose": 6,
"brachet": 6,
"julius": 7,
"julii": 7,
"heuet": 7,
"heuert": 7,
"augustus": 8,
"augusti": 8,
"ernting": 8,
"septembris": 9,
"7bre": 9,
"7bris": 9,
"september": 9,
"scheidling": 9,
"october": 10,
"octobris": 10,
"8bre": 10,
"8bris": 10,
"gilbhard": 10,
"november": 11,
"novembris": 11,
"9bre": 11,
"9bris": 11,
"nebelmonat": 11,
"nebelung": 11,
"december": 12,
"decembris": 12,
"10bre": 12,
"10bris": 12,
"xbre": 12,
"xbris": 12,
"julmond": 12,
"christmond": 12,
}
)
# This self._numeric is different from the base
# avoid bug gregorian / french calendar conversion (+/-10 days)
self._numeric = re.compile(r"((\d+)[/\. ])?\s*((\d+)[/\.])?\s*(\d+)\s*$")
self._span = re.compile(r"(de)\s+(?P<start>.+)\s+(à)\s+(?P<stop>.+)",
re.IGNORECASE)
self._range = re.compile(r"(entre|ent\.|ent)\s+(?P<start>.+)\s+(et)\s+(?P<stop>.+)",
re.IGNORECASE)
self._span = re.compile(
r"(de)\s+(?P<start>.+)\s+(à)\s+(?P<stop>.+)", re.IGNORECASE
)
self._range = re.compile(
r"(entre|ent\.|ent)\s+(?P<start>.+)\s+(et)\s+(?P<stop>.+)", re.IGNORECASE
)
# This self._text are different from the base
# by adding ".?" after the first date and removing "\s*$" at the end
#gregorian and julian
# gregorian and julian
self._text2 = re.compile(r'(\d+)?.?\s+?%s\s*((\d+)(/\d+)?)?' %
self._mon_str, re.IGNORECASE)
self._text2 = re.compile(
r"(\d+)?.?\s+?%s\s*((\d+)(/\d+)?)?" % self._mon_str, re.IGNORECASE
)
#hebrew
# hebrew
self._jtext2 = re.compile(r'(\d+)?.?\s+?%s\s*((\d+)(/\d+)?)?' %
self._jmon_str, re.IGNORECASE)
self._jtext2 = re.compile(
r"(\d+)?.?\s+?%s\s*((\d+)(/\d+)?)?" % self._jmon_str, re.IGNORECASE
)
#french
# french
self._ftext2 = re.compile(r'(\d+)?.?\s+?%s\s*((\d+)(/\d+)?)?' %
self._fmon_str, re.IGNORECASE)
self._ftext2 = re.compile(
r"(\d+)?.?\s+?%s\s*((\d+)(/\d+)?)?" % self._fmon_str, re.IGNORECASE
)
#persian
# persian
self._ptext2 = re.compile(r'(\d+)?.?\s+?%s\s*((\d+)(/\d+)?)?' %
self._pmon_str, re.IGNORECASE)
self._ptext2 = re.compile(
r"(\d+)?.?\s+?%s\s*((\d+)(/\d+)?)?" % self._pmon_str, re.IGNORECASE
)
#islamic
# islamic
self._itext2 = re.compile(r'(\d+)?.?\s+?%s\s*((\d+)(/\d+)?)?' %
self._imon_str, re.IGNORECASE)
self._itext2 = re.compile(
r"(\d+)?.?\s+?%s\s*((\d+)(/\d+)?)?" % self._imon_str, re.IGNORECASE
)
#swedish
# swedish
self._stext2 = re.compile(r'(\d+)?.?\s+?%s\s*((\d+)(/\d+)?)?' %
self._smon_str, re.IGNORECASE)
self._stext2 = re.compile(
r"(\d+)?.?\s+?%s\s*((\d+)(/\d+)?)?" % self._smon_str, re.IGNORECASE
)
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# French display
#
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
class DateDisplayFR(DateDisplay):
"""
French language date display class.
@@ -232,23 +251,25 @@ class DateDisplayFR(DateDisplay):
_bce_str = "%s avant le calendrier"
def formats_changed(self):
""" Allow overriding so a subclass can modify """
"""Allow overriding so a subclass can modify"""
# Replace the previous "Numérique" by a string which
# do have an explicit meaning: "System default (format)"
example = self.dhformat
example = example.replace('%d', "J")
example = example.replace('%m', "M")
example = example.replace('%Y', "A")
example = example.replace("%d", "J")
example = example.replace("%m", "M")
example = example.replace("%Y", "A")
self.formats = ("AAAA-MM-JJ (ISO)", # 0
"Défaut système (" + example + ")", # 1
"Jour Mois Année", # 2
"Jour MOI Année", # 3
"Jour. Mois Année", # 4
"Jour. MOI Année", # 5
"Mois Jour, Année", # 6
"MOI Jour, Année",) # 7
self.formats = (
"AAAA-MM-JJ (ISO)", # 0
"Défaut système (" + example + ")", # 1
"Jour Mois Année", # 2
"Jour MOI Année", # 3
"Jour. Mois Année", # 4
"Jour. MOI Année", # 5
"Mois Jour, Année", # 6
"MOI Jour, Année",
) # 7
# this definition must agree with its "_display_gregorian" method
def _display_gregorian(self, date_val, **kwargs):
@@ -272,14 +293,14 @@ class DateDisplayFR(DateDisplay):
if date_val[0] == date_val[1] == 0:
value = str(date_val[2])
else:
value = self.dhformat.replace('%m', str(date_val[1]))
value = value.replace('%d', str(date_val[0]))
value = self.dhformat.replace("%m", str(date_val[1]))
value = value.replace("%d", str(date_val[0]))
# base_display :
# value = value.replace('%Y', str(abs(date_val[2])))
# value = value.replace('-', '/')
value = value.replace('%Y', str(date_val[2]))
value = value.replace("%Y", str(date_val[2]))
elif self.format == 2:
# day month_name year
@@ -291,8 +312,7 @@ class DateDisplayFR(DateDisplay):
value = "%s %s" % (self.long_months[date_val[1]], year)
else:
value = "%d %s %s" % (date_val[0],
self.long_months[date_val[1]], year)
value = "%d %s %s" % (date_val[0], self.long_months[date_val[1]], year)
elif self.format == 3:
# day month_abbreviation year
@@ -304,8 +324,7 @@ class DateDisplayFR(DateDisplay):
value = "%s %s" % (self.short_months[date_val[1]], year)
else:
value = "%d %s %s" % (date_val[0],
self.short_months[date_val[1]], year)
value = "%d %s %s" % (date_val[0], self.short_months[date_val[1]], year)
elif self.format == 4:
# day. month_name year
@@ -321,9 +340,7 @@ class DateDisplayFR(DateDisplay):
# value = "%d %s %s" % (date_val[0],
# self.long_months[date_val[1]], year)
value = "%d. %s %s" % (date_val[0],
self.long_months[date_val[1]],
year)
value = "%d. %s %s" % (date_val[0], self.long_months[date_val[1]], year)
elif self.format == 5:
# day. month_abbreviation year
@@ -339,8 +356,11 @@ class DateDisplayFR(DateDisplay):
# value = "%d %s %s" % (date_val[0],
# self.short_months[date_val[1]], year)
value = "%d. %s %s" % (date_val[0],
self.short_months[date_val[1]], year)
value = "%d. %s %s" % (
date_val[0],
self.short_months[date_val[1]],
year,
)
elif self.format == 6:
# month_name day, year
@@ -351,8 +371,7 @@ class DateDisplayFR(DateDisplay):
else:
value = "%s %s" % (self.long_months[date_val[1]], year)
else:
value = "%s %d, %s" % (self.long_months[date_val[1]],
date_val[0], year)
value = "%s %d, %s" % (self.long_months[date_val[1]], date_val[0], year)
elif self.format == 7:
# month_abbreviation day, year
@@ -363,8 +382,11 @@ class DateDisplayFR(DateDisplay):
else:
value = "%s %s" % (self.short_months[date_val[1]], year)
else:
value = "%s %d, %s" % (self.short_months[date_val[1]],
date_val[0], year)
value = "%s %d, %s" % (
self.short_months[date_val[1]],
date_val[0],
year,
)
else:
return self.display_iso(date_val)
@@ -375,13 +397,15 @@ class DateDisplayFR(DateDisplay):
display = DateDisplay.display_formatted
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# Register classes
#
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
register_datehandler(
('fr_FR', 'fr', 'french', 'French', 'fr_CA',
'fr_BE', 'fr_CH', ('%d/%m/%Y',)),
DateParserFR, DateDisplayFR)
("fr_FR", "fr", "french", "French", "fr_CA", "fr_BE", "fr_CH", ("%d/%m/%Y",)),
DateParserFR,
DateDisplayFR,
)
+74 -58
View File
@@ -28,50 +28,51 @@
Croatian-specific classes for parsing and displaying dates.
"""
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# Python modules
#
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
import re
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# Gramps modules
#
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
from ..lib.date import Date
from ._dateparser import DateParser
from ._datedisplay import DateDisplay
from ._datehandler import register_datehandler
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# Croatian parser
#
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
class DateParserHR(DateParser):
modifier_to_int = {
'prije' : Date.MOD_BEFORE,
'pr. ' : Date.MOD_BEFORE,
'poslije' : Date.MOD_AFTER,
'po. ' : Date.MOD_AFTER,
'nakon' : Date.MOD_AFTER,
'na. ' : Date.MOD_AFTER,
'oko' : Date.MOD_ABOUT,
'okolo' : Date.MOD_ABOUT,
'ok. ' : Date.MOD_ABOUT,
}
"prije": Date.MOD_BEFORE,
"pr. ": Date.MOD_BEFORE,
"poslije": Date.MOD_AFTER,
"po. ": Date.MOD_AFTER,
"nakon": Date.MOD_AFTER,
"na. ": Date.MOD_AFTER,
"oko": Date.MOD_ABOUT,
"okolo": Date.MOD_ABOUT,
"ok. ": Date.MOD_ABOUT,
"from": Date.MOD_FROM,
"to": Date.MOD_TO,
}
quality_to_int = {
'približno' : Date.QUAL_ESTIMATED,
'prb.' : Date.QUAL_ESTIMATED,
'izračunato' : Date.QUAL_CALCULATED,
'izr.' : Date.QUAL_CALCULATED,
}
"približno": Date.QUAL_ESTIMATED,
"prb.": Date.QUAL_ESTIMATED,
"izračunato": Date.QUAL_CALCULATED,
"izr.": Date.QUAL_CALCULATED,
}
bce = ["prije nove ere", "prije Krista",
"p.n.e."] + DateParser.bce
bce = ["prije nove ere", "prije Krista", "p.n.e."] + DateParser.bce
def init_strings(self):
"""
@@ -80,71 +81,86 @@ class DateParserHR(DateParser):
DateParser.init_strings(self)
# match 'Day. MONTH year.' format with or without dots
self._text2 = re.compile(r'(\d+)?\.?\s*?%s\.?\s*((\d+)(/\d+)?)?\s*\.?$'
% self._mon_str, re.IGNORECASE)
self._text2 = re.compile(
r"(\d+)?\.?\s*?%s\.?\s*((\d+)(/\d+)?)?\s*\.?$" % self._mon_str,
re.IGNORECASE,
)
# match Day.Month.Year.
self._numeric = re.compile(
r"((\d+)[/\. ])?\s*((\d+)[/\.])?\s*(\d+)\.?$")
self._numeric = re.compile(r"((\d+)[/\. ])?\s*((\d+)[/\.])?\s*(\d+)\.?$")
self._jtext2 = re.compile(r'(\d+)?.?\s+?%s\s*((\d+)(/\d+)?)?'
% self._jmon_str, re.IGNORECASE)
self._jtext2 = re.compile(
r"(\d+)?.?\s+?%s\s*((\d+)(/\d+)?)?" % self._jmon_str, re.IGNORECASE
)
_span_1 = ['od']
_span_2 = ['do']
_range_1 = ['između']
_range_2 = ['i']
self._span = re.compile(r"(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)"
% ('|'.join(_span_1), '|'.join(_span_2)),
re.IGNORECASE)
self._range = re.compile(r"(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)"
% ('|'.join(_range_1), '|'.join(_range_2)),
re.IGNORECASE)
_span_1 = ["od"]
_span_2 = ["do"]
_range_1 = ["između"]
_range_2 = ["i"]
self._span = re.compile(
r"(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)"
% ("|".join(_span_1), "|".join(_span_2)),
re.IGNORECASE,
)
self._range = re.compile(
r"(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)"
% ("|".join(_range_1), "|".join(_range_2)),
re.IGNORECASE,
)
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# Croatian display
#
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
class DateDisplayHR(DateDisplay):
"""
Croatian language date display class.
"""
# TODO fix BUG 7064: non-Gregorian calendars wrongly use BCE notation for negative dates
# TODO fix BUG 7064: non-Gregorian calendars wrongly use BCE notation for negative dates
# not refactoring _bce_str into base class because it'll be gone under #7064
_bce_str = "%s p.n.e."
display = DateDisplay.display_formatted
def format_short_month_year(self, month, year, inflect, short_months):
""" Allow a subclass to modify the year, e.g. add a period """
if not hasattr(short_months[1], 'f'): # not a Lexeme: no inflection
"""Allow a subclass to modify the year, e.g. add a period"""
if not hasattr(short_months[1], "f"): # not a Lexeme: no inflection
return "{short_month} {year}.".format(
short_month = short_months[month], year = year)
short_month=short_months[month], year=year
)
return self.FORMATS_short_month_year[inflect].format(
short_month = short_months[month], year = year)
short_month=short_months[month], year=year
)
def _get_localized_year(self, year):
""" Allow a subclass to modify the year, e.g. add a period """
return year + '.'
"""Allow a subclass to modify the year, e.g. add a period"""
return year + "."
# FIXME probably there should be a Croatian-specific "formats" (and this
# ("American comma") format (and dd_dformat03 too) should be eliminated)
def dd_dformat02(self, date_val, inflect, long_months):
""" month_name day, year """
return DateDisplay.dd_dformat02(
self, date_val, inflect, long_months).replace(' .', '')
"""month_name day, year"""
return DateDisplay.dd_dformat02(self, date_val, inflect, long_months).replace(
" .", ""
)
def dd_dformat04(self, date_val, inflect, long_months):
""" day month_name year """
return DateDisplay.dd_dformat04(
self, date_val, inflect, long_months).replace(' .', '')
"""day month_name year"""
return DateDisplay.dd_dformat04(self, date_val, inflect, long_months).replace(
" .", ""
)
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# Register classes
#
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
register_datehandler(
('hr_HR', 'hr', 'HR', 'croatian', 'Croatian', 'hrvatski', ('%d. %m. %Y.',)),
DateParserHR, DateDisplayHR)
("hr_HR", "hr", "HR", "croatian", "Croatian", "hrvatski", ("%d. %m. %Y.",)),
DateParserHR,
DateDisplayHR,
)
+221 -171
View File
@@ -24,226 +24,233 @@
Hungarian-specific classes for parsing and displaying dates.
"""
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# Python modules
#
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
import re
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# Gramps modules
#
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
from ..lib.date import Date
from ._dateparser import DateParser
from ._datedisplay import DateDisplay
from ._datehandler import register_datehandler
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# Hungarian parser
#
#
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
class DateParserHU(DateParser):
month_to_int = DateParser.month_to_int
month_to_int["-"]=0 #to make the Zero month to work
month_to_int["-"] = 0 # to make the Zero month to work
month_to_int["január"] = 1
month_to_int["jan"] = 1
month_to_int["jan."] = 1
month_to_int["I"] = 1
# month_to_int["i"] = 1
# month_to_int["i"] = 1
month_to_int["február"] = 2
month_to_int["feb"] = 2
month_to_int["feb."] = 2
month_to_int["II"] = 2
# month_to_int["ii"] = 2
# month_to_int["ii"] = 2
month_to_int["március"] = 3
month_to_int["márc"] = 3
month_to_int["márc."] = 3
month_to_int["III"] = 3
# month_to_int["iii"] = 3
# month_to_int["iii"] = 3
month_to_int["április"] = 4
month_to_int["ápr"] = 4
month_to_int["ápr."] = 4
month_to_int["IV"] = 4
# month_to_int["iv"] = 4
# month_to_int["iv"] = 4
month_to_int["május"] = 5
month_to_int["máj"] = 5
month_to_int["máj."] = 5
month_to_int["V"] = 5
# month_to_int["v"] = 5
# month_to_int["v"] = 5
month_to_int["június"] = 6
month_to_int["jún"] = 6
month_to_int["jún."] = 6
month_to_int["VI"] = 6
# month_to_int["vi"] = 6
# month_to_int["vi"] = 6
month_to_int["július"] = 7
month_to_int["júl"] = 7
month_to_int["júl."] = 7
month_to_int["VII"] = 7
# month_to_int["vii"] = 7
# month_to_int["vii"] = 7
month_to_int["augusztus"] = 8
month_to_int["aug"] = 8
month_to_int["aug."] = 8
month_to_int["VIII"] = 8
# month_to_int["viii"] = 8
# month_to_int["viii"] = 8
month_to_int["szeptember"] = 9
month_to_int["szept"] = 9
month_to_int["szept."] = 9
month_to_int["IX"] = 9
# month_to_int["ix"] = 9
# month_to_int["ix"] = 9
month_to_int["október"] = 10
month_to_int["okt"] = 10
month_to_int["okt."] = 10
month_to_int["X"] = 10
# month_to_int["x"] = 10
# month_to_int["x"] = 10
month_to_int["november"] = 11
month_to_int["nov"] = 11
month_to_int["nov."] = 11
month_to_int["XI"] = 11
# month_to_int["xi"] = 11
# month_to_int["xi"] = 11
month_to_int["december"] = 12
month_to_int["dec"] = 12
month_to_int["dec."] = 12
month_to_int["XII"] = 12
# month_to_int["xii"] = 12
# month_to_int["xii"] = 12
#-----------------------------------------------------------------------
#
# Alternative and latin names - not verified
#
#-----------------------------------------------------------------------
# -----------------------------------------------------------------------
#
# Alternative and latin names - not verified
#
# -----------------------------------------------------------------------
# Other common latin names
# month_to_int["januaris"] = 01
# month_to_int["januarii"] = 01
# month_to_int["januarius"] = 01
# month_to_int["februaris"] = 02
# month_to_int["februarii"] = 02
# month_to_int["februarius"] = 02
# month_to_int["martii"] = 03
# month_to_int["martius"] = 03
# month_to_int["aprilis"] = 04
# month_to_int["maius"] = 05
# month_to_int["maii"] = 05
# month_to_int["junius"] = 06
# month_to_int["junii"] = 06
# month_to_int["julius"] = 07
# month_to_int["julii"] = 07
# month_to_int["augustus"] = 08
# month_to_int["augusti"] = 08
# month_to_int["septembris"] = 09
# month_to_int["7bris"] = 09
# month_to_int["september"] = 09
# month_to_int["october"] = 10
# month_to_int["octobris"] = 10
# month_to_int["8bris"] = 10
# month_to_int["novembris"] = 11
# month_to_int["9bris"] = 11
# month_to_int["november"] = 11
# month_to_int["decembris"] = 12
# month_to_int["10bris"] = 12
# month_to_int["xbris"] = 12
# month_to_int["december"] = 12
# month_to_int["januaris"] = 01
# month_to_int["januarii"] = 01
# month_to_int["januarius"] = 01
# month_to_int["februaris"] = 02
# month_to_int["februarii"] = 02
# month_to_int["februarius"] = 02
# month_to_int["martii"] = 03
# month_to_int["martius"] = 03
# month_to_int["aprilis"] = 04
# month_to_int["maius"] = 05
# month_to_int["maii"] = 05
# month_to_int["junius"] = 06
# month_to_int["junii"] = 06
# month_to_int["julius"] = 07
# month_to_int["julii"] = 07
# month_to_int["augustus"] = 08
# month_to_int["augusti"] = 08
# month_to_int["septembris"] = 09
# month_to_int["7bris"] = 09
# month_to_int["september"] = 09
# month_to_int["october"] = 10
# month_to_int["octobris"] = 10
# month_to_int["8bris"] = 10
# month_to_int["novembris"] = 11
# month_to_int["9bris"] = 11
# month_to_int["november"] = 11
# month_to_int["decembris"] = 12
# month_to_int["10bris"] = 12
# month_to_int["xbris"] = 12
# month_to_int["december"] = 12
# old Hungarian names
# month_to_int["Boldogasszony hava"] = 01
# month_to_int["Fergeteg hava"] = 01
# month_to_int["Böjtelő hava"] = 02
# month_to_int["Jégbontó hava"] = 02
# month_to_int["Böjtmás hava"] = 03
# month_to_int["Kikelet hava"] = 03
# month_to_int["Szent György hava"] = 04
# month_to_int["Szelek hava"] = 04
# month_to_int["Pünkösd hava"] = 05
# month_to_int["Ígéret hava"] = 05
# month_to_int["Szent Iván hava"] = 06
# month_to_int["Napisten hava"] = 06
# month_to_int["Szent Jakab hava"] = 07
# month_to_int["Áldás hava"] = 07
# month_to_int["Kisasszony hava"] = 08
# month_to_int["Újkenyér hava"] = 08
# month_to_int["Szent Mihály hava"] = 09
# month_to_int["Földanya hava"] = 09
# month_to_int["Mindszent hava"] = 10
# month_to_int["Magvető hava"] = 10
# month_to_int["Szent András hava"] = 11
# month_to_int["Enyészet hava"] = 11
# month_to_int["Karácsony hava"] = 12
# month_to_int["Álom hava"] = 12
# month_to_int["Boldogasszony hava"] = 01
# month_to_int["Fergeteg hava"] = 01
# month_to_int["Böjtelő hava"] = 02
# month_to_int["Jégbontó hava"] = 02
# month_to_int["Böjtmás hava"] = 03
# month_to_int["Kikelet hava"] = 03
# month_to_int["Szent György hava"] = 04
# month_to_int["Szelek hava"] = 04
# month_to_int["Pünkösd hava"] = 05
# month_to_int["Ígéret hava"] = 05
# month_to_int["Szent Iván hava"] = 06
# month_to_int["Napisten hava"] = 06
# month_to_int["Szent Jakab hava"] = 07
# month_to_int["Áldás hava"] = 07
# month_to_int["Kisasszony hava"] = 08
# month_to_int["Újkenyér hava"] = 08
# month_to_int["Szent Mihály hava"] = 09
# month_to_int["Földanya hava"] = 09
# month_to_int["Mindszent hava"] = 10
# month_to_int["Magvető hava"] = 10
# month_to_int["Szent András hava"] = 11
# month_to_int["Enyészet hava"] = 11
# month_to_int["Karácsony hava"] = 12
# month_to_int["Álom hava"] = 12
modifier_to_int = {
'előtt' : Date.MOD_BEFORE,
'körül' : Date.MOD_ABOUT,
'után' : Date.MOD_AFTER,
}
"előtt": Date.MOD_BEFORE,
"körül": Date.MOD_ABOUT,
"után": Date.MOD_AFTER,
"from": Date.MOD_FROM,
"to": Date.MOD_TO,
}
quality_to_int = {
'becsült' : Date.QUAL_ESTIMATED,
'hozzávetőleg' : Date.QUAL_ESTIMATED,
'becs.' : Date.QUAL_ESTIMATED,
'számított' : Date.QUAL_CALCULATED,
'körülbelül' : Date.QUAL_ESTIMATED,
'számolt' : Date.QUAL_CALCULATED,
'szám.' : Date.QUAL_CALCULATED,
}
bce = ["időszámításunk előtt", "időszámítás előtt", "i. e.",
"Krisztus előtt", "Krisztus előtti", "Kr. e."] + DateParser.bce
"becsült": Date.QUAL_ESTIMATED,
"hozzávetőleg": Date.QUAL_ESTIMATED,
"becs.": Date.QUAL_ESTIMATED,
"számított": Date.QUAL_CALCULATED,
"körülbelül": Date.QUAL_ESTIMATED,
"számolt": Date.QUAL_CALCULATED,
"szám.": Date.QUAL_CALCULATED,
}
bce = [
"időszámításunk előtt",
"időszámítás előtt",
"i. e.",
"Krisztus előtt",
"Krisztus előtti",
"Kr. e.",
] + DateParser.bce
calendar_to_int = {
'Gergely' : Date.CAL_GREGORIAN,
'Julián' : Date.CAL_JULIAN,
'julián' : Date.CAL_JULIAN,
'héber' : Date.CAL_HEBREW,
'iszlám' : Date.CAL_ISLAMIC,
'francia köztársasági' : Date.CAL_FRENCH,
'perzsa' : Date.CAL_PERSIAN,
'svéd' : Date.CAL_SWEDISH,
}
"Gergely": Date.CAL_GREGORIAN,
"Julián": Date.CAL_JULIAN,
"julián": Date.CAL_JULIAN,
"héber": Date.CAL_HEBREW,
"iszlám": Date.CAL_ISLAMIC,
"francia köztársasági": Date.CAL_FRENCH,
"perzsa": Date.CAL_PERSIAN,
"svéd": Date.CAL_SWEDISH,
}
def init_strings(self):
# Compiles regular expression strings for matching dates
DateParser.init_strings(self)
self._numeric = re.compile(
r"((\d+)[/\.])?\s*((\d+)[/\.])?\s*(\d+)[/\. ]?$")
self._numeric = re.compile(r"((\d+)[/\.])?\s*((\d+)[/\.])?\s*(\d+)[/\. ]?$")
# this next RE has the (possibly-slashed) year at the string's start
self._text2 = re.compile(r'((\d+)(/\d+)?\.)?\s+?%s\.?\s*(\d+\.)?\s*$'
% self._mon_str, re.IGNORECASE)
_span_1 = [r'-tó\\)l', '-tól', '-től']
_span_2 = ['-ig']
_range_1 = ['és']
_range_2 = ['között']
self._span = re.compile(r"(?P<start>.+)(%s)\s+(?P<stop>.+)(%s)" %
('|'.join(_span_1), '|'.join(_span_2)),
re.IGNORECASE)
self._range = re.compile(r"(?P<start>.+)\s+(%s)\s+(?P<stop>.+)\s+(%s)"
% ('|'.join(_range_1), '|'.join(_range_2)),
re.IGNORECASE)
self._text2 = re.compile(
r"((\d+)(/\d+)?\.)?\s+?%s\.?\s*(\d+\.)?\s*$" % self._mon_str, re.IGNORECASE
)
_span_1 = [r"-tó\\)l", "-tól", "-től"]
_span_2 = ["-ig"]
_range_1 = ["és"]
_range_2 = ["között"]
self._span = re.compile(
r"(?P<start>.+)(%s)\s+(?P<stop>.+)(%s)"
% ("|".join(_span_1), "|".join(_span_2)),
re.IGNORECASE,
)
self._range = re.compile(
r"(?P<start>.+)\s+(%s)\s+(?P<stop>.+)\s+(%s)"
% ("|".join(_range_1), "|".join(_range_2)),
re.IGNORECASE,
)
def _get_int(self, val):
"""
@@ -253,13 +260,14 @@ class DateParserHU(DateParser):
if val is None:
return 0
else:
return int(val.replace('.', ''))
return int(val.replace(".", ""))
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# Hungarian display
#
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
class DateDisplayHU(DateDisplay):
"""
Hungarian language date display class.
@@ -267,24 +275,34 @@ class DateDisplayHU(DateDisplay):
_bce_str = "i. e. %s"
roman_months=(
"-.", "I.", "II.", "III.", "IV.", "V.", "VI.",
"VII.", "VIII.", "IX.", "X.", "XI.", "XII."
)
roman_months = (
"-.",
"I.",
"II.",
"III.",
"IV.",
"V.",
"VI.",
"VII.",
"VIII.",
"IX.",
"X.",
"XI.",
"XII.",
)
formats = (
"ÉÉÉÉ-HH-NN (ISO)", # 0
"Alapértelmezett éééé. hh. nn.", # 1
"Év hónap nap", # year, full month name, day # 2
"Év hó nap", #year, short month name, day # 3
"Év római h.sz. nap" #year, Roman number, day # 4
)
# this definition must agree with its "_display_calendar" method
"ÉÉÉÉ-HH-NN (ISO)", # 0
"Alapértelmezett éééé. hh. nn.", # 1
"Év hónap nap", # year, full month name, day # 2
"Év hó nap", # year, short month name, day # 3
"Év római h.sz. nap", # year, Roman number, day # 4
)
# this definition must agree with its "_display_calendar" method
display = DateDisplay.display_formatted
def _display_calendar(self, date_val, long_months, short_months = None,
inflect=""):
def _display_calendar(self, date_val, long_months, short_months=None, inflect=""):
# this must agree with its locale-specific "formats" definition
year = self._slash_year(date_val[2], date_val[3])
@@ -301,55 +319,84 @@ class DateDisplayHU(DateDisplay):
if date_val[3]:
return self.display_iso(date_val)
else:
if date_val[0]==0: #No day
if date_val[1]==0: #No month -> year
value="%s" % year
if date_val[0] == 0: # No day
if date_val[1] == 0: # No month -> year
value = "%s" % year
else:
value="%s. %02d." % (year, date_val[1]) #If no day -> year, month
value = "%s. %02d." % (
year,
date_val[1],
) # If no day -> year, month
else:
value="%s. %02d. %02d." % (year, date_val[1], date_val[0])
value = "%s. %02d. %02d." % (year, date_val[1], date_val[0])
elif self.format == 2:
# year, full month name, day
if date_val[0]==0:
if date_val[1]==0:
value="%s" % year
if date_val[0] == 0:
if date_val[1] == 0:
value = "%s" % year
else:
value="%s. %s" % (year, self.long_months[date_val[1]]) #If no day -> year, month
value = "%s. %s" % (
year,
self.long_months[date_val[1]],
) # If no day -> year, month
else:
if date_val[1]==0:
value="%s. %s %02d." % (year, '-', date_val[0]) #To indicate somehow if the month is missing
else:
value="%s. %s %02d." % (year, self.long_months[date_val[1]], date_val[0])
if date_val[1] == 0:
value = "%s. %s %02d." % (
year,
"-",
date_val[0],
) # To indicate somehow if the month is missing
else:
value = "%s. %s %02d." % (
year,
self.long_months[date_val[1]],
date_val[0],
)
elif self.format == 3:
#year, short month name, day
# year, short month name, day
if date_val[0]==0:
if date_val[1]==0:
value="%s" % year
if date_val[0] == 0:
if date_val[1] == 0:
value = "%s" % year
else:
value="%s. %s" % (year, self.short_months[date_val[1]]) #If no day -> year, month
value = "%s. %s" % (
year,
self.short_months[date_val[1]],
) # If no day -> year, month
else:
if date_val[1]==0:
value="%s. %s %02d." % (year, '-.', date_val[0]) #To indicate somehow if the month is missing
else:
value="%s. %s %02d." % (year, self.short_months[date_val[1]], date_val[0])
if date_val[1] == 0:
value = "%s. %s %02d." % (
year,
"-.",
date_val[0],
) # To indicate somehow if the month is missing
else:
value = "%s. %s %02d." % (
year,
self.short_months[date_val[1]],
date_val[0],
)
elif self.format == 4:
#year, Roman number, day
# year, Roman number, day
if date_val[0]==0:
if date_val[1]==0:
value="%s" % year
if date_val[0] == 0:
if date_val[1] == 0:
value = "%s" % year
else:
value="%s. %s" % (year, self.roman_months[date_val[1]]) #If no day -> year, month
value = "%s. %s" % (
year,
self.roman_months[date_val[1]],
) # If no day -> year, month
else:
value="%s. %s %02d." % (year, self.roman_months[date_val[1]], date_val[0])
value = "%s. %s %02d." % (
year,
self.roman_months[date_val[1]],
date_val[0],
)
else:
# day month_name year
@@ -361,11 +408,14 @@ class DateDisplayHU(DateDisplay):
else:
return value
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# Register classes
#
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
register_datehandler(
('hu_HU', 'hu', 'hungarian', 'Hungarian', 'magyar', ('%Y-%m-%d',)),
DateParserHU, DateDisplayHU)
("hu_HU", "hu", "hungarian", "Hungarian", "magyar", ("%Y-%m-%d",)),
DateParserHU,
DateDisplayHU,
)
+109 -74
View File
@@ -24,29 +24,29 @@
Icelandic-specific classes for parsing and displaying dates.
"""
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# Python modules
#
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
import re
import datetime
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# Gramps modules
#
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
from ..lib.date import Date
from ._dateparser import DateParser
from ._datedisplay import DateDisplay
from ._datehandler import register_datehandler
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# Icelandic parser class
#
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
class DateParserIs(DateParser):
"""
Convert a text string into a Date object, expecting a date
@@ -56,39 +56,41 @@ class DateParserIs(DateParser):
# modifiers before the date
modifier_to_int = {
'fyrir' : Date.MOD_BEFORE,
'á undan' : Date.MOD_BEFORE,
'eftir' : Date.MOD_AFTER,
'í kringum' : Date.MOD_ABOUT,
'uþb' : Date.MOD_ABOUT,
'um' : Date.MOD_ABOUT,
}
"fyrir": Date.MOD_BEFORE,
"á undan": Date.MOD_BEFORE,
"eftir": Date.MOD_AFTER,
"í kringum": Date.MOD_ABOUT,
"uþb": Date.MOD_ABOUT,
"um": Date.MOD_ABOUT,
"from": Date.MOD_FROM,
"to": Date.MOD_TO,
}
bce = ["f Kr"]
calendar_to_int = {
'gregoríanskt ' : Date.CAL_GREGORIAN,
'g' : Date.CAL_GREGORIAN,
'júlíanskt' : Date.CAL_JULIAN,
'j' : Date.CAL_JULIAN,
'hebreskt' : Date.CAL_HEBREW,
'h' : Date.CAL_HEBREW,
'íslamskt' : Date.CAL_ISLAMIC,
'múslimskt' : Date.CAL_ISLAMIC,
'i' : Date.CAL_ISLAMIC,
'franskt' : Date.CAL_FRENCH,
'franska lýðveldisins' : Date.CAL_FRENCH,
'f' : Date.CAL_FRENCH,
'persneskt' : Date.CAL_PERSIAN,
'p' : Date.CAL_PERSIAN,
'sænskt' : Date.CAL_SWEDISH,
's' : Date.CAL_SWEDISH,
}
"gregoríanskt ": Date.CAL_GREGORIAN,
"g": Date.CAL_GREGORIAN,
"júlíanskt": Date.CAL_JULIAN,
"j": Date.CAL_JULIAN,
"hebreskt": Date.CAL_HEBREW,
"h": Date.CAL_HEBREW,
"íslamskt": Date.CAL_ISLAMIC,
"múslimskt": Date.CAL_ISLAMIC,
"i": Date.CAL_ISLAMIC,
"franskt": Date.CAL_FRENCH,
"franska lýðveldisins": Date.CAL_FRENCH,
"f": Date.CAL_FRENCH,
"persneskt": Date.CAL_PERSIAN,
"p": Date.CAL_PERSIAN,
"sænskt": Date.CAL_SWEDISH,
"s": Date.CAL_SWEDISH,
}
quality_to_int = {
'áætlað' : Date.QUAL_ESTIMATED,
'reiknað' : Date.QUAL_CALCULATED,
}
"áætlað": Date.QUAL_ESTIMATED,
"reiknað": Date.QUAL_CALCULATED,
}
def dhformat_changed(self):
self._dhformat_parse = re.compile(r".*%(\S).*%(\S).*%(\S).*%(\S).*")
@@ -97,34 +99,63 @@ class DateParserIs(DateParser):
DateParser.init_strings(self)
# match 'day. month year' format
self._text2 = re.compile(r'(\d+)?\.?\s*?%s\.?\s*((\d+)(/\d+)?)?\s*$'
% self._mon_str, re.IGNORECASE)
self._text2 = re.compile(
r"(\d+)?\.?\s*?%s\.?\s*((\d+)(/\d+)?)?\s*$" % self._mon_str, re.IGNORECASE
)
# match 'short-day day.month year' format
short_day_str = '(' + '|'.join(self._ds.short_days[1:]) + ')'
self._numeric = re.compile(r"%s\s*((\d+)[\.]\s*)?((\d+)\s*)?(\d+)\s*$"
% short_day_str, re.IGNORECASE)
short_day_str = "(" + "|".join(self._ds.short_days[1:]) + ")"
self._numeric = re.compile(
r"%s\s*((\d+)[\.]\s*)?((\d+)\s*)?(\d+)\s*$" % short_day_str, re.IGNORECASE
)
self._span = re.compile(
r"(frá)?\s*(?P<start>.+)\s*(til|--|)\s*(?P<stop>.+)",
re.IGNORECASE)
r"(frá)?\s*(?P<start>.+)\s*(til|--|)\s*(?P<stop>.+)", re.IGNORECASE
)
self._range = re.compile(
r"(milli)\s+(?P<start>.+)\s+og\s+(?P<stop>.+)", re.IGNORECASE)
r"(milli)\s+(?P<start>.+)\s+og\s+(?P<stop>.+)", re.IGNORECASE
)
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# Icelandic display class
#
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
class DateDisplayIs(DateDisplay):
"""
Icelandic language date display class.
"""
long_months = ( "", "janúar", "febrúar", "mars", "apríl", "maí",
"júní", "júlí", "ágúst", "september", "október",
"nóvember", "desember" )
long_months = (
"",
"janúar",
"febrúar",
"mars",
"apríl",
"maí",
"júní",
"júlí",
"ágúst",
"september",
"október",
"nóvember",
"desember",
)
short_months = ( "", "jan", "feb", "mar", "apr", "maí", "jún",
"júl", "ágú", "sep", "okt", "nóv", "des" )
short_months = (
"",
"jan",
"feb",
"mar",
"apr",
"maí",
"jún",
"júl",
"ágú",
"sep",
"okt",
"nóv",
"des",
)
formats = (
"ÁÁÁÁ-MM-DD (ISO)",
@@ -133,9 +164,9 @@ class DateDisplayIs(DateDisplay):
"Mán Dag Ár",
"Dagur mánuður ár",
"Dag Mán Ár",
)
# this must agree with DateDisplayEn's "formats" definition
# (since no locale-specific _display_gregorian exists, here)
)
# this must agree with DateDisplayEn's "formats" definition
# (since no locale-specific _display_gregorian exists, here)
calendar = (
"",
@@ -144,8 +175,8 @@ class DateDisplayIs(DateDisplay):
"franska lýðveldisins",
"persneskt",
"íslamskt",
"sænskt"
)
"sænskt",
)
_mod_str = ("", "fyrir ", "eftir ", "uþb ", "", "", "")
@@ -178,19 +209,20 @@ class DateDisplayIs(DateDisplay):
d1 = self.display_cal[cal](start)
d2 = self.display_cal[cal](date.get_stop_date())
scal = self.format_extras(cal, newyear)
return "%smilli %s og %s%s" % (qual_str, d1, d2,
scal)
return "%smilli %s og %s%s" % (qual_str, d1, d2, scal)
else:
text = self.display_cal[date.get_calendar()](start)
scal = self.format_extras(cal, newyear)
return "%s%s%s%s" % (qual_str, self._mod_str[mod],
text, scal)
return "%s%s%s%s" % (qual_str, self._mod_str[mod], text, scal)
def _get_weekday(self, date_val):
if (date_val[0] == 0 or date_val[1] == 0 # no day or no month or both
or date_val[2] > datetime.MAXYEAR): # bug 10815
return ''
w_day = datetime.date(date_val[2], date_val[1], date_val[0]) # y, m, d
if (
date_val[0] == 0
or date_val[1] == 0 # no day or no month or both
or date_val[2] > datetime.MAXYEAR
): # bug 10815
return ""
w_day = datetime.date(date_val[2], date_val[1], date_val[0]) # y, m, d
return self.short_days[((w_day.weekday() + 1) % 7) + 1]
def dd_dformat01(self, date_val):
@@ -203,23 +235,26 @@ class DateDisplayIs(DateDisplay):
if date_val[0] == date_val[1] == 0:
return str(date_val[2])
else:
value = self.dhformat.replace('%m', str(date_val[1]))
value = self.dhformat.replace("%m", str(date_val[1]))
# some locales have %b for the month, e.g. ar_EG, is_IS, nb_NO
value = value.replace('%b', str(date_val[1]))
value = value.replace("%b", str(date_val[1]))
# some locales have %a for the abbreviated day, e.g. is_IS
value = value.replace('%a', self._get_weekday(date_val))
if date_val[0] == 0: # ignore the zero day and its delimiter
i_day = value.find('%e') # Icelandic uses %e and not %d
value = value.replace(value[i_day:i_day+3], '')
value = value.replace('%e', str(date_val[0]))
value = value.replace('%Y', str(abs(date_val[2])))
return value.replace('-', '/')
value = value.replace("%a", self._get_weekday(date_val))
if date_val[0] == 0: # ignore the zero day and its delimiter
i_day = value.find("%e") # Icelandic uses %e and not %d
value = value.replace(value[i_day : i_day + 3], "")
value = value.replace("%e", str(date_val[0]))
value = value.replace("%Y", str(abs(date_val[2])))
return value.replace("-", "/")
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# Register classes
#
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
register_datehandler(
('is_IS', 'is', 'íslenskt', 'Icelandic', ('%a %e.%b %Y',)),
DateParserIs, DateDisplayIs)
("is_IS", "is", "íslenskt", "Icelandic", ("%a %e.%b %Y",)),
DateParserIs,
DateDisplayIs,
)
+131 -87
View File
@@ -25,133 +25,174 @@
Italian-specific classes for parsing and displaying dates.
"""
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# Python modules
#
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
import re
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# Gramps modules
#
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
from ..lib.date import Date
from ._dateparser import DateParser
from ._datedisplay import DateDisplay
from ._datehandler import register_datehandler
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# Italian parser
#
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
class DateParserIT(DateParser):
modifier_to_int = {
'prima del' : Date.MOD_BEFORE,
'prima' : Date.MOD_BEFORE,
'dopo del' : Date.MOD_AFTER,
'dopo' : Date.MOD_AFTER,
'approssimativamente' : Date.MOD_ABOUT,
'apross.' : Date.MOD_ABOUT,
'apross' : Date.MOD_ABOUT,
'circa il' : Date.MOD_ABOUT,
'circa' : Date.MOD_ABOUT,
'ca.' : Date.MOD_ABOUT,
'ca' : Date.MOD_ABOUT,
'c.' : Date.MOD_ABOUT,
}
"prima del": Date.MOD_BEFORE,
"prima": Date.MOD_BEFORE,
"dopo del": Date.MOD_AFTER,
"dopo": Date.MOD_AFTER,
"approssimativamente": Date.MOD_ABOUT,
"apross.": Date.MOD_ABOUT,
"apross": Date.MOD_ABOUT,
"circa il": Date.MOD_ABOUT,
"circa": Date.MOD_ABOUT,
"ca.": Date.MOD_ABOUT,
"ca": Date.MOD_ABOUT,
"c.": Date.MOD_ABOUT,
"from": Date.MOD_FROM,
"to": Date.MOD_TO,
}
calendar_to_int = {
'gregoriano' : Date.CAL_GREGORIAN,
'g' : Date.CAL_GREGORIAN,
'giuliano' : Date.CAL_JULIAN,
'j' : Date.CAL_JULIAN,
'ebraico' : Date.CAL_HEBREW,
'e' : Date.CAL_HEBREW,
'islamico' : Date.CAL_ISLAMIC,
'i' : Date.CAL_ISLAMIC,
'rivoluzionario': Date.CAL_FRENCH,
'r' : Date.CAL_FRENCH,
'persiano' : Date.CAL_PERSIAN,
'p' : Date.CAL_PERSIAN,
'svedese' : Date.CAL_SWEDISH,
's' : Date.CAL_SWEDISH,
}
"gregoriano": Date.CAL_GREGORIAN,
"g": Date.CAL_GREGORIAN,
"giuliano": Date.CAL_JULIAN,
"j": Date.CAL_JULIAN,
"ebraico": Date.CAL_HEBREW,
"e": Date.CAL_HEBREW,
"islamico": Date.CAL_ISLAMIC,
"i": Date.CAL_ISLAMIC,
"rivoluzionario": Date.CAL_FRENCH,
"r": Date.CAL_FRENCH,
"persiano": Date.CAL_PERSIAN,
"p": Date.CAL_PERSIAN,
"svedese": Date.CAL_SWEDISH,
"s": Date.CAL_SWEDISH,
}
quality_to_int = {
'stimata' : Date.QUAL_ESTIMATED,
'st.' : Date.QUAL_ESTIMATED,
'st' : Date.QUAL_ESTIMATED,
'calcolata' : Date.QUAL_CALCULATED,
'calc.' : Date.QUAL_CALCULATED,
'calc' : Date.QUAL_CALCULATED,
}
"stimata": Date.QUAL_ESTIMATED,
"st.": Date.QUAL_ESTIMATED,
"st": Date.QUAL_ESTIMATED,
"calcolata": Date.QUAL_CALCULATED,
"calc.": Date.QUAL_CALCULATED,
"calc": Date.QUAL_CALCULATED,
}
def init_strings(self):
DateParser.init_strings(self)
_span_1 = ['dal', 'da']
_span_2 = ['al', 'a']
_range_1 = ['tra', 'fra']
_range_2 = ['e']
self._span = re.compile(r"(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" %
('|'.join(_span_1), '|'.join(_span_2)),
re.IGNORECASE)
_span_1 = ["dal", "da"]
_span_2 = ["al", "a"]
_range_1 = ["tra", "fra"]
_range_2 = ["e"]
self._span = re.compile(
r"(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)"
% ("|".join(_span_1), "|".join(_span_2)),
re.IGNORECASE,
)
self._range = re.compile(
r"(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" %
('|'.join(_range_1), '|'.join(_range_2)), re.IGNORECASE)
r"(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)"
% ("|".join(_range_1), "|".join(_range_2)),
re.IGNORECASE,
)
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# Italian display
#
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
class DateDisplayIT(DateDisplay):
"""
Italian language date display class.
"""
long_months = ( "", "gennaio", "febbraio", "marzo", "aprile",
"maggio", "giugno", "luglio", "agosto", "settembre",
"ottobre", "novembre", "dicembre" )
short_months = ( "", "gen", "feb", "mar", "apr", "mag", "giu",
"lug", "ago", "set", "ott", "nov", "dic" )
long_months = (
"",
"gennaio",
"febbraio",
"marzo",
"aprile",
"maggio",
"giugno",
"luglio",
"agosto",
"settembre",
"ottobre",
"novembre",
"dicembre",
)
short_months = (
"",
"gen",
"feb",
"mar",
"apr",
"mag",
"giu",
"lug",
"ago",
"set",
"ott",
"nov",
"dic",
)
calendar = (
"", "Giuliano", "Ebraico",
"Rivoluzionario", "Persiano", "Islamico",
"Svedese"
)
"",
"Giuliano",
"Ebraico",
"Rivoluzionario",
"Persiano",
"Islamico",
"Svedese",
)
_mod_str = ("", "prima del ", "dopo del ", "circa il ", "", "", "")
_qual_str = ("", "stimata ", "calcolata ")
french = (
'',
'vendemmiaio',
'brumaio',
'frimaio',
'nevoso',
'piovoso',
'ventoso',
'germile',
'fiorile',
'pratile',
'messidoro',
'termidoro',
'fruttidoro',
'extra',
)
"",
"vendemmiaio",
"brumaio",
"frimaio",
"nevoso",
"piovoso",
"ventoso",
"germile",
"fiorile",
"pratile",
"messidoro",
"termidoro",
"fruttidoro",
"extra",
)
formats = (
"AAAA-MM-DD (ISO)", "Numerico", "Mese Giorno Anno",
"MES Giorno, Anno", "Giorno Mese Anno", "Giorno MES Anno"
)
# this must agree with DateDisplayEn's "formats" definition
# (since no locale-specific _display_gregorian exists, here)
"AAAA-MM-DD (ISO)",
"Numerico",
"Mese Giorno Anno",
"MES Giorno, Anno",
"Giorno Mese Anno",
"Giorno MES Anno",
)
# this must agree with DateDisplayEn's "formats" definition
# (since no locale-specific _display_gregorian exists, here)
def display(self, date):
"""
@@ -173,22 +214,25 @@ class DateDisplayIT(DateDisplay):
d1 = self.display_cal[cal](start)
d2 = self.display_cal[cal](date.get_stop_date())
scal = self.format_extras(cal, newyear)
return "%s%s %s %s %s%s" % (qual_str, 'dal', d1, 'al', d2, scal)
return "%s%s %s %s %s%s" % (qual_str, "dal", d1, "al", d2, scal)
elif mod == Date.MOD_RANGE:
d1 = self.display_cal[cal](start)
d2 = self.display_cal[cal](date.get_stop_date())
scal = self.format_extras(cal, newyear)
return "%s%s %s %s %s%s" % (qual_str, 'tra', d1, 'e', d2, scal)
return "%s%s %s %s %s%s" % (qual_str, "tra", d1, "e", d2, scal)
else:
text = self.display_cal[date.get_calendar()](start)
scal = self.format_extras(cal, newyear)
return "%s%s%s%s" % (qual_str, self._mod_str[mod], text, scal)
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# Register classes
#
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
register_datehandler(
('it_IT', 'it', 'italian', 'Italian', 'it_CH', ('%d/%m/%Y',)),
DateParserIT, DateDisplayIT)
("it_IT", "it", "italian", "Italian", "it_CH", ("%d/%m/%Y",)),
DateParserIT,
DateDisplayIT,
)
+148 -143
View File
@@ -24,30 +24,30 @@
Japanese-specific classes for parsing and displaying dates.
"""
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# Python modules
#
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
import re
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# Gramps modules
#
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
from ..lib.date import Date
from ._dateparser import DateParser
from ._datedisplay import DateDisplay
from ._datehandler import register_datehandler
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# Japanese parser
#
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
class DateParserJA(DateParser):
"""
Convert a text string into a Date object. If the date cannot be
@@ -56,21 +56,23 @@ class DateParserJA(DateParser):
# modifiers after the date
modifier_after_to_int = {
'以前' : Date.MOD_BEFORE,
'以降' : Date.MOD_AFTER,
'' : Date.MOD_ABOUT,
'ごろ' : Date.MOD_ABOUT,
}
"以前": Date.MOD_BEFORE,
"以降": Date.MOD_AFTER,
"": Date.MOD_ABOUT,
"ごろ": Date.MOD_ABOUT,
"from": Date.MOD_FROM,
"to": Date.MOD_TO,
}
month_to_int = DateParser.month_to_int
quality_to_int = {
'およそ' : Date.QUAL_ESTIMATED,
'ごろ' : Date.QUAL_ESTIMATED,
'' : Date.QUAL_ESTIMATED,
'の見積り' : Date.QUAL_ESTIMATED,
'計算上' : Date.QUAL_CALCULATED,
}
"およそ": Date.QUAL_ESTIMATED,
"ごろ": Date.QUAL_ESTIMATED,
"": Date.QUAL_ESTIMATED,
"の見積り": Date.QUAL_ESTIMATED,
"計算上": Date.QUAL_CALCULATED,
}
bce = ["紀元前", "BC"] + DateParser.bce
@@ -80,130 +82,138 @@ class DateParserJA(DateParser):
"""
DateParser.init_strings(self)
DateParser.calendar_to_int.update({
'グレゴリオ暦' : Date.CAL_GREGORIAN,
'g' : Date.CAL_GREGORIAN,
'ユリウス暦' : Date.CAL_JULIAN,
'j' : Date.CAL_JULIAN,
'ユダヤ暦' : Date.CAL_HEBREW,
'h' : Date.CAL_HEBREW,
'ヒジュラ暦' : Date.CAL_ISLAMIC,
'i' : Date.CAL_ISLAMIC,
'フランス革命暦' : Date.CAL_FRENCH,
'共和暦' : Date.CAL_FRENCH,
'f' : Date.CAL_FRENCH,
'イラン暦' : Date.CAL_PERSIAN,
'p' : Date.CAL_PERSIAN,
'スウェーデン暦' : Date.CAL_SWEDISH,
's' : Date.CAL_SWEDISH,
})
DateParser.calendar_to_int.update(
{
"グレゴリオ暦": Date.CAL_GREGORIAN,
"g": Date.CAL_GREGORIAN,
"ユリウス暦": Date.CAL_JULIAN,
"j": Date.CAL_JULIAN,
"ユダヤ暦": Date.CAL_HEBREW,
"h": Date.CAL_HEBREW,
"ヒジュラ暦": Date.CAL_ISLAMIC,
"i": Date.CAL_ISLAMIC,
"フランス革命暦": Date.CAL_FRENCH,
"共和暦": Date.CAL_FRENCH,
"f": Date.CAL_FRENCH,
"イラン暦": Date.CAL_PERSIAN,
"p": Date.CAL_PERSIAN,
"スウェーデン暦": Date.CAL_SWEDISH,
"s": Date.CAL_SWEDISH,
}
)
DateParser.month_to_int.update({
"一月" : 1,
"ichigatsu" : 1,
"睦月" : 1,
"mutsuki" : 1,
"二月" : 2,
"nigatsu" : 2,
"如月" : 2,
"kisaragi" : 2,
"衣更着" : 2,
"kinusaragi" : 2,
"三月" : 3,
"sangatsu" : 3,
"弥生" : 3,
"yayoi" : 3,
"四月" : 4,
"shigatsu" : 4,
"卯月" : 4,
"uzuki" : 4,
"五月" : 5,
"gogatsu" : 5,
"皐月" : 5,
"satsuki" : 5,
"早苗月" : 5,
"sanaetsuki" : 5,
"六月" : 6,
"rokugatsu" : 6,
"水無月" : 6,
"minazuki" : 6,
"七月" : 7,
"shichigatsu" : 7,
"文月" : 7,
"fumizuki" : 7,
"八月" : 8,
"hachigatsu" : 8,
"葉月" : 8,
"hazuki" : 8,
"九月" : 9,
"kugatsu" : 9,
"長月" : 9,
"nagatsuki" : 9,
"十月" : 10,
"jugatsu" : 10,
"jūgatsu" : 10,
"juugatsu" : 10,
"神無月" : 10,
"kannazuki" : 10,
"kaminazuki" : 10,
"神有月" : 10,
"" : 10,
"kamiarizuki" : 10,
"十一月" : 11,
"juichigatsu" : 11,
"jūichigatsu" : 11,
"juuichigatsu" : 11,
"霜月" : 11,
"shimotsuki" : 11,
"十二月" : 12,
"junigatsu" : 12,
"jūnigatsu" : 12,
"juunigatsu" : 12,
"師走" : 12,
"shiwasu" : 12,
})
DateParser.month_to_int.update(
{
"一月": 1,
"ichigatsu": 1,
"睦月": 1,
"mutsuki": 1,
"二月": 2,
"nigatsu": 2,
"如月": 2,
"kisaragi": 2,
"衣更着": 2,
"kinusaragi": 2,
"三月": 3,
"sangatsu": 3,
"弥生": 3,
"yayoi": 3,
"四月": 4,
"shigatsu": 4,
"卯月": 4,
"uzuki": 4,
"五月": 5,
"gogatsu": 5,
"皐月": 5,
"satsuki": 5,
"早苗月": 5,
"sanaetsuki": 5,
"六月": 6,
"rokugatsu": 6,
"水無月": 6,
"minazuki": 6,
"七月": 7,
"shichigatsu": 7,
"文月": 7,
"fumizuki": 7,
"八月": 8,
"hachigatsu": 8,
"葉月": 8,
"hazuki": 8,
"九月": 9,
"kugatsu": 9,
"長月": 9,
"nagatsuki": 9,
"十月": 10,
"jugatsu": 10,
"jūgatsu": 10,
"juugatsu": 10,
"神無月": 10,
"kannazuki": 10,
"kaminazuki": 10,
"": 10,
"神在月": 10,
"kamiarizuki": 10,
"十一月": 11,
"juichigatsu": 11,
"jūichigatsu": 11,
"juuichigatsu": 11,
"霜月": 11,
"shimotsuki": 11,
"十二月": 12,
"junigatsu": 12,
"jūnigatsu": 12,
"juunigatsu": 12,
"師走": 12,
"shiwasu": 12,
}
)
_span_1 = ['から', '~', '']
_span_2 = ['まで']
_range_1 = ['から', '', '~', '']
_range_2 = ['までの間', 'の間']
self._span = re.compile(r"(?P<start>.+)(%s)(?P<stop>.+)(%s)" %
('|'.join(_span_1), '|'.join(_span_2)),
re.IGNORECASE)
self._range = re.compile(r"(?P<start>.+)(%s)(?P<stop>.+)(%s)" %
('|'.join(_range_1), '|'.join(_range_2)),
re.IGNORECASE)
_span_1 = ["から", "~", ""]
_span_2 = ["まで"]
_range_1 = ["から", "", "~", ""]
_range_2 = ["までの間", "の間"]
self._span = re.compile(
r"(?P<start>.+)(%s)(?P<stop>.+)(%s)"
% ("|".join(_span_1), "|".join(_span_2)),
re.IGNORECASE,
)
self._range = re.compile(
r"(?P<start>.+)(%s)(?P<stop>.+)(%s)"
% ("|".join(_range_1), "|".join(_range_2)),
re.IGNORECASE,
)
self._numeric = re.compile(r"((\d+)年\s*)?((\d+)月\s*)?(\d+)?日?\s*$")
self._cal = re.compile(r"(.*?)\s*\(%s\)\s*(.*)" % self._cal_str,
re.IGNORECASE)
self._qual = re.compile(r"(.*?)\s*%s\s*(.*)" % self._qual_str,
re.IGNORECASE)
self._cal = re.compile(r"(.*?)\s*\(%s\)\s*(.*)" % self._cal_str, re.IGNORECASE)
self._qual = re.compile(r"(.*?)\s*%s\s*(.*)" % self._qual_str, re.IGNORECASE)
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# Japanese display
#
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
class DateDisplayJA(DateDisplay):
"""
Japanese language date display class.
"""
def formats_changed(self):
""" Allow overriding so a subclass can modify """
"""Allow overriding so a subclass can modify"""
# Specify what is actually the "System Default".
example = self.dhformat
example = example.replace('%d', "31")
example = example.replace('%m', "12")
example = example.replace('%Y', "1999")
example = example.replace("%d", "31")
example = example.replace("%m", "12")
example = example.replace("%Y", "1999")
# This definition must agree with its "_display_gregorian" method
self. formats = ("YYYY-MM-DD (ISO)", # 0
"システムデフォールト (" + example + ")", # 1
"1999年12月31日", # 2
"1999年十二月31日", # 3
)
self.formats = (
"YYYY-MM-DD (ISO)", # 0
"システムデフォールト (" + example + ")", # 1
"1999年12月31日", # 2
"1999年十二月31日", # 3
)
def _display_gregorian(self, date_val, **kwargs):
"""
@@ -223,12 +233,12 @@ class DateDisplayJA(DateDisplay):
if date_val[0] == date_val[1] == 0:
value = str(date_val[2])
else:
value = self.dhformat.replace('%m', str(date_val[1]))
if date_val[0] == 0: # ignore the zero day and its delimiter
i_day = value.find('%d')
value = value.replace(value[i_day:i_day+3], '')
value = value.replace('%d', str(date_val[0]))
value = value.replace('%Y', str(date_val[2]))
value = self.dhformat.replace("%m", str(date_val[1]))
if date_val[0] == 0: # ignore the zero day and its delimiter
i_day = value.find("%d")
value = value.replace(value[i_day : i_day + 3], "")
value = value.replace("%d", str(date_val[0]))
value = value.replace("%Y", str(date_val[2]))
elif self.format == 2:
# 1999年12月31日
@@ -236,12 +246,9 @@ class DateDisplayJA(DateDisplay):
if date_val[1] == 0:
value = "%s" % year
else:
value = "%s%s" % (year,
self.short_months[date_val[1]])
value = "%s%s" % (year, self.short_months[date_val[1]])
else:
value = "%s%s%s" % (year,
self.short_months[date_val[1]],
date_val[0])
value = "%s%s%s" % (year, self.short_months[date_val[1]], date_val[0])
elif self.format == 3:
# 1999年十二月31日
@@ -249,12 +256,9 @@ class DateDisplayJA(DateDisplay):
if date_val[1] == 0:
value = "%s" % year
else:
value = "%s%s" % (year,
self.long_months[date_val[1]])
value = "%s%s" % (year, self.long_months[date_val[1]])
else:
value = "%s%s%s" % (year,
self.long_months[date_val[1]],
date_val[0])
value = "%s%s%s" % (year, self.long_months[date_val[1]], date_val[0])
else:
return self.display_iso(date_val)
@@ -266,12 +270,13 @@ class DateDisplayJA(DateDisplay):
display = DateDisplay.display_formatted
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# Register classes
#
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
register_datehandler(
('ja_JP', 'ja', 'japanese', 'Japanese', ('%Y年%m月%d',)),
DateParserJA, DateDisplayJA)
("ja_JP", "ja", "japanese", "Japanese", ("%Y年%m月%d",)), DateParserJA, DateDisplayJA
)
+129 -76
View File
@@ -23,28 +23,28 @@
Lithuanian-specific classes for parsing and displaying dates.
"""
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# Python modules
#
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
import re
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# Gramps modules
#
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
from ..lib.date import Date
from ._dateparser import DateParser
from ._datedisplay import DateDisplay
from ._datehandler import register_datehandler
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# Lithuanian parser
#
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
class DateParserLT(DateParser):
"""
Convert a text string into a Date object. If the date cannot be
@@ -101,92 +101,137 @@ class DateParserLT(DateParser):
month_to_int["gruod"] = 12
modifier_to_int = {
'prieš' : Date.MOD_BEFORE,
'po' : Date.MOD_AFTER,
'apie' : Date.MOD_ABOUT,
}
"prieš": Date.MOD_BEFORE,
"po": Date.MOD_AFTER,
"apie": Date.MOD_ABOUT,
"from": Date.MOD_FROM,
"to": Date.MOD_TO,
}
calendar_to_int = {
'grigaliaus' : Date.CAL_GREGORIAN,
'g' : Date.CAL_GREGORIAN,
'julijaus' : Date.CAL_JULIAN,
'j' : Date.CAL_JULIAN,
'hebrajų' : Date.CAL_HEBREW,
'h' : Date.CAL_HEBREW,
'islamo' : Date.CAL_ISLAMIC,
'i' : Date.CAL_ISLAMIC,
'prancūzų respublikos': Date.CAL_FRENCH,
'r' : Date.CAL_FRENCH,
'persų' : Date.CAL_PERSIAN,
'p' : Date.CAL_PERSIAN,
'švedų' : Date.CAL_SWEDISH,
's' : Date.CAL_SWEDISH,
}
"grigaliaus": Date.CAL_GREGORIAN,
"g": Date.CAL_GREGORIAN,
"julijaus": Date.CAL_JULIAN,
"j": Date.CAL_JULIAN,
"hebrajų": Date.CAL_HEBREW,
"h": Date.CAL_HEBREW,
"islamo": Date.CAL_ISLAMIC,
"i": Date.CAL_ISLAMIC,
"prancūzų respublikos": Date.CAL_FRENCH,
"r": Date.CAL_FRENCH,
"persų": Date.CAL_PERSIAN,
"p": Date.CAL_PERSIAN,
"švedų": Date.CAL_SWEDISH,
"s": Date.CAL_SWEDISH,
}
quality_to_int = {
'apytikriai' : Date.QUAL_ESTIMATED,
'apskaičiuota' : Date.QUAL_CALCULATED,
}
"apytikriai": Date.QUAL_ESTIMATED,
"apskaičiuota": Date.QUAL_CALCULATED,
}
def init_strings(self):
DateParser.init_strings(self)
# this next RE has the (possibly-slashed) year at the string's start
self._text2 = re.compile(
r'((\d+)(/\d+)?)?\s+?m\.\s+%s\s*(\d+)?\s*d?\.?$'
% self._mon_str, re.IGNORECASE)
_span_1 = ['nuo']
_span_2 = ['iki']
_range_1 = ['tarp']
_range_2 = ['ir']
self._span = re.compile(r"(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" %
('|'.join(_span_1), '|'.join(_span_2)),
re.IGNORECASE)
r"((\d+)(/\d+)?)?\s+?m\.\s+%s\s*(\d+)?\s*d?\.?$" % self._mon_str,
re.IGNORECASE,
)
_span_1 = ["nuo"]
_span_2 = ["iki"]
_range_1 = ["tarp"]
_range_2 = ["ir"]
self._span = re.compile(
r"(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)"
% ("|".join(_span_1), "|".join(_span_2)),
re.IGNORECASE,
)
self._range = re.compile(
r"(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" %
('|'.join(_range_1), '|'.join(_range_2)), re.IGNORECASE)
r"(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)"
% ("|".join(_range_1), "|".join(_range_2)),
re.IGNORECASE,
)
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# Lithuanian displayer
#
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
class DateDisplayLT(DateDisplay):
"""
Lithuanian language date display class.
"""
long_months = ( "", "sausio", "vasario", "kovo", "balandžio", "gegužės",
"birželio", "liepos", "rugpjūčio", "rugsėjo", "spalio",
"lapkričio", "gruodžio" )
long_months = (
"",
"sausio",
"vasario",
"kovo",
"balandžio",
"gegužės",
"birželio",
"liepos",
"rugpjūčio",
"rugsėjo",
"spalio",
"lapkričio",
"gruodžio",
)
long_months_vardininkas = ( "", "sausis", "vasaris", "kovas", "balandis", "gegužė",
"birželis", "liepa", "rugpjūtis", "rugsėjis", "spalis",
"lapkritis", "gruodis" )
long_months_vardininkas = (
"",
"sausis",
"vasaris",
"kovas",
"balandis",
"gegužė",
"birželis",
"liepa",
"rugpjūtis",
"rugsėjis",
"spalis",
"lapkritis",
"gruodis",
)
short_months = ( "", "Sau", "Vas", "Kov", "Bal", "Geg", "Bir",
"Lie", "Rgp", "Rgs", "Spa", "Lap", "Grd" )
short_months = (
"",
"Sau",
"Vas",
"Kov",
"Bal",
"Geg",
"Bir",
"Lie",
"Rgp",
"Rgs",
"Spa",
"Lap",
"Grd",
)
calendar = (
"", "julijaus",
"",
"julijaus",
"hebrajų",
"prancūzų respublikos",
"persų",
"islamo",
"švedų"
)
"švedų",
)
_mod_str = ("",
"prieš ",
"po ",
"apie ",
"", "", "")
_mod_str = ("", "prieš ", "po ", "apie ", "", "", "")
_qual_str = ("", "apytikriai ", "apskaičiuota ")
formats = (
"mmmm-MM-DD (ISO)", "mmmm.MM.DD",
"mmmm m. mėnesio diena d.", "Mėn diena, metai")
# this definition must agree with its "_display_gregorian" method
"mmmm-MM-DD (ISO)",
"mmmm.MM.DD",
"mmmm m. mėnesio diena d.",
"Mėn diena, metai",
)
# this definition must agree with its "_display_gregorian" method
def _display_gregorian(self, date_val, **kwargs):
"""
@@ -206,11 +251,16 @@ class DateDisplayLT(DateDisplay):
if date_val[1] == 0:
value = year
else:
value = "%s m. %s" % (year, self.long_months_vardininkas[date_val[1]])
value = "%s m. %s" % (
year,
self.long_months_vardininkas[date_val[1]],
)
else:
value = "%s m. %s %d d." % (year,
self.long_months[date_val[1]],
date_val[0])
value = "%s m. %s %d d." % (
year,
self.long_months[date_val[1]],
date_val[0],
)
elif self.format == 3:
# month_abbreviation day, year
if date_val[0] == 0:
@@ -219,8 +269,11 @@ class DateDisplayLT(DateDisplay):
else:
value = "%s %s" % (self.short_months[date_val[1]], year)
else:
value = "%s %d, %s" % (self.short_months[date_val[1]],
date_val[0], year)
value = "%s %d, %s" % (
self.short_months[date_val[1]],
date_val[0],
year,
)
if date_val[2] < 0:
return self._bce_str % value
else:
@@ -246,25 +299,25 @@ class DateDisplayLT(DateDisplay):
d1 = self.display_cal[cal](start)
d2 = self.display_cal[cal](date.get_stop_date())
scal = self.format_extras(cal, newyear)
return "%s%s %s %s %s%s" % (qual_str, 'nuo', d1, 'iki',
d2, scal)
return "%s%s %s %s %s%s" % (qual_str, "nuo", d1, "iki", d2, scal)
elif mod == Date.MOD_RANGE:
d1 = self.display_cal[cal](start)
d2 = self.display_cal[cal](date.get_stop_date())
scal = self.format_extras(cal, newyear)
return "%s%s %s %s %s%s" % (qual_str, 'tarp', d1, 'ir',
d2, scal)
return "%s%s %s %s %s%s" % (qual_str, "tarp", d1, "ir", d2, scal)
else:
text = self.display_cal[date.get_calendar()](start)
scal = self.format_extras(cal, newyear)
return "%s%s%s%s" % (qual_str, self._mod_str[mod], text,
scal)
return "%s%s%s%s" % (qual_str, self._mod_str[mod], text, scal)
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# Register classes
#
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
register_datehandler(
('lt_LT', 'lt', 'lithuanian', 'Lithuanian', ('%Y.%m.%d',)),
DateParserLT, DateDisplayLT)
("lt_LT", "lt", "lithuanian", "Lithuanian", ("%Y.%m.%d",)),
DateParserLT,
DateDisplayLT,
)
+88 -59
View File
@@ -23,28 +23,28 @@
Norwegian-specific classes for parsing and displaying dates.
"""
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# Python modules
#
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
import re
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# Gramps modules
#
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
from ..lib.date import Date
from ._dateparser import DateParser
from ._datedisplay import DateDisplay
from ._datehandler import register_datehandler
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# Norwegian parser class
#
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
class DateParserNb(DateParser):
"""
Convert a text string into a Date object, expecting a date
@@ -54,66 +54,94 @@ class DateParserNb(DateParser):
# modifiers before the date
modifier_to_int = {
'før' : Date.MOD_BEFORE,
'innen' : Date.MOD_BEFORE,
'etter' : Date.MOD_AFTER,
'omkring' : Date.MOD_ABOUT,
'omtrent' : Date.MOD_ABOUT,
'ca' : Date.MOD_ABOUT
}
"før": Date.MOD_BEFORE,
"innen": Date.MOD_BEFORE,
"etter": Date.MOD_AFTER,
"omkring": Date.MOD_ABOUT,
"omtrent": Date.MOD_ABOUT,
"ca": Date.MOD_ABOUT,
"from": Date.MOD_FROM,
"to": Date.MOD_TO,
}
bce = ["f Kr"]
calendar_to_int = {
'gregoriansk ' : Date.CAL_GREGORIAN,
'g' : Date.CAL_GREGORIAN,
'juliansk' : Date.CAL_JULIAN,
'j' : Date.CAL_JULIAN,
'hebraisk' : Date.CAL_HEBREW,
'h' : Date.CAL_HEBREW,
'islamisk' : Date.CAL_ISLAMIC,
'muslimsk' : Date.CAL_ISLAMIC,
'i' : Date.CAL_ISLAMIC,
'fransk' : Date.CAL_FRENCH,
'fransk republikansk' : Date.CAL_FRENCH,
'f' : Date.CAL_FRENCH,
'persisk' : Date.CAL_PERSIAN,
'p' : Date.CAL_PERSIAN,
'svensk' : Date.CAL_SWEDISH,
's' : Date.CAL_SWEDISH,
}
"gregoriansk ": Date.CAL_GREGORIAN,
"g": Date.CAL_GREGORIAN,
"juliansk": Date.CAL_JULIAN,
"j": Date.CAL_JULIAN,
"hebraisk": Date.CAL_HEBREW,
"h": Date.CAL_HEBREW,
"islamisk": Date.CAL_ISLAMIC,
"muslimsk": Date.CAL_ISLAMIC,
"i": Date.CAL_ISLAMIC,
"fransk": Date.CAL_FRENCH,
"fransk republikansk": Date.CAL_FRENCH,
"f": Date.CAL_FRENCH,
"persisk": Date.CAL_PERSIAN,
"p": Date.CAL_PERSIAN,
"svensk": Date.CAL_SWEDISH,
"s": Date.CAL_SWEDISH,
}
quality_to_int = {
'estimert' : Date.QUAL_ESTIMATED,
'beregnet' : Date.QUAL_CALCULATED,
}
"estimert": Date.QUAL_ESTIMATED,
"beregnet": Date.QUAL_CALCULATED,
}
def init_strings(self):
DateParser.init_strings(self)
self._numeric = re.compile(
r"((\d+)[/\.\s]\s*)?((\d+)[/\.\-\s]\s*)?(\d+)\s*$")
self._numeric = re.compile(r"((\d+)[/\.\s]\s*)?((\d+)[/\.\-\s]\s*)?(\d+)\s*$")
self._span = re.compile(
r"(fra)?\s*(?P<start>.+)\s*(til|--|)\s*(?P<stop>.+)",
re.IGNORECASE)
r"(fra)?\s*(?P<start>.+)\s*(til|--|)\s*(?P<stop>.+)", re.IGNORECASE
)
self._range = re.compile(
r"(mellom)\s+(?P<start>.+)\s+og\s+(?P<stop>.+)", re.IGNORECASE)
r"(mellom)\s+(?P<start>.+)\s+og\s+(?P<stop>.+)", re.IGNORECASE
)
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# Norwegian display class
#
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
class DateDisplayNb(DateDisplay):
"""
Norwegian language date display class.
"""
long_months = ( "", "januar", "februar", "mars", "april", "mai",
"juni", "juli", "august", "september", "oktober",
"november", "desember" )
long_months = (
"",
"januar",
"februar",
"mars",
"april",
"mai",
"juni",
"juli",
"august",
"september",
"oktober",
"november",
"desember",
)
short_months = ( "", "jan", "feb", "mar", "apr", "mai", "jun",
"jul", "aug", "sep", "okt", "nov", "des" )
short_months = (
"",
"jan",
"feb",
"mar",
"apr",
"mai",
"jun",
"jul",
"aug",
"sep",
"okt",
"nov",
"des",
)
formats = (
"ÅÅÅÅ-MM-DD (ISO)",
@@ -122,9 +150,9 @@ class DateDisplayNb(DateDisplay):
"Mån Dag År",
"Dag måned år",
"Dag Mån År",
)
# this must agree with DateDisplayEn's "formats" definition
# (since no locale-specific _display_gregorian exists, here)
)
# this must agree with DateDisplayEn's "formats" definition
# (since no locale-specific _display_gregorian exists, here)
calendar = (
"",
@@ -133,8 +161,8 @@ class DateDisplayNb(DateDisplay):
"fransk republikansk",
"persisk",
"islamisk",
"svensk"
)
"svensk",
)
_mod_str = ("", "før ", "etter ", "ca ", "", "", "")
@@ -167,23 +195,24 @@ class DateDisplayNb(DateDisplay):
d1 = self.display_cal[cal](start)
d2 = self.display_cal[cal](date.get_stop_date())
scal = self.format_extras(cal, newyear)
return "%smellom %s og %s%s" % (qual_str, d1, d2,
scal)
return "%smellom %s og %s%s" % (qual_str, d1, d2, scal)
else:
text = self.display_cal[date.get_calendar()](start)
scal = self.format_extras(cal, newyear)
return "%s%s%s%s" % (qual_str, self._mod_str[mod],
text, scal)
return "%s%s%s%s" % (qual_str, self._mod_str[mod], text, scal)
def dd_dformat01(self, date_val):
""" numerical -- for Norwegian dates """
"""numerical -- for Norwegian dates"""
return DateDisplay.dd_dformat01(self, date_val).lstrip()
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# Register classes
#
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
register_datehandler(
('nb_NO', 'nb', 'nn_NO', 'nn', 'norsk', 'Norwegian', ('%d. %b %Y',)),
DateParserNb, DateDisplayNb)
("nb_NO", "nb", "nn_NO", "nn", "norsk", "Norwegian", ("%d. %b %Y",)),
DateParserNb,
DateDisplayNb,
)
+122 -80
View File
@@ -29,28 +29,28 @@
Dutch-specific classes for parsing and displaying dates.
"""
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# Python modules
#
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
import re
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# Gramps modules
#
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
from ..lib.date import Date
from ._dateparser import DateParser
from ._datedisplay import DateDisplay
from ._datehandler import register_datehandler
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# Dutch parser
#
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
class DateParserNL(DateParser):
month_to_int = DateParser.month_to_int
@@ -63,7 +63,7 @@ class DateParserNL(DateParser):
month_to_int["feber"] = 2
month_to_int["februaris"] = 2
month_to_int["merz"] = 3
#make sure on all distro mrt and maa are accepted
# make sure on all distro mrt and maa are accepted
month_to_int["maa"] = 3
month_to_int["mrt"] = 3
month_to_int["aprilis"] = 4
@@ -83,74 +83,112 @@ class DateParserNL(DateParser):
month_to_int["xbris"] = 12
modifier_to_int = {
'voor' : Date.MOD_BEFORE,
'na' : Date.MOD_AFTER,
'ca.' : Date.MOD_ABOUT,
'circa' : Date.MOD_ABOUT,
'om' : Date.MOD_ABOUT,
'omstreeks' : Date.MOD_ABOUT,
'ongeveer' : Date.MOD_ABOUT,
'rond' : Date.MOD_ABOUT,
'tegen' : Date.MOD_ABOUT,
}
"voor": Date.MOD_BEFORE,
"na": Date.MOD_AFTER,
"ca.": Date.MOD_ABOUT,
"circa": Date.MOD_ABOUT,
"om": Date.MOD_ABOUT,
"omstreeks": Date.MOD_ABOUT,
"ongeveer": Date.MOD_ABOUT,
"rond": Date.MOD_ABOUT,
"tegen": Date.MOD_ABOUT,
"from": Date.MOD_FROM,
"to": Date.MOD_TO,
}
calendar_to_int = {
'gregoriaans' : Date.CAL_GREGORIAN,
'greg.' : Date.CAL_GREGORIAN,
'juliaans' : Date.CAL_JULIAN,
'jul.' : Date.CAL_JULIAN,
'hebreeuws' : Date.CAL_HEBREW,
'hebr.' : Date.CAL_HEBREW,
'islamitisch' : Date.CAL_ISLAMIC,
'isl.' : Date.CAL_ISLAMIC,
'frans republiekeins' : Date.CAL_FRENCH,
'fran.' : Date.CAL_FRENCH,
'persisch' : Date.CAL_PERSIAN,
'zweeds' : Date.CAL_SWEDISH,
'z' : Date.CAL_SWEDISH,
}
"gregoriaans": Date.CAL_GREGORIAN,
"greg.": Date.CAL_GREGORIAN,
"juliaans": Date.CAL_JULIAN,
"jul.": Date.CAL_JULIAN,
"hebreeuws": Date.CAL_HEBREW,
"hebr.": Date.CAL_HEBREW,
"islamitisch": Date.CAL_ISLAMIC,
"isl.": Date.CAL_ISLAMIC,
"frans republiekeins": Date.CAL_FRENCH,
"fran.": Date.CAL_FRENCH,
"persisch": Date.CAL_PERSIAN,
"zweeds": Date.CAL_SWEDISH,
"z": Date.CAL_SWEDISH,
}
quality_to_int = {
'geschat' : Date.QUAL_ESTIMATED,
'gesch.' : Date.QUAL_ESTIMATED,
'berekend' : Date.QUAL_CALCULATED,
'ber.' : Date.QUAL_CALCULATED,
}
"geschat": Date.QUAL_ESTIMATED,
"gesch.": Date.QUAL_ESTIMATED,
"berekend": Date.QUAL_CALCULATED,
"ber.": Date.QUAL_CALCULATED,
}
bce = ["voor onze tijdrekening", "voor Christus", "v. Chr."] + DateParser.bce
def init_strings(self):
DateParser.init_strings(self)
self._span = re.compile(
r"(van)\s+(?P<start>.+)\s+(tot)\s+(?P<stop>.+)", re.IGNORECASE)
self._range = re.compile(r"tussen\s+(?P<start>.+)\s+en\s+(?P<stop>.+)",
re.IGNORECASE)
self._text2 = re.compile(r'(\d+)?.?\s+?%s\s*((\d+)(/\d+)?)?'
% self._mon_str, re.IGNORECASE)
self._jtext2 = re.compile(r'(\d+)?.?\s+?%s\s*((\d+)(/\d+)?)?'
% self._jmon_str, re.IGNORECASE)
r"(van)\s+(?P<start>.+)\s+(tot)\s+(?P<stop>.+)", re.IGNORECASE
)
self._range = re.compile(
r"tussen\s+(?P<start>.+)\s+en\s+(?P<stop>.+)", re.IGNORECASE
)
self._text2 = re.compile(
r"(\d+)?.?\s+?%s\s*((\d+)(/\d+)?)?" % self._mon_str, re.IGNORECASE
)
self._jtext2 = re.compile(
r"(\d+)?.?\s+?%s\s*((\d+)(/\d+)?)?" % self._jmon_str, re.IGNORECASE
)
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# Dutch display
#
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
class DateDisplayNL(DateDisplay):
"""
Dutch language date display class.
"""
# TODO: Translate these month strings:
long_months = ( "", "januari", "februari", "maart", "april", "mei",
"juni", "juli", "augustus", "september", "oktober",
"november", "december" )
short_months = ( "", "jan", "feb", "mrt", "apr", "mei", "jun",
"jul", "aug", "sep", "okt", "nov", "dec" )
# TODO: Translate these month strings:
long_months = (
"",
"januari",
"februari",
"maart",
"april",
"mei",
"juni",
"juli",
"augustus",
"september",
"oktober",
"november",
"december",
)
short_months = (
"",
"jan",
"feb",
"mrt",
"apr",
"mei",
"jun",
"jul",
"aug",
"sep",
"okt",
"nov",
"dec",
)
calendar = (
"", "juliaans", "hebreeuws",
"frans republikeins", "persisch", "islamitisch",
"zweeds" )
"",
"juliaans",
"hebreeuws",
"frans republikeins",
"persisch",
"islamitisch",
"zweeds",
)
_mod_str = ("", "voor ", "na ", "omstreeks ", "", "", "")
@@ -159,10 +197,14 @@ class DateDisplayNL(DateDisplay):
_bce_str = "%s v. Chr."
formats = (
"JJJJ-MM-DD (ISO)", "Numeriek DD/MM/JJJJ", "Maand Dag, Jaar",
"Mnd. Dag Jaar", "Dag Maand Jaar", "Dag Mnd. Jaar"
)
# this definition must agree with its "_display_gregorian" method
"JJJJ-MM-DD (ISO)",
"Numeriek DD/MM/JJJJ",
"Maand Dag, Jaar",
"Mnd. Dag Jaar",
"Dag Maand Jaar",
"Dag Mnd. Jaar",
)
# this definition must agree with its "_display_gregorian" method
def _display_gregorian(self, date_val, **kwargs):
"""
@@ -180,10 +222,10 @@ class DateDisplayNL(DateDisplay):
if date_val[0] == date_val[1] == 0:
value = str(date_val[2])
else:
value = self.dhformat.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('-', '/')
value = self.dhformat.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_name day, year
if date_val[0] == 0:
@@ -192,8 +234,7 @@ class DateDisplayNL(DateDisplay):
else:
value = "%s %s" % (self.long_months[date_val[1]], year)
else:
value = "%s %d, %s" % (self.long_months[date_val[1]],
date_val[0], year)
value = "%s %d, %s" % (self.long_months[date_val[1]], date_val[0], year)
elif self.format == 3:
# month_abbreviation day, year
if date_val[0] == 0:
@@ -202,8 +243,11 @@ class DateDisplayNL(DateDisplay):
else:
value = "%s %s" % (self.short_months[date_val[1]], year)
else:
value = "%s %d, %s" % (self.short_months[date_val[1]],
date_val[0], year)
value = "%s %d, %s" % (
self.short_months[date_val[1]],
date_val[0],
year,
)
elif self.format == 4:
# day month_name year
if date_val[0] == 0:
@@ -212,8 +256,7 @@ class DateDisplayNL(DateDisplay):
else:
value = "%s %s" % (self.long_months[date_val[1]], year)
else:
value = "%d %s %s" % (date_val[0],
self.long_months[date_val[1]], year)
value = "%d %s %s" % (date_val[0], self.long_months[date_val[1]], year)
else:
# day month_abbreviation year
if date_val[0] == 0:
@@ -222,8 +265,7 @@ class DateDisplayNL(DateDisplay):
else:
value = "%s %s" % (self.short_months[date_val[1]], year)
else:
value = "%d %s %s" % (date_val[0],
self.short_months[date_val[1]], year)
value = "%d %s %s" % (date_val[0], self.short_months[date_val[1]], year)
if date_val[2] < 0:
return self._bce_str % value
else:
@@ -249,25 +291,25 @@ class DateDisplayNL(DateDisplay):
d1 = self.display_cal[cal](start)
d2 = self.display_cal[cal](date.get_stop_date())
scal = self.format_extras(cal, newyear)
return "%s%s %s %s %s%s" % (qual_str, 'van', d1,
'tot', d2, scal)
return "%s%s %s %s %s%s" % (qual_str, "van", d1, "tot", d2, scal)
elif mod == Date.MOD_RANGE:
d1 = self.display_cal[cal](start)
d2 = self.display_cal[cal](date.get_stop_date())
scal = self.format_extras(cal, newyear)
return "%stussen %s en %s%s" % (qual_str, d1, d2,
scal)
return "%stussen %s en %s%s" % (qual_str, d1, d2, scal)
else:
text = self.display_cal[date.get_calendar()](start)
scal = self.format_extras(cal, newyear)
return "%s%s%s%s" % (qual_str, self._mod_str[mod], text,
scal)
return "%s%s%s%s" % (qual_str, self._mod_str[mod], text, scal)
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# Register classes
#
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
register_datehandler(
('nl_NL', 'dutch', 'Dutch', 'nl_BE', 'nl', ('%d-%m-%Y',)),
DateParserNL, DateDisplayNL)
("nl_NL", "dutch", "Dutch", "nl_BE", "nl", ("%d-%m-%Y",)),
DateParserNL,
DateDisplayNL,
)
+119 -84
View File
@@ -26,28 +26,28 @@
Polish-specific classes for parsing and displaying dates.
"""
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# Python modules
#
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
import re
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# Gramps modules
#
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
from ..lib.date import Date
from ._dateparser import DateParser
from ._datedisplay import DateDisplay
from ._datehandler import register_datehandler
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# Polish parser
#
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
class DateParserPL(DateParser):
month_to_int = DateParser.month_to_int
@@ -112,83 +112,117 @@ class DateParserPL(DateParser):
month_to_int["paz"] = 10
modifier_to_int = {
'przed' : Date.MOD_BEFORE,
'po' : Date.MOD_AFTER,
'około' : Date.MOD_ABOUT,
'ok.' : Date.MOD_ABOUT,
'circa' : Date.MOD_ABOUT,
'ca.' : Date.MOD_ABOUT,
"przed": Date.MOD_BEFORE,
"po": Date.MOD_AFTER,
"około": Date.MOD_ABOUT,
"ok.": Date.MOD_ABOUT,
"circa": Date.MOD_ABOUT,
"ca.": Date.MOD_ABOUT,
# Alternative forms: misspellings sometimes used in emails
'okolo' : Date.MOD_ABOUT,
'ok' : Date.MOD_ABOUT,
}
"okolo": Date.MOD_ABOUT,
"ok": Date.MOD_ABOUT,
"from": Date.MOD_FROM,
"to": Date.MOD_TO,
}
calendar_to_int = {
'gregoriański' : Date.CAL_GREGORIAN,
'greg.' : Date.CAL_GREGORIAN,
'juliański' : Date.CAL_JULIAN,
'jul.' : Date.CAL_JULIAN,
'hebrajski' : Date.CAL_HEBREW,
'hebr.' : Date.CAL_HEBREW,
'islamski' : Date.CAL_ISLAMIC,
'isl.' : Date.CAL_ISLAMIC,
'francuski republikański': Date.CAL_FRENCH,
'franc.' : Date.CAL_FRENCH,
'perski' : Date.CAL_PERSIAN,
'szwedzki' : Date.CAL_SWEDISH,
's' : Date.CAL_SWEDISH,
# Alternative forms: nouns without polish accent letters
# (misspellings sometimes used in emails)
'gregorianski' : Date.CAL_GREGORIAN,
'julianski' : Date.CAL_JULIAN,
'francuski republikanski': Date.CAL_FRENCH,
}
"gregoriański": Date.CAL_GREGORIAN,
"greg.": Date.CAL_GREGORIAN,
"juliański": Date.CAL_JULIAN,
"jul.": Date.CAL_JULIAN,
"hebrajski": Date.CAL_HEBREW,
"hebr.": Date.CAL_HEBREW,
"islamski": Date.CAL_ISLAMIC,
"isl.": Date.CAL_ISLAMIC,
"francuski republikański": Date.CAL_FRENCH,
"franc.": Date.CAL_FRENCH,
"perski": Date.CAL_PERSIAN,
"szwedzki": Date.CAL_SWEDISH,
"s": Date.CAL_SWEDISH,
# Alternative forms: nouns without polish accent letters
# (misspellings sometimes used in emails)
"gregorianski": Date.CAL_GREGORIAN,
"julianski": Date.CAL_JULIAN,
"francuski republikanski": Date.CAL_FRENCH,
}
quality_to_int = {
'szacowany' : Date.QUAL_ESTIMATED,
'szac.' : Date.QUAL_ESTIMATED,
'obliczony' : Date.QUAL_CALCULATED,
'obl.' : Date.QUAL_CALCULATED,
}
"szacowany": Date.QUAL_ESTIMATED,
"szac.": Date.QUAL_ESTIMATED,
"obliczony": Date.QUAL_CALCULATED,
"obl.": Date.QUAL_CALCULATED,
}
bce = ["przed naszą erą", "przed Chrystusem",
"p.n.e."] + DateParser.bce
bce = ["przed naszą erą", "przed Chrystusem", "p.n.e."] + DateParser.bce
def init_strings(self):
DateParser.init_strings(self)
self._span = re.compile(
r"(od)\s+(?P<start>.+)\s+(do)\s+(?P<stop>.+)", re.IGNORECASE)
r"(od)\s+(?P<start>.+)\s+(do)\s+(?P<stop>.+)", re.IGNORECASE
)
# Also handle a common mistakes
self._range = re.compile(
r"((?:po)?mi(?:ę|e)dzy)\s+(?P<start>.+)\s+(a)\s+(?P<stop>.+)",
re.IGNORECASE)
self._text2 = re.compile(r'(\d+)?.?\s+?%s\s*((\d+)(/\d+)?)?'
% self._mon_str, re.IGNORECASE)
self._jtext2 = re.compile(r'(\d+)?.?\s+?%s\s*((\d+)(/\d+)?)?'
% self._jmon_str, re.IGNORECASE)
r"((?:po)?mi(?:ę|e)dzy)\s+(?P<start>.+)\s+(a)\s+(?P<stop>.+)", re.IGNORECASE
)
self._text2 = re.compile(
r"(\d+)?.?\s+?%s\s*((\d+)(/\d+)?)?" % self._mon_str, re.IGNORECASE
)
self._jtext2 = re.compile(
r"(\d+)?.?\s+?%s\s*((\d+)(/\d+)?)?" % self._jmon_str, re.IGNORECASE
)
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# Polish display
#
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
class DateDisplayPL(DateDisplay):
"""
Polish language date display class.
"""
long_months = ( "", "Styczeń", "Luty", "Marzec", "Kwiecień", "Maj",
"Czerwiec", "Lipiec", "Sierpień", "Wrzesień", "Październik",
"Listopad", "Grudzi" )
long_months = (
"",
"Stycz",
"Luty",
"Marzec",
"Kwiecień",
"Maj",
"Czerwiec",
"Lipiec",
"Sierpień",
"Wrzesień",
"Październik",
"Listopad",
"Grudzień",
)
short_months = ( "", "Sty", "Lut", "Mar", "Kwi", "Maj", "Cze",
"Lip", "Sie", "Wrz", "Paź", "Lis", "Gru" )
short_months = (
"",
"Sty",
"Lut",
"Mar",
"Kwi",
"Maj",
"Cze",
"Lip",
"Sie",
"Wrz",
"Paź",
"Lis",
"Gru",
)
calendar = (
"", "juliański", "hebrajski",
"francuski republikański", "perski", "islamski",
"swedish"
)
"",
"juliański",
"hebrajski",
"francuski republikański",
"perski",
"islamski",
"swedish",
)
_mod_str = ("", "przed ", "po ", "ok. ", "", "", "")
@@ -197,10 +231,14 @@ class DateDisplayPL(DateDisplay):
_bce_str = "%s p.n.e."
formats = (
"RRRR-MM-DD (ISO)", "Numeryczny", "Miesiąc Dzień, Rok",
"Miesiąc.Dzień.Rok", "Dzień Miesiąc Rok", "Dzień MieRzym Rok"
)
# this definition must agree with its "_display_gregorian" method
"RRRR-MM-DD (ISO)",
"Numeryczny",
"Miesiąc Dzień, Rok",
"Miesiąc.Dzień.Rok",
"Dzień Miesiąc Rok",
"Dzień MieRzym Rok",
)
# this definition must agree with its "_display_gregorian" method
roman_months = (
"",
@@ -215,8 +253,8 @@ class DateDisplayPL(DateDisplay):
"IX",
"X",
"XI",
"XII"
)
"XII",
)
def _display_gregorian(self, date_val, **kwargs):
"""
@@ -234,9 +272,9 @@ class DateDisplayPL(DateDisplay):
if date_val[0] == date_val[1] == 0:
value = str(date_val[2])
else:
value = self.dhformat.replace('%d', str(date_val[0]))
value = value.replace('%m', str(date_val[1]))
value = value.replace('%Y', str(date_val[2]))
value = self.dhformat.replace("%d", str(date_val[0]))
value = value.replace("%m", str(date_val[1]))
value = value.replace("%Y", str(date_val[2]))
elif self.format == 2:
# month_name day, year
if date_val[0] == 0:
@@ -245,8 +283,7 @@ class DateDisplayPL(DateDisplay):
else:
value = "%s %s" % (self.long_months[date_val[1]], year)
else:
value = "%s %d, %s" % (self.long_months[date_val[1]],
date_val[0], year)
value = "%s %d, %s" % (self.long_months[date_val[1]], date_val[0], year)
elif self.format == 3:
# month_number. day. year
if date_val[0] == 0:
@@ -264,8 +301,7 @@ class DateDisplayPL(DateDisplay):
else:
value = "%s %s" % (self.long_months[date_val[1]], year)
else:
value = "%d %s %s" % (date_val[0],
self.long_months[date_val[1]], year)
value = "%d %s %s" % (date_val[0], self.long_months[date_val[1]], year)
else:
# day Roman_number_month year
if date_val[0] == 0:
@@ -274,8 +310,7 @@ class DateDisplayPL(DateDisplay):
else:
value = "%s %s" % (self.roman_months[date_val[1]], year)
else:
value = "%d %s %s" % (date_val[0],
self.roman_months[date_val[1]], year)
value = "%d %s %s" % (date_val[0], self.roman_months[date_val[1]], year)
if date_val[2] < 0:
return self._bce_str % value
else:
@@ -301,25 +336,25 @@ class DateDisplayPL(DateDisplay):
d1 = self.display_cal[cal](start)
d2 = self.display_cal[cal](date.get_stop_date())
scal = self.format_extras(cal, newyear)
return "%s%s %s %s %s%s" % (qual_str, 'od', d1, 'do', d2,
scal)
return "%s%s %s %s %s%s" % (qual_str, "od", d1, "do", d2, scal)
elif mod == Date.MOD_RANGE:
d1 = self.display_cal[cal](start)
d2 = self.display_cal[cal](date.get_stop_date())
scal = self.format_extras(cal, newyear)
return "%s%s %s %s %s%s" % (qual_str, 'między', d1, 'a', d2,
scal)
return "%s%s %s %s %s%s" % (qual_str, "między", d1, "a", d2, scal)
else:
text = self.display_cal[date.get_calendar()](start)
scal = self.format_extras(cal, newyear)
return "%s%s%s%s" % (qual_str, self._mod_str[mod], text,
scal)
return "%s%s%s%s" % (qual_str, self._mod_str[mod], text, scal)
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# Register classes
#
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
register_datehandler(
('pl_PL', 'polish', 'Polish_Poland', 'pl', ('%d.%m.%Y',)),
DateParserPL, DateDisplayPL)
("pl_PL", "polish", "Polish_Poland", "pl", ("%d.%m.%Y",)),
DateParserPL,
DateDisplayPL,
)
+131 -88
View File
@@ -25,128 +25,161 @@
Portuguese-specific classes for parsing and displaying dates.
"""
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# Python modules
#
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
import re
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# Gramps modules
#
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
from ..lib.date import Date
from ._dateparser import DateParser
from ._datedisplay import DateDisplay
from ._datehandler import register_datehandler
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# Portuguese parser
#
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
class DateParserPT(DateParser):
modifier_to_int = {
'antes de' : Date.MOD_BEFORE,
'antes' : Date.MOD_BEFORE,
'ant.' : Date.MOD_BEFORE,
'ant' : Date.MOD_BEFORE,
'até' : Date.MOD_BEFORE,
'depois de' : Date.MOD_AFTER,
'depois' : Date.MOD_AFTER,
'dep.' : Date.MOD_AFTER,
'dep' : Date.MOD_AFTER,
'aprox.' : Date.MOD_ABOUT,
'aprox' : Date.MOD_ABOUT,
'apr.' : Date.MOD_ABOUT,
'apr' : Date.MOD_ABOUT,
'cerca de' : Date.MOD_ABOUT,
'ca.' : Date.MOD_ABOUT,
'ca' : Date.MOD_ABOUT,
'c.' : Date.MOD_ABOUT,
'por volta de' : Date.MOD_ABOUT,
'por volta' : Date.MOD_ABOUT,
'pvd.' : Date.MOD_ABOUT,
}
"antes de": Date.MOD_BEFORE,
"antes": Date.MOD_BEFORE,
"ant.": Date.MOD_BEFORE,
"ant": Date.MOD_BEFORE,
"até": Date.MOD_BEFORE,
"depois de": Date.MOD_AFTER,
"depois": Date.MOD_AFTER,
"dep.": Date.MOD_AFTER,
"dep": Date.MOD_AFTER,
"aprox.": Date.MOD_ABOUT,
"aprox": Date.MOD_ABOUT,
"apr.": Date.MOD_ABOUT,
"apr": Date.MOD_ABOUT,
"cerca de": Date.MOD_ABOUT,
"ca.": Date.MOD_ABOUT,
"ca": Date.MOD_ABOUT,
"c.": Date.MOD_ABOUT,
"por volta de": Date.MOD_ABOUT,
"por volta": Date.MOD_ABOUT,
"pvd.": Date.MOD_ABOUT,
"from": Date.MOD_FROM,
"to": Date.MOD_TO,
}
calendar_to_int = {
'gregoriano' : Date.CAL_GREGORIAN,
'g' : Date.CAL_GREGORIAN,
'juliano' : Date.CAL_JULIAN,
'j' : Date.CAL_JULIAN,
'hebreu' : Date.CAL_HEBREW,
'h' : Date.CAL_HEBREW,
'islâmico' : Date.CAL_ISLAMIC,
'i' : Date.CAL_ISLAMIC,
'revolucionário' : Date.CAL_FRENCH,
'r' : Date.CAL_FRENCH,
'persa' : Date.CAL_PERSIAN,
'p' : Date.CAL_PERSIAN,
'swedish' : Date.CAL_SWEDISH,
's' : Date.CAL_SWEDISH,
}
"gregoriano": Date.CAL_GREGORIAN,
"g": Date.CAL_GREGORIAN,
"juliano": Date.CAL_JULIAN,
"j": Date.CAL_JULIAN,
"hebreu": Date.CAL_HEBREW,
"h": Date.CAL_HEBREW,
"islâmico": Date.CAL_ISLAMIC,
"i": Date.CAL_ISLAMIC,
"revolucionário": Date.CAL_FRENCH,
"r": Date.CAL_FRENCH,
"persa": Date.CAL_PERSIAN,
"p": Date.CAL_PERSIAN,
"swedish": Date.CAL_SWEDISH,
"s": Date.CAL_SWEDISH,
}
quality_to_int = {
'estimado' : Date.QUAL_ESTIMATED,
'estimada' : Date.QUAL_ESTIMATED,
'est.' : Date.QUAL_ESTIMATED,
'est' : Date.QUAL_ESTIMATED,
'calc.' : Date.QUAL_CALCULATED,
'calc' : Date.QUAL_CALCULATED,
'calculado' : Date.QUAL_CALCULATED,
'calculada' : Date.QUAL_CALCULATED,
}
"estimado": Date.QUAL_ESTIMATED,
"estimada": Date.QUAL_ESTIMATED,
"est.": Date.QUAL_ESTIMATED,
"est": Date.QUAL_ESTIMATED,
"calc.": Date.QUAL_CALCULATED,
"calc": Date.QUAL_CALCULATED,
"calculado": Date.QUAL_CALCULATED,
"calculada": Date.QUAL_CALCULATED,
}
def init_strings(self):
DateParser.init_strings(self)
_span_1 = ['de']
_span_2 = ['a']
_range_1 = ['entre', r'ent\.', 'ent']
_range_2 = ['e']
self._span = re.compile(r"(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)"
% ('|'.join(_span_1), '|'.join(_span_2)),
re.IGNORECASE)
self._range = re.compile(r"(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)"
% ('|'.join(_range_1), '|'.join(_range_2)),
re.IGNORECASE)
_span_1 = ["de"]
_span_2 = ["a"]
_range_1 = ["entre", r"ent\.", "ent"]
_range_2 = ["e"]
self._span = re.compile(
r"(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)"
% ("|".join(_span_1), "|".join(_span_2)),
re.IGNORECASE,
)
self._range = re.compile(
r"(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)"
% ("|".join(_range_1), "|".join(_range_2)),
re.IGNORECASE,
)
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# Portuguese display
#
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
class DateDisplayPT(DateDisplay):
"""
Portuguese language date display class.
"""
long_months = ( "", "Janeiro", "Fevereiro", "Março", "Abril", "Maio",
"Junho", "Julho", "Agosto", "Setembro", "Outubro",
"Novembro", "Dezembro" )
short_months = ( "", "Jan", "Fev", "Mar", "Abr", "Mai", "Jun",
"Jul", "Ago", "Set", "Out", "Nov", "Dez" )
long_months = (
"",
"Janeiro",
"Fevereiro",
"Março",
"Abril",
"Maio",
"Junho",
"Julho",
"Agosto",
"Setembro",
"Outubro",
"Novembro",
"Dezembro",
)
calendar = (
"", "Juliano", "Hebreu",
"Revolucionário", "Persa", "Islâmico",
"Sueco"
)
short_months = (
"",
"Jan",
"Fev",
"Mar",
"Abr",
"Mai",
"Jun",
"Jul",
"Ago",
"Set",
"Out",
"Nov",
"Dez",
)
_mod_str = ("","antes de ","depois de ","por volta de ","","","")
calendar = ("", "Juliano", "Hebreu", "Revolucionário", "Persa", "Islâmico", "Sueco")
_qual_str = ("","estimado ","calculado ")
_mod_str = ("", "antes de ", "depois de ", "por volta de ", "", "", "")
_qual_str = ("", "estimado ", "calculado ")
formats = (
"AAAA-MM-DD (ISO)", "Numérica", "Mês Dia, Ano",
"MÊS Dia, Ano", "Dia Mês, Ano", "Dia MÊS, Ano"
)
# this must agree with DateDisplayEn's "formats" definition
# (since no locale-specific _display_gregorian exists, here)
"AAAA-MM-DD (ISO)",
"Numérica",
"Mês Dia, Ano",
"MÊS Dia, Ano",
"Dia Mês, Ano",
"Dia MÊS, Ano",
)
# this must agree with DateDisplayEn's "formats" definition
# (since no locale-specific _display_gregorian exists, here)
def display(self,date):
def display(self, date):
"""
Return a text string representing the date.
"""
@@ -166,23 +199,33 @@ class DateDisplayPT(DateDisplay):
d1 = self.display_cal[cal](start)
d2 = self.display_cal[cal](date.get_stop_date())
scal = self.format_extras(cal, newyear)
return "%s%s %s %s %s%s" % (qual_str, 'de', d1, 'a', d2, scal)
return "%s%s %s %s %s%s" % (qual_str, "de", d1, "a", d2, scal)
elif mod == Date.MOD_RANGE:
d1 = self.display_cal[cal](start)
d2 = self.display_cal[cal](date.get_stop_date())
scal = self.format_extras(cal, newyear)
return "%s%s %s %s %s%s" % (qual_str, 'entre', d1, 'e', d2, scal)
return "%s%s %s %s %s%s" % (qual_str, "entre", d1, "e", d2, scal)
else:
text = self.display_cal[date.get_calendar()](start)
scal = self.format_extras(cal, newyear)
return "%s%s%s%s" % (qual_str, self._mod_str[mod], text, scal)
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# Register classes
#
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
register_datehandler(
('pt_PT', 'pt_PT.UTF-8', 'pt_BR', 'pt_BR.UTF-8',
'pt' 'portuguese', 'Portuguese', ('%d-%m-%Y',)),
DateParserPT, DateDisplayPT)
(
"pt_PT",
"pt_PT.UTF-8",
"pt_BR",
"pt_BR.UTF-8",
"pt" "portuguese",
"Portuguese",
("%d-%m-%Y",),
),
DateParserPT,
DateDisplayPT,
)
+86 -81
View File
@@ -23,91 +23,97 @@
Russian-specific classes for parsing and displaying dates.
"""
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# Python modules
#
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
import re
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# Gramps modules
#
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
from ..lib.date import Date
from ._dateparser import DateParser
from ._datedisplay import DateDisplay
from ._datehandler import register_datehandler
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# Russian parser
#
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
class DateParserRU(DateParser):
modifier_to_int = {
'перед' : Date.MOD_BEFORE,
'по' : Date.MOD_BEFORE,
'до' : Date.MOD_BEFORE,
'после' : Date.MOD_AFTER,
'п.' : Date.MOD_AFTER,
'п' : Date.MOD_AFTER,
'с' : Date.MOD_AFTER,
'ок' : Date.MOD_ABOUT,
'ок.' : Date.MOD_ABOUT,
'около' : Date.MOD_ABOUT,
'примерно' : Date.MOD_ABOUT,
'прим' : Date.MOD_ABOUT,
'прим.' : Date.MOD_ABOUT,
'приблизительно' : Date.MOD_ABOUT,
'приб.' : Date.MOD_ABOUT,
'прибл.' : Date.MOD_ABOUT,
'приб' : Date.MOD_ABOUT,
'прибл' : Date.MOD_ABOUT,
}
"перед": Date.MOD_BEFORE,
"по": Date.MOD_BEFORE,
"до": Date.MOD_BEFORE,
"после": Date.MOD_AFTER,
"п.": Date.MOD_AFTER,
"п": Date.MOD_AFTER,
"с": Date.MOD_AFTER,
"ок": Date.MOD_ABOUT,
"ок.": Date.MOD_ABOUT,
"около": Date.MOD_ABOUT,
"примерно": Date.MOD_ABOUT,
"прим": Date.MOD_ABOUT,
"прим.": Date.MOD_ABOUT,
"приблизительно": Date.MOD_ABOUT,
"приб.": Date.MOD_ABOUT,
"прибл.": Date.MOD_ABOUT,
"приб": Date.MOD_ABOUT,
"прибл": Date.MOD_ABOUT,
"from": Date.MOD_FROM,
"to": Date.MOD_TO,
}
quality_to_int = {
'оценено' : Date.QUAL_ESTIMATED,
'оцен.' : Date.QUAL_ESTIMATED,
'оц.' : Date.QUAL_ESTIMATED,
'оцен' : Date.QUAL_ESTIMATED,
'оц' : Date.QUAL_ESTIMATED,
'вычислено' : Date.QUAL_CALCULATED,
'вычисл.' : Date.QUAL_CALCULATED,
'выч.' : Date.QUAL_CALCULATED,
'вычисл' : Date.QUAL_CALCULATED,
'выч' : Date.QUAL_CALCULATED,
}
"оценено": Date.QUAL_ESTIMATED,
"оцен.": Date.QUAL_ESTIMATED,
"оц.": Date.QUAL_ESTIMATED,
"оцен": Date.QUAL_ESTIMATED,
"оц": Date.QUAL_ESTIMATED,
"вычислено": Date.QUAL_CALCULATED,
"вычисл.": Date.QUAL_CALCULATED,
"выч.": Date.QUAL_CALCULATED,
"вычисл": Date.QUAL_CALCULATED,
"выч": Date.QUAL_CALCULATED,
}
bce = [
'до нашей эры', 'до н. э.', 'до н.э.',
'до н э', 'до нэ'] + DateParser.bce
bce = ["до нашей эры", "до н. э.", "до н.э.", "до н э", "до нэ"] + DateParser.bce
def init_strings(self):
DateParser.init_strings(self)
DateParser.calendar_to_int.update({
'персидский' : Date.CAL_PERSIAN,
'п' : Date.CAL_PERSIAN,
})
_span_1 = ['с', 'от']
#_span_2 = ['по', 'до'] # <-- clashes with bce parsing :-(
_span_2 = ['по']
_range_1 = ['между', r'меж\.', 'меж']
_range_2 = ['и']
self._span = re.compile(r"(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)"
% ('|'.join(_span_1), '|'.join(_span_2)),
re.IGNORECASE)
self._range = re.compile(r"(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)"
% ('|'.join(_range_1), '|'.join(_range_2)),
re.IGNORECASE)
DateParser.calendar_to_int.update(
{
"персидский": Date.CAL_PERSIAN,
"п": Date.CAL_PERSIAN,
}
)
_span_1 = ["с", "от"]
# _span_2 = ['по', 'до'] # <-- clashes with bce parsing :-(
_span_2 = ["по"]
_range_1 = ["между", r"меж\.", "меж"]
_range_2 = ["и"]
self._span = re.compile(
r"(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)"
% ("|".join(_span_1), "|".join(_span_2)),
re.IGNORECASE,
)
self._range = re.compile(
r"(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)"
% ("|".join(_range_1), "|".join(_range_2)),
re.IGNORECASE,
)
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
#
# Russian displayer
#
#-------------------------------------------------------------------------
# -------------------------------------------------------------------------
class DateDisplayRU(DateDisplay):
"""
Russian language date display class.
@@ -128,20 +134,19 @@ class DateDisplayRU(DateDisplay):
if date_val[1] == 0:
return year
else:
return self.format_long_month_year(date_val[1], year,
inflect, long_months)
elif date_val[1] == 0: # month is zero but day is not (see 8477)
return self.format_long_month_year(
date_val[1], year, inflect, long_months
)
elif