4827: HTML-Export, make language selectable (WebCal)
This commit is contained in:
parent
bd221d6fcf
commit
9c3600b598
@ -47,7 +47,6 @@ _LOG = logging.getLogger(".WebPage")
|
|||||||
#------------------------------------------------------------------------
|
#------------------------------------------------------------------------
|
||||||
from gramps.gen.const import GRAMPS_LOCALE as glocale
|
from gramps.gen.const import GRAMPS_LOCALE as glocale
|
||||||
_ = glocale.translation.sgettext
|
_ = glocale.translation.sgettext
|
||||||
ngettext = glocale.translation.ngettext # else "nearby" comments are ignored
|
|
||||||
from gramps.gen.lib import Date, Name, NameType, Person
|
from gramps.gen.lib import Date, Name, NameType, Person
|
||||||
from gramps.gen.lib.date import Today
|
from gramps.gen.lib.date import Today
|
||||||
from gramps.gen.const import PROGRAM_NAME, URL_HOMEPAGE
|
from gramps.gen.const import PROGRAM_NAME, URL_HOMEPAGE
|
||||||
@ -127,6 +126,10 @@ class WebCalReport(Report):
|
|||||||
|
|
||||||
mgobn = lambda name: options.menu.get_option_by_name(name).get_value()
|
mgobn = lambda name: options.menu.get_option_by_name(name).get_value()
|
||||||
|
|
||||||
|
lang = mgobn('trans')
|
||||||
|
self.rlocale = self.set_locale(lang)
|
||||||
|
self._ = self.rlocale.translation.sgettext
|
||||||
|
|
||||||
self.html_dir = mgobn('target')
|
self.html_dir = mgobn('target')
|
||||||
self.title_text = mgobn('title')
|
self.title_text = mgobn('title')
|
||||||
filter_option = options.menu.get_option_by_name('filter')
|
filter_option = options.menu.get_option_by_name('filter')
|
||||||
@ -416,7 +419,8 @@ class WebCalReport(Report):
|
|||||||
|
|
||||||
# Header contants
|
# Header contants
|
||||||
xmllang = xml_lang()
|
xmllang = xml_lang()
|
||||||
_meta1 = 'name ="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=1"'
|
_meta1 = 'name ="viewport" content="width=device-width, '\
|
||||||
|
'initial-scale=1.0, maximum-scale=1.0, user-scalable=1"'
|
||||||
_meta2 = 'name ="apple-mobile-web-app-capable" content="yes"'
|
_meta2 = 'name ="apple-mobile-web-app-capable" content="yes"'
|
||||||
_meta3 = 'name="generator" content="%s %s %s"' % (
|
_meta3 = 'name="generator" content="%s %s %s"' % (
|
||||||
PROGRAM_NAME, VERSION, URL_HOMEPAGE)
|
PROGRAM_NAME, VERSION, URL_HOMEPAGE)
|
||||||
@ -478,7 +482,7 @@ class WebCalReport(Report):
|
|||||||
# Created for ?
|
# Created for ?
|
||||||
msg = None
|
msg = None
|
||||||
if self.author and self.email:
|
if self.author and self.email:
|
||||||
msg = _('the "WebCal" will be the potential-email Subject|'
|
msg = self._('the "WebCal" will be the potential-email Subject|'
|
||||||
'Created for %(html_email_author_start)s'
|
'Created for %(html_email_author_start)s'
|
||||||
'WebCal%(html_email_author_end)s') % {
|
'WebCal%(html_email_author_end)s') % {
|
||||||
'html_email_author_start' :
|
'html_email_author_start' :
|
||||||
@ -486,7 +490,8 @@ class WebCalReport(Report):
|
|||||||
'html_email_author_end' :
|
'html_email_author_end' :
|
||||||
'">' + self.author + '</a>'}
|
'">' + self.author + '</a>'}
|
||||||
elif self.author:
|
elif self.author:
|
||||||
msg = _('Created for %(author)s') % {'author' : self.author}
|
msg = self._('Created for %(author)s') % {
|
||||||
|
'author' : self.author}
|
||||||
|
|
||||||
if msg:
|
if msg:
|
||||||
header += Html("p", msg, id="CreatorInfo")
|
header += Html("p", msg, id="CreatorInfo")
|
||||||
@ -522,7 +527,8 @@ class WebCalReport(Report):
|
|||||||
|
|
||||||
# each year will link to current month.
|
# each year will link to current month.
|
||||||
# this will always need an extension added
|
# this will always need an extension added
|
||||||
full_month_name = date_displayer.long_months[self.today.get_month()]
|
month = int(self.today.get_month())
|
||||||
|
full_month_name = self.rlocale.date_displayer.long_months[month]
|
||||||
|
|
||||||
# Note. We use '/' here because it is a URL, not a OS dependent
|
# Note. We use '/' here because it is a URL, not a OS dependent
|
||||||
# pathname.
|
# pathname.
|
||||||
@ -532,7 +538,8 @@ class WebCalReport(Report):
|
|||||||
|
|
||||||
# Figure out if we need <li class="CurrentSection">
|
# Figure out if we need <li class="CurrentSection">
|
||||||
# or just plain <li>
|
# or just plain <li>
|
||||||
check_cs = str(cal_year) == currentsection and 'class = "CurrentSection"' or False
|
check_cs = str(cal_year) == currentsection and\
|
||||||
|
'class = "CurrentSection"' or False
|
||||||
if check_cs:
|
if check_cs:
|
||||||
unordered.extend(
|
unordered.extend(
|
||||||
Html("li", hyper, attr=check_cs, inline=True)
|
Html("li", hyper, attr=check_cs, inline=True)
|
||||||
@ -558,13 +565,13 @@ class WebCalReport(Report):
|
|||||||
|
|
||||||
# An optional link to a home page
|
# An optional link to a home page
|
||||||
if self.home_link:
|
if self.home_link:
|
||||||
navs.append((self.home_link, _('Home'), add_home))
|
navs.append((self.home_link, self._('Home'), add_home))
|
||||||
navs.extend((date_displayer.long_months[month],
|
navs.extend((self.rlocale.date_displayer.long_months[int(month)],
|
||||||
date_displayer.short_months[month], True)
|
self.rlocale.date_displayer.short_months[int(month)], True)
|
||||||
for month in range(1, 13))
|
for month in range(1, 13))
|
||||||
|
|
||||||
# Add a link for year_glance() if requested
|
# Add a link for year_glance() if requested
|
||||||
navs.append(('fullyearlinked', _('Year Glance'), self.fullyear))
|
navs.append(('fullyearlinked', self._('Year Glance'), self.fullyear))
|
||||||
|
|
||||||
# remove menu items if they are not True
|
# remove menu items if they are not True
|
||||||
navs = [(u, n) for u, n, c in navs if c]
|
navs = [(u, n) for u, n, c in navs if c]
|
||||||
@ -602,11 +609,11 @@ class WebCalReport(Report):
|
|||||||
'class = "CurrentSection"' or False
|
'class = "CurrentSection"' or False
|
||||||
|
|
||||||
if url == self.home_link:
|
if url == self.home_link:
|
||||||
mytitle = _("NarrativeWeb Home")
|
mytitle = self._("NarrativeWeb Home")
|
||||||
elif url_fname == 'fullyearlinked':
|
elif url_fname == 'fullyearlinked':
|
||||||
mytitle = _('Full year at a Glance')
|
mytitle = self._('Full year at a Glance')
|
||||||
else:
|
else:
|
||||||
mytitle = _(url_fname)
|
mytitle = self._(url_fname)
|
||||||
hyper = Html("a", nav_text, href=url,
|
hyper = Html("a", nav_text, href=url,
|
||||||
name=url_fname, title=mytitle)
|
name=url_fname, title=mytitle)
|
||||||
|
|
||||||
@ -631,9 +638,10 @@ class WebCalReport(Report):
|
|||||||
@param: month - month number 1, 2, .., 12
|
@param: month - month number 1, 2, .., 12
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
date_displayer = self.rlocale.date_displayer
|
||||||
# define names for long and short month names
|
# define names for long and short month names
|
||||||
full_month_name = date_displayer.long_months[month]
|
full_month_name = date_displayer.long_months[int(month)]
|
||||||
abbr_month_name = date_displayer.short_months[month]
|
abbr_month_name = date_displayer.short_months[int(month)]
|
||||||
|
|
||||||
# dow (day-of-week) uses Gramps numbering, sunday => 1, etc
|
# dow (day-of-week) uses Gramps numbering, sunday => 1, etc
|
||||||
start_dow = self.start_dow
|
start_dow = self.start_dow
|
||||||
@ -749,6 +757,7 @@ class WebCalReport(Report):
|
|||||||
my_title += Html("a", _escape(">"), href=dest,
|
my_title += Html("a", _escape(">"), href=dest,
|
||||||
title=date_displayer.display(nexty))
|
title=date_displayer.display(nexty))
|
||||||
my_title += Html("</a>")
|
my_title += Html("</a>")
|
||||||
|
#print(my_title)
|
||||||
trow = Html("tr") + (
|
trow = Html("tr") + (
|
||||||
Html("th", my_title, class_='monthName',
|
Html("th", my_title, class_='monthName',
|
||||||
colspan=7, inline=True)
|
colspan=7, inline=True)
|
||||||
@ -765,7 +774,7 @@ class WebCalReport(Report):
|
|||||||
|
|
||||||
for day_col in range(7):
|
for day_col in range(7):
|
||||||
dayclass = get_class_for_daycol(day_col)
|
dayclass = get_class_for_daycol(day_col)
|
||||||
dayname = get_name_for_daycol(day_col)
|
dayname = self._(get_name_for_daycol(day_col))
|
||||||
trow += Html("th", class_=dayclass, inline=True) + (
|
trow += Html("th", class_=dayclass, inline=True) + (
|
||||||
Html('abbr', dayname[0], title=dayname))
|
Html('abbr', dayname[0], title=dayname))
|
||||||
|
|
||||||
@ -834,7 +843,8 @@ class WebCalReport(Report):
|
|||||||
|
|
||||||
# get events for this day
|
# get events for this day
|
||||||
day_list = get_day_list(event_date, holiday_list,
|
day_list = get_day_list(event_date, holiday_list,
|
||||||
bday_anniv_list)
|
bday_anniv_list,
|
||||||
|
rlocale=self.rlocale)
|
||||||
|
|
||||||
# is there something this day?
|
# is there something this day?
|
||||||
if day_list:
|
if day_list:
|
||||||
@ -956,7 +966,7 @@ class WebCalReport(Report):
|
|||||||
_('Formatting months ...'), 12) as step:
|
_('Formatting months ...'), 12) as step:
|
||||||
|
|
||||||
for month in range(1, 13):
|
for month in range(1, 13):
|
||||||
cal_fname = date_displayer.long_months[month]
|
cal_fname = self.rlocale.date_displayer.long_months[int(month)]
|
||||||
of = self.create_file(cal_fname, str(year))
|
of = self.create_file(cal_fname, str(year))
|
||||||
|
|
||||||
# Add xml, doctype, meta and stylesheets
|
# Add xml, doctype, meta and stylesheets
|
||||||
@ -1043,7 +1053,7 @@ class WebCalReport(Report):
|
|||||||
of = self.create_file('fullyearlinked', str(year))
|
of = self.create_file('fullyearlinked', str(year))
|
||||||
|
|
||||||
# page title
|
# page title
|
||||||
title = _("%(year)d, At A Glance") % {'year' : year}
|
title = self._("%(year)d, At A Glance") % {'year' : year}
|
||||||
|
|
||||||
# Create page header
|
# Create page header
|
||||||
# body has already been added to yearglance already once
|
# body has already been added to yearglance already once
|
||||||
@ -1058,7 +1068,7 @@ class WebCalReport(Report):
|
|||||||
# identify currentsection for proper highlighting
|
# identify currentsection for proper highlighting
|
||||||
body += self.month_navigation(nr_up, year, "fullyearlinked", True)
|
body += self.month_navigation(nr_up, year, "fullyearlinked", True)
|
||||||
|
|
||||||
msg = (_('This calendar is meant to give you access '
|
msg = (self._('This calendar is meant to give you access '
|
||||||
'to all your data at a glance compressed into one page. '
|
'to all your data at a glance compressed into one page. '
|
||||||
'Clicking on a date will take you to a page that shows all'
|
'Clicking on a date will take you to a page that shows all'
|
||||||
' the events for that date, if there are any.\n'))
|
' the events for that date, if there are any.\n'))
|
||||||
@ -1111,7 +1121,7 @@ class WebCalReport(Report):
|
|||||||
one_day_file = self.create_file(fname_date, str(year))
|
one_day_file = self.create_file(fname_date, str(year))
|
||||||
|
|
||||||
# page title
|
# page title
|
||||||
title = _('One Day Within A Year')
|
title = self._('One Day Within A Year')
|
||||||
|
|
||||||
# create page header
|
# create page header
|
||||||
oneday, body = self.write_header(nr_up, title, "OneDay")
|
oneday, body = self.write_header(nr_up, title, "OneDay")
|
||||||
@ -1141,7 +1151,7 @@ class WebCalReport(Report):
|
|||||||
prevd = Date(int(event[1][:4]), int(event[1][4:6]),
|
prevd = Date(int(event[1][:4]), int(event[1][4:6]),
|
||||||
int(event[1][6:]))
|
int(event[1][6:]))
|
||||||
my_title = Html("a", _escape("<"), href=url,
|
my_title = Html("a", _escape("<"), href=url,
|
||||||
title=date_displayer.display(prevd))
|
title=self.rlocale.get_date(prevd))
|
||||||
else:
|
else:
|
||||||
my_title = Html('<em> </em>')
|
my_title = Html('<em> </em>')
|
||||||
my_title += Html("</a> ")
|
my_title += Html("</a> ")
|
||||||
@ -1150,13 +1160,13 @@ class WebCalReport(Report):
|
|||||||
nextd = Date(int(event[2][:4]), int(event[2][4:6]),
|
nextd = Date(int(event[2][:4]), int(event[2][4:6]),
|
||||||
int(event[2][6:]))
|
int(event[2][6:]))
|
||||||
my_title += Html("a", _escape(">"), href=url,
|
my_title += Html("a", _escape(">"), href=url,
|
||||||
title=date_displayer.display(nextd))
|
title=self.rlocale.get_date(nextd))
|
||||||
else:
|
else:
|
||||||
my_title += Html('<b> </b>')
|
my_title += Html('<b> </b>')
|
||||||
my_title += Html("</a>")
|
my_title += Html("</a>")
|
||||||
content += Html("h3", my_title, inline=True)
|
content += Html("h3", my_title, inline=True)
|
||||||
my_title = Html("span", " ")
|
my_title = Html("span", " ")
|
||||||
my_title += date_displayer.display(event_date)
|
my_title += self.rlocale.date_displayer.display(event_date)
|
||||||
my_title += Html("span", " ")
|
my_title += Html("span", " ")
|
||||||
content += Html("h3", my_title, inline=True)
|
content += Html("h3", my_title, inline=True)
|
||||||
|
|
||||||
@ -1323,11 +1333,12 @@ class WebCalReport(Report):
|
|||||||
|
|
||||||
# add link to NarrativeWeb
|
# add link to NarrativeWeb
|
||||||
if self.link_to_narweb:
|
if self.link_to_narweb:
|
||||||
|
prfx = self.narweb_prefix
|
||||||
text = str(Html("a", short_name,
|
text = str(Html("a", short_name,
|
||||||
href=self.build_url_fname_html(
|
href=self.build_url_fname_html(
|
||||||
person.handle,
|
person.handle,
|
||||||
"ppl",
|
"ppl",
|
||||||
prefix=self.narweb_prefix)))
|
prefix=prfx)))
|
||||||
else:
|
else:
|
||||||
text = short_name
|
text = short_name
|
||||||
if age_at_death is None:
|
if age_at_death is None:
|
||||||
@ -1368,7 +1379,8 @@ class WebCalReport(Report):
|
|||||||
if person_death == Date():
|
if person_death == Date():
|
||||||
first_died = spouse_death
|
first_died = spouse_death
|
||||||
elif spouse_death != Date():
|
elif spouse_death != Date():
|
||||||
first_died = person_death if spouse_death > person_death else spouse_death
|
first_died = person_death if spouse_death\
|
||||||
|
> person_death else spouse_death
|
||||||
else:
|
else:
|
||||||
first_died = person_death
|
first_died = person_death
|
||||||
|
|
||||||
@ -1409,7 +1421,8 @@ class WebCalReport(Report):
|
|||||||
if ((self.alive and alive1
|
if ((self.alive and alive1
|
||||||
and alive2) or not self.alive):
|
and alive2) or not self.alive):
|
||||||
|
|
||||||
text = _('%(spouse)s and %(person)s') % {
|
msg = '%(spouse)s and %(person)s'
|
||||||
|
text = self._(msg) % {
|
||||||
'spouse' : spouse_name,
|
'spouse' : spouse_name,
|
||||||
'person' : short_name}
|
'person' : short_name}
|
||||||
|
|
||||||
@ -1429,12 +1442,12 @@ class WebCalReport(Report):
|
|||||||
with Html("div", id="footer", role="Footer-End") as footer:
|
with Html("div", id="footer", role="Footer-End") as footer:
|
||||||
|
|
||||||
# Display date as user set in preferences
|
# Display date as user set in preferences
|
||||||
msg = _('Generated by %(gramps_home_html_start)s'
|
msg = self._('Generated by %(gramps_home_html_start)s'
|
||||||
'Gramps%(html_end)s on %(date)s') % {
|
'Gramps%(html_end)s on %(date)s') % {
|
||||||
'gramps_home_html_start' :
|
'gramps_home_html_start' :
|
||||||
'<a href="' + URL_HOMEPAGE + '">',
|
'<a href="' + URL_HOMEPAGE + '">',
|
||||||
'html_end' : '</a>',
|
'html_end' : '</a>',
|
||||||
'date' : date_displayer.display(Today())}
|
'date' : self.rlocale.date_displayer.display(Today())}
|
||||||
footer += Html("p", msg, id='createdate')
|
footer += Html("p", msg, id='createdate')
|
||||||
|
|
||||||
copy_nr = self.copy
|
copy_nr = self.copy
|
||||||
@ -1535,7 +1548,7 @@ class WebCalReport(Report):
|
|||||||
output_file = self.create_file('index', "")
|
output_file = self.create_file('index', "")
|
||||||
|
|
||||||
# page title
|
# page title
|
||||||
title = _("My Family Calendar")
|
title = self._("My Family Calendar")
|
||||||
|
|
||||||
nr_up = 0
|
nr_up = 0
|
||||||
|
|
||||||
@ -1658,6 +1671,7 @@ class WebCalOptions(MenuReportOptions):
|
|||||||
css.add_item(css_item[1], css_item[0])
|
css.add_item(css_item[1], css_item[0])
|
||||||
css.set_help(_('The stylesheet to be used for the web pages'))
|
css.set_help(_('The stylesheet to be used for the web pages'))
|
||||||
menu.add_option(category_name, "css", css)
|
menu.add_option(category_name, "css", css)
|
||||||
|
stdoptions.add_localization_option(menu, category_name)
|
||||||
|
|
||||||
def __add_content_options(self, menu):
|
def __add_content_options(self, menu):
|
||||||
"""
|
"""
|
||||||
@ -1927,7 +1941,7 @@ def _has_webpage_extension(url):
|
|||||||
"""
|
"""
|
||||||
return any(url.endswith(ext) for ext in _WEB_EXT)
|
return any(url.endswith(ext) for ext in _WEB_EXT)
|
||||||
|
|
||||||
def get_day_list(event_date, holiday_list, bday_anniv_list):
|
def get_day_list(event_date, holiday_list, bday_anniv_list, rlocale=glocale):
|
||||||
"""
|
"""
|
||||||
Will fill day_list and return it to its caller: calendar_build()
|
Will fill day_list and return it to its caller: calendar_build()
|
||||||
|
|
||||||
@ -1941,8 +1955,10 @@ def get_day_list(event_date, holiday_list, bday_anniv_list):
|
|||||||
to create one day nyears, date, text, event --- are
|
to create one day nyears, date, text, event --- are
|
||||||
necessary for figuring the age or years married for
|
necessary for figuring the age or years married for
|
||||||
each day being created...
|
each day being created...
|
||||||
|
rlocale -- the locale to use
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
trans_text = rlocale.translation.sgettext
|
||||||
# initialize day_list
|
# initialize day_list
|
||||||
day_list = []
|
day_list = []
|
||||||
|
|
||||||
@ -1971,7 +1987,9 @@ def get_day_list(event_date, holiday_list, bday_anniv_list):
|
|||||||
|
|
||||||
# number of years for birthday, ex: 10 years
|
# number of years for birthday, ex: 10 years
|
||||||
age_str = event_date - date
|
age_str = event_date - date
|
||||||
age_str.format(precision=1, as_age=False)
|
#age_str.format(precision=1, as_age=False, dlocale=rlocale)
|
||||||
|
age_str = age_str.format(precision=1, as_age=False, dlocale=rlocale)
|
||||||
|
|
||||||
|
|
||||||
# a birthday
|
# a birthday
|
||||||
if event == 'Birthday':
|
if event == 'Birthday':
|
||||||
@ -1987,8 +2005,8 @@ def get_day_list(event_date, holiday_list, bday_anniv_list):
|
|||||||
# where "12 years" is already localized to your language
|
# where "12 years" is already localized to your language
|
||||||
age = ', <em>'
|
age = ', <em>'
|
||||||
date_y = date.get_year()
|
date_y = date.get_year()
|
||||||
age += _('%s old') % str(age_str) if date_y != 0 else \
|
age += trans_text('%s old') % str(age_str) if date_y != 0 else \
|
||||||
_("Born %(birth_date)s.") % {
|
trans_text("Born %(birth_date)s.") % {
|
||||||
'birth_date' : dead_event_date}
|
'birth_date' : dead_event_date}
|
||||||
txt_str = (text + age + '</em>')
|
txt_str = (text + age + '</em>')
|
||||||
|
|
||||||
@ -1996,15 +2014,15 @@ def get_day_list(event_date, holiday_list, bday_anniv_list):
|
|||||||
elif event == "Anniversary":
|
elif event == "Anniversary":
|
||||||
|
|
||||||
if nyears == 0:
|
if nyears == 0:
|
||||||
txt_str = _('%(couple)s, <em>wedding</em>') % {
|
txt_str = trans_text('%(couple)s, <em>wedding</em>') % {
|
||||||
'couple' : text}
|
'couple' : text}
|
||||||
else:
|
else:
|
||||||
if age_at_death is not None:
|
if age_at_death is not None:
|
||||||
age = '%s %s' % (_("Married"), age_at_death)
|
age = '%s %s' % (trans_text("Married"), age_at_death)
|
||||||
txt_str = "%s, <em>%s" % (text, age)
|
txt_str = "%s, <em>%s" % (text, age)
|
||||||
if isinstance(dead_event_date,
|
if isinstance(dead_event_date,
|
||||||
Date) and dead_event_date.get_year() > 0:
|
Date) and dead_event_date.get_year() > 0:
|
||||||
txt_str += " (" + _("Until") + " "
|
txt_str += " (" + trans_text("Until") + " "
|
||||||
txt_str += str(dead_event_date)
|
txt_str += str(dead_event_date)
|
||||||
txt_str += ")</em>"
|
txt_str += ")</em>"
|
||||||
else:
|
else:
|
||||||
@ -2012,6 +2030,7 @@ def get_day_list(event_date, holiday_list, bday_anniv_list):
|
|||||||
else:
|
else:
|
||||||
age = '<em>%s' % nyears
|
age = '<em>%s' % nyears
|
||||||
# translators: leave all/any {...} untranslated
|
# translators: leave all/any {...} untranslated
|
||||||
|
ngettext = rlocale.translation.ngettext
|
||||||
txt_str = ngettext("{couple}, {years} year anniversary",
|
txt_str = ngettext("{couple}, {years} year anniversary",
|
||||||
"{couple}, {years} year anniversary",
|
"{couple}, {years} year anniversary",
|
||||||
nyears).format(couple=text, years=age)
|
nyears).format(couple=text, years=age)
|
||||||
|
Loading…
Reference in New Issue
Block a user