4827: HTML-Export, make language selectable (WebCal)

This commit is contained in:
SNoiraud 2016-09-09 15:12:20 +02:00
parent bd221d6fcf
commit 9c3600b598

View File

@ -47,7 +47,6 @@ _LOG = logging.getLogger(".WebPage")
#------------------------------------------------------------------------
from gramps.gen.const import GRAMPS_LOCALE as glocale
_ = 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.date import Today
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()
lang = mgobn('trans')
self.rlocale = self.set_locale(lang)
self._ = self.rlocale.translation.sgettext
self.html_dir = mgobn('target')
self.title_text = mgobn('title')
filter_option = options.menu.get_option_by_name('filter')
@ -416,7 +419,8 @@ class WebCalReport(Report):
# Header contants
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"'
_meta3 = 'name="generator" content="%s %s %s"' % (
PROGRAM_NAME, VERSION, URL_HOMEPAGE)
@ -478,7 +482,7 @@ class WebCalReport(Report):
# Created for ?
msg = None
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'
'WebCal%(html_email_author_end)s') % {
'html_email_author_start' :
@ -486,7 +490,8 @@ class WebCalReport(Report):
'html_email_author_end' :
'">' + self.author + '</a>'}
elif self.author:
msg = _('Created for %(author)s') % {'author' : self.author}
msg = self._('Created for %(author)s') % {
'author' : self.author}
if msg:
header += Html("p", msg, id="CreatorInfo")
@ -522,7 +527,8 @@ class WebCalReport(Report):
# each year will link to current month.
# 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
# pathname.
@ -532,7 +538,8 @@ class WebCalReport(Report):
# Figure out if we need <li class="CurrentSection">
# 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:
unordered.extend(
Html("li", hyper, attr=check_cs, inline=True)
@ -558,13 +565,13 @@ class WebCalReport(Report):
# An optional link to a home page
if self.home_link:
navs.append((self.home_link, _('Home'), add_home))
navs.extend((date_displayer.long_months[month],
date_displayer.short_months[month], True)
navs.append((self.home_link, self._('Home'), add_home))
navs.extend((self.rlocale.date_displayer.long_months[int(month)],
self.rlocale.date_displayer.short_months[int(month)], True)
for month in range(1, 13))
# 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
navs = [(u, n) for u, n, c in navs if c]
@ -602,11 +609,11 @@ class WebCalReport(Report):
'class = "CurrentSection"' or False
if url == self.home_link:
mytitle = _("NarrativeWeb Home")
mytitle = self._("NarrativeWeb Home")
elif url_fname == 'fullyearlinked':
mytitle = _('Full year at a Glance')
mytitle = self._('Full year at a Glance')
else:
mytitle = _(url_fname)
mytitle = self._(url_fname)
hyper = Html("a", nav_text, href=url,
name=url_fname, title=mytitle)
@ -631,9 +638,10 @@ class WebCalReport(Report):
@param: month - month number 1, 2, .., 12
"""
date_displayer = self.rlocale.date_displayer
# define names for long and short month names
full_month_name = date_displayer.long_months[month]
abbr_month_name = date_displayer.short_months[month]
full_month_name = date_displayer.long_months[int(month)]
abbr_month_name = date_displayer.short_months[int(month)]
# dow (day-of-week) uses Gramps numbering, sunday => 1, etc
start_dow = self.start_dow
@ -749,6 +757,7 @@ class WebCalReport(Report):
my_title += Html("a", _escape(">"), href=dest,
title=date_displayer.display(nexty))
my_title += Html("</a>")
#print(my_title)
trow = Html("tr") + (
Html("th", my_title, class_='monthName',
colspan=7, inline=True)
@ -765,7 +774,7 @@ class WebCalReport(Report):
for day_col in range(7):
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) + (
Html('abbr', dayname[0], title=dayname))
@ -834,7 +843,8 @@ class WebCalReport(Report):
# get events for this day
day_list = get_day_list(event_date, holiday_list,
bday_anniv_list)
bday_anniv_list,
rlocale=self.rlocale)
# is there something this day?
if day_list:
@ -956,7 +966,7 @@ class WebCalReport(Report):
_('Formatting months ...'), 12) as step:
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))
# Add xml, doctype, meta and stylesheets
@ -1043,7 +1053,7 @@ class WebCalReport(Report):
of = self.create_file('fullyearlinked', str(year))
# page title
title = _("%(year)d, At A Glance") % {'year' : year}
title = self._("%(year)d, At A Glance") % {'year' : year}
# Create page header
# body has already been added to yearglance already once
@ -1058,7 +1068,7 @@ class WebCalReport(Report):
# identify currentsection for proper highlighting
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. '
'Clicking on a date will take you to a page that shows all'
' 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))
# page title
title = _('One Day Within A Year')
title = self._('One Day Within A Year')
# create page header
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]),
int(event[1][6:]))
my_title = Html("a", _escape("<"), href=url,
title=date_displayer.display(prevd))
title=self.rlocale.get_date(prevd))
else:
my_title = Html('<em>&nbsp;&nbsp;</em>')
my_title += Html("</a>&nbsp;")
@ -1150,13 +1160,13 @@ class WebCalReport(Report):
nextd = Date(int(event[2][:4]), int(event[2][4:6]),
int(event[2][6:]))
my_title += Html("a", _escape(">"), href=url,
title=date_displayer.display(nextd))
title=self.rlocale.get_date(nextd))
else:
my_title += Html('<b>&nbsp;&nbsp;</b>')
my_title += Html("</a>")
content += Html("h3", my_title, inline=True)
my_title = Html("span", " ")
my_title += date_displayer.display(event_date)
my_title += self.rlocale.date_displayer.display(event_date)
my_title += Html("span", " ")
content += Html("h3", my_title, inline=True)
@ -1323,11 +1333,12 @@ class WebCalReport(Report):
# add link to NarrativeWeb
if self.link_to_narweb:
prfx = self.narweb_prefix
text = str(Html("a", short_name,
href=self.build_url_fname_html(
person.handle,
"ppl",
prefix=self.narweb_prefix)))
prefix=prfx)))
else:
text = short_name
if age_at_death is None:
@ -1368,7 +1379,8 @@ class WebCalReport(Report):
if person_death == Date():
first_died = spouse_death
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:
first_died = person_death
@ -1409,7 +1421,8 @@ class WebCalReport(Report):
if ((self.alive and alive1
and alive2) or not self.alive):
text = _('%(spouse)s and %(person)s') % {
msg = '%(spouse)s and %(person)s'
text = self._(msg) % {
'spouse' : spouse_name,
'person' : short_name}
@ -1429,12 +1442,12 @@ class WebCalReport(Report):
with Html("div", id="footer", role="Footer-End") as footer:
# 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_home_html_start' :
'<a href="' + URL_HOMEPAGE + '">',
'html_end' : '</a>',
'date' : date_displayer.display(Today())}
'date' : self.rlocale.date_displayer.display(Today())}
footer += Html("p", msg, id='createdate')
copy_nr = self.copy
@ -1535,7 +1548,7 @@ class WebCalReport(Report):
output_file = self.create_file('index', "")
# page title
title = _("My Family Calendar")
title = self._("My Family Calendar")
nr_up = 0
@ -1658,6 +1671,7 @@ class WebCalOptions(MenuReportOptions):
css.add_item(css_item[1], css_item[0])
css.set_help(_('The stylesheet to be used for the web pages'))
menu.add_option(category_name, "css", css)
stdoptions.add_localization_option(menu, category_name)
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)
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()
@ -1941,8 +1955,10 @@ def get_day_list(event_date, holiday_list, bday_anniv_list):
to create one day nyears, date, text, event --- are
necessary for figuring the age or years married for
each day being created...
rlocale -- the locale to use
"""
trans_text = rlocale.translation.sgettext
# initialize 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
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
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
age = ', <em>'
date_y = date.get_year()
age += _('%s old') % str(age_str) if date_y != 0 else \
_("Born %(birth_date)s.") % {
age += trans_text('%s old') % str(age_str) if date_y != 0 else \
trans_text("Born %(birth_date)s.") % {
'birth_date' : dead_event_date}
txt_str = (text + age + '</em>')
@ -1996,15 +2014,15 @@ def get_day_list(event_date, holiday_list, bday_anniv_list):
elif event == "Anniversary":
if nyears == 0:
txt_str = _('%(couple)s, <em>wedding</em>') % {
txt_str = trans_text('%(couple)s, <em>wedding</em>') % {
'couple' : text}
else:
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)
if isinstance(dead_event_date,
Date) and dead_event_date.get_year() > 0:
txt_str += " (" + _("Until") + " "
txt_str += " (" + trans_text("Until") + " "
txt_str += str(dead_event_date)
txt_str += ")</em>"
else:
@ -2012,6 +2030,7 @@ def get_day_list(event_date, holiday_list, bday_anniv_list):
else:
age = '<em>%s' % nyears
# translators: leave all/any {...} untranslated
ngettext = rlocale.translation.ngettext
txt_str = ngettext("{couple}, {years} year anniversary",
"{couple}, {years} year anniversary",
nyears).format(couple=text, years=age)