tweaks to Chinese date handlers (fix parsing, reduce date formats)
This commit is contained in:
parent
0ad582f7b0
commit
cbe83feeaa
@ -3,6 +3,7 @@
|
|||||||
# Gramps - a GTK+/GNOME based genealogy program
|
# Gramps - a GTK+/GNOME based genealogy program
|
||||||
#
|
#
|
||||||
# Copyright (C) 2004-2006 Donald N. Allingham
|
# Copyright (C) 2004-2006 Donald N. Allingham
|
||||||
|
# Copyright (C) 2014-2015 Paul Franklin
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or modify
|
# This program is free software; you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU General Public License as published by
|
# it under the terms of the GNU General Public License as published by
|
||||||
@ -16,7 +17,7 @@
|
|||||||
#
|
#
|
||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with this program; if not, write to the Free Software
|
# along with this program; if not, write to the Free Software
|
||||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
#
|
#
|
||||||
|
|
||||||
"""
|
"""
|
||||||
@ -123,12 +124,13 @@ class DateParserZH_CN(DateParser):
|
|||||||
_span_2 = ['至']
|
_span_2 = ['至']
|
||||||
_range_1 = ['介于']
|
_range_1 = ['介于']
|
||||||
_range_2 = ['与']
|
_range_2 = ['与']
|
||||||
self._span = re.compile("(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" %
|
self._span = re.compile("(%s)(?P<start>.+)(%s)(?P<stop>\d+)" %
|
||||||
('|'.join(_span_1), '|'.join(_span_2)),
|
('|'.join(_span_1), '|'.join(_span_2)),
|
||||||
re.IGNORECASE)
|
re.IGNORECASE)
|
||||||
self._range = re.compile("(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" %
|
self._range = re.compile("(%s)(?P<start>.+)(%s)(?P<stop>\d+)" %
|
||||||
('|'.join(_range_1), '|'.join(_range_2)),
|
('|'.join(_range_1), '|'.join(_range_2)),
|
||||||
re.IGNORECASE)
|
re.IGNORECASE)
|
||||||
|
self._numeric = re.compile("((\d+)年\s*)?((\d+)月\s*)?(\d+)?日?\s*$")
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
@ -140,66 +142,35 @@ class DateDisplayZH_CN(DateDisplay):
|
|||||||
Simplified-Chinese language date display class.
|
Simplified-Chinese language date display class.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# this is used to display the 12 gregorian months
|
|
||||||
long_months = ( "", "正月", "二月", "三月", "四月", "五月",
|
|
||||||
"六月", "七月", "八月", "九月", "十月",
|
|
||||||
"十一月", "十二月" )
|
|
||||||
|
|
||||||
short_months = ( "", "一月", "二月", "三月", "四月", "五月", "六月",
|
|
||||||
"七月", "八月", "九月", "十月", "十一月", "十二月" )
|
|
||||||
|
|
||||||
formats = (
|
formats = (
|
||||||
"年年年年-月月-日日 (ISO)", "数字格式", "月 日,年",
|
"年年年年-月月-日日 (ISO)", "数字格式",
|
||||||
"月 日,年", "日 月 年", "日 月 年",
|
|
||||||
)
|
)
|
||||||
# this must agree with DateDisplayEn's "formats" definition
|
# this definition must agree with its "_display_calendar" method
|
||||||
# (since no locale-specific _display_gregorian exists, here)
|
|
||||||
|
|
||||||
calendar = (
|
|
||||||
"", "儒略历", "希伯来历", "法国共和历",
|
|
||||||
"伊郎历", "伊斯兰历", "瑞典历"
|
|
||||||
)
|
|
||||||
|
|
||||||
_mod_str = ("", "以前 ", "以后 ", "大约 ", "", "", "")
|
|
||||||
|
|
||||||
_qual_str = ("", "据估计 ", "据计算 ", "")
|
|
||||||
|
|
||||||
# FIXME translate these English strings into simplified-Chinese ones
|
# FIXME translate these English strings into simplified-Chinese ones
|
||||||
_bce_str = "%s B.C.E."
|
_bce_str = "%s B.C.E."
|
||||||
|
|
||||||
|
display = DateDisplay.display_formatted
|
||||||
|
|
||||||
def display(self, date):
|
def _display_calendar(self, date_val, long_months, short_months = None,
|
||||||
"""
|
inflect=""):
|
||||||
Return a text string representing the date.
|
# this must agree with its locale-specific "formats" definition
|
||||||
"""
|
|
||||||
mod = date.get_modifier()
|
|
||||||
cal = date.get_calendar()
|
|
||||||
qual = date.get_quality()
|
|
||||||
start = date.get_start_date()
|
|
||||||
newyear = date.get_new_year()
|
|
||||||
|
|
||||||
qual_str = (self._qual_str)[qual]
|
if short_months is None:
|
||||||
|
# Let the short formats work the same as long formats
|
||||||
|
short_months = long_months
|
||||||
|
|
||||||
if mod == Date.MOD_TEXTONLY:
|
if self.format == 0:
|
||||||
return date.get_text()
|
return self.display_iso(date_val)
|
||||||
elif start == Date.EMPTY:
|
# elif self.format == 1:
|
||||||
return ""
|
|
||||||
elif mod == Date.MOD_SPAN:
|
|
||||||
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)
|
|
||||||
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)
|
|
||||||
else:
|
else:
|
||||||
text = self.display_cal[date.get_calendar()](start)
|
# numerical
|
||||||
scal = self.format_extras(cal, newyear)
|
value = self.dd_dformat01(date_val)
|
||||||
return "%s%s%s%s" % (qual_str, (self._mod_str)[mod], text,
|
if date_val[2] < 0:
|
||||||
scal)
|
# TODO fix BUG 7064: non-Gregorian calendars wrongly use BCE notation for negative dates
|
||||||
|
return self._bce_str % value
|
||||||
|
else:
|
||||||
|
return value
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
# Gramps - a GTK+/GNOME based genealogy program
|
# Gramps - a GTK+/GNOME based genealogy program
|
||||||
#
|
#
|
||||||
# Copyright (C) 2004-2006 Donald N. Allingham
|
# Copyright (C) 2004-2006 Donald N. Allingham
|
||||||
|
# Copyright (C) 2014-2015 Paul Franklin
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or modify
|
# This program is free software; you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU General Public License as published by
|
# it under the terms of the GNU General Public License as published by
|
||||||
@ -123,12 +124,13 @@ class DateParserZH_TW(DateParser):
|
|||||||
_span_2 = ['至']
|
_span_2 = ['至']
|
||||||
_range_1 = ['介於']
|
_range_1 = ['介於']
|
||||||
_range_2 = ['與']
|
_range_2 = ['與']
|
||||||
self._span = re.compile("(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" %
|
self._span = re.compile("(%s)(?P<start>.+)(%s)(?P<stop>\d+)" %
|
||||||
('|'.join(_span_1), '|'.join(_span_2)),
|
('|'.join(_span_1), '|'.join(_span_2)),
|
||||||
re.IGNORECASE)
|
re.IGNORECASE)
|
||||||
self._range = re.compile("(%s)\s+(?P<start>.+)\s+(%s)\s+(?P<stop>.+)" %
|
self._range = re.compile("(%s)(?P<start>.+)(%s)(?P<stop>\d+)" %
|
||||||
('|'.join(_range_1), '|'.join(_range_2)),
|
('|'.join(_range_1), '|'.join(_range_2)),
|
||||||
re.IGNORECASE)
|
re.IGNORECASE)
|
||||||
|
self._numeric = re.compile("((\d+)年\s*)?((\d+)月\s*)?(\d+)?日?\s*$")
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
@ -140,66 +142,35 @@ class DateDisplayZH_TW(DateDisplay):
|
|||||||
Traditional-Chinese language date display class.
|
Traditional-Chinese language date display class.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# this is used to display the 12 gregorian months
|
|
||||||
long_months = ( "", "正月", "二月", "三月", "四月", "五月",
|
|
||||||
"六月", "七月", "八月", "九月", "十月",
|
|
||||||
"十一月", "十二月" )
|
|
||||||
|
|
||||||
short_months = ( "", "一月", "二月", "三月", "四月", "五月", "六月",
|
|
||||||
"七月", "八月", "九月", "十月", "十一月", "十二月" )
|
|
||||||
|
|
||||||
formats = (
|
formats = (
|
||||||
"年年年年-月月-日日 (ISO)", "數字格式", "月 日,年",
|
"年年年年-月月-日日 (ISO)", "數字格式",
|
||||||
"月 日,年", "日 月 年", "日 月 年"
|
|
||||||
)
|
)
|
||||||
# this must agree with DateDisplayEn's "formats" definition
|
# this definition must agree with its "_display_calendar" method
|
||||||
# (since no locale-specific _display_gregorian exists, here)
|
|
||||||
|
|
||||||
calendar = (
|
|
||||||
"", "儒略曆", "希伯來歷", "法國共和歷",
|
|
||||||
"伊郎歷", "伊斯蘭曆", "瑞典歷"
|
|
||||||
)
|
|
||||||
|
|
||||||
_mod_str = ("", "以前 ", "以後 ", "大約 ", "", "", "")
|
|
||||||
|
|
||||||
_qual_str = ("", "據估計 ", "據計算 ", "")
|
|
||||||
|
|
||||||
# FIXME translate these English strings into traditional-Chinese ones
|
# FIXME translate these English strings into traditional-Chinese ones
|
||||||
_bce_str = "%s B.C.E."
|
_bce_str = "%s B.C.E."
|
||||||
|
|
||||||
|
display = DateDisplay.display_formatted
|
||||||
|
|
||||||
def display(self, date):
|
def _display_calendar(self, date_val, long_months, short_months = None,
|
||||||
"""
|
inflect=""):
|
||||||
Return a text string representing the date.
|
# this must agree with its locale-specific "formats" definition
|
||||||
"""
|
|
||||||
mod = date.get_modifier()
|
|
||||||
cal = date.get_calendar()
|
|
||||||
qual = date.get_quality()
|
|
||||||
start = date.get_start_date()
|
|
||||||
newyear = date.get_new_year()
|
|
||||||
|
|
||||||
qual_str = (self._qual_str)[qual]
|
if short_months is None:
|
||||||
|
# Let the short formats work the same as long formats
|
||||||
|
short_months = long_months
|
||||||
|
|
||||||
if mod == Date.MOD_TEXTONLY:
|
if self.format == 0:
|
||||||
return date.get_text()
|
return self.display_iso(date_val)
|
||||||
elif start == Date.EMPTY:
|
# elif self.format == 1:
|
||||||
return ""
|
|
||||||
elif mod == Date.MOD_SPAN:
|
|
||||||
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)
|
|
||||||
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)
|
|
||||||
else:
|
else:
|
||||||
text = self.display_cal[date.get_calendar()](start)
|
# numerical
|
||||||
scal = self.format_extras(cal, newyear)
|
value = self.dd_dformat01(date_val)
|
||||||
return "%s%s%s%s" % (qual_str, (self._mod_str)[mod], text,
|
if date_val[2] < 0:
|
||||||
scal)
|
# TODO fix BUG 7064: non-Gregorian calendars wrongly use BCE notation for negative dates
|
||||||
|
return self._bce_str % value
|
||||||
|
else:
|
||||||
|
return value
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
|
Loading…
x
Reference in New Issue
Block a user