enable translated output for this report
svn: r22263
This commit is contained in:
parent
0ce4b749d0
commit
fcd2296461
@ -4,7 +4,7 @@
|
||||
# Copyright (C) 2008-2009 Brian G. Matherly
|
||||
# Copyright (C) 2009 Rob G. Healey <robhealey1@gmail.com>
|
||||
# Copyright (C) 2010 Jakim Friant
|
||||
# Copyright (C) 2012 Paul Franklin
|
||||
# Copyright (C) 2012-2013 Paul Franklin
|
||||
#
|
||||
# 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
|
||||
@ -29,9 +29,6 @@
|
||||
#
|
||||
#------------------------------------------------------------------------
|
||||
import copy
|
||||
from gramps.gen.const import GRAMPS_LOCALE as glocale
|
||||
_ = glocale.translation.gettext
|
||||
ngettext = glocale.translation.ngettext
|
||||
import datetime, time
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
@ -39,25 +36,36 @@ import datetime, time
|
||||
# GRAMPS modules
|
||||
#
|
||||
#------------------------------------------------------------------------
|
||||
from gramps.gen.const import GRAMPS_LOCALE as glocale
|
||||
_ = glocale.translation.gettext
|
||||
from gramps.gen.const import URL_HOMEPAGE
|
||||
from gramps.gen.display.name import displayer as global_name_display
|
||||
from gramps.gen.errors import ReportError
|
||||
from gramps.gen.lib import NameType, EventType, Name, Date, Person, Surname
|
||||
from gramps.gen.relationship import get_relationship_calculator
|
||||
from gramps.gen.plug.docgen import (FontStyle, ParagraphStyle, GraphicsStyle,
|
||||
FONT_SERIF, PARA_ALIGN_RIGHT,
|
||||
PARA_ALIGN_LEFT, PARA_ALIGN_CENTER,
|
||||
IndexMark, INDEX_TYPE_TOC)
|
||||
FONT_SERIF, PARA_ALIGN_RIGHT,
|
||||
PARA_ALIGN_LEFT, PARA_ALIGN_CENTER,
|
||||
IndexMark, INDEX_TYPE_TOC)
|
||||
from gramps.gen.plug.menu import (BooleanOption, StringOption, NumberOption,
|
||||
EnumeratedListOption, FilterOption, PersonOption)
|
||||
EnumeratedListOption, FilterOption,
|
||||
PersonOption)
|
||||
from gramps.gen.plug.report import Report
|
||||
from gramps.gen.plug.report import utils as ReportUtils
|
||||
from gramps.gen.plug.report import MenuReportOptions
|
||||
from gramps.gen.plug.report import stdoptions
|
||||
from gramps.gen.utils.alive import probably_alive
|
||||
from gramps.gen.datehandler import displayer as _dd, long_days
|
||||
from gramps.gen.datehandler import long_days
|
||||
|
||||
import gramps.plugins.lib.libholiday as libholiday
|
||||
|
||||
def _T_(value): # enable deferred translations (see Python docs 22.1.3.4)
|
||||
return value
|
||||
|
||||
_TITLE0 = _T_("Birthday and Anniversary Report")
|
||||
_TITLE1 = _T_("My Birthday Report")
|
||||
_TITLE2 = _T_("Produced with Gramps")
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
#
|
||||
# BirthdayReport
|
||||
@ -100,6 +108,9 @@ class BirthdayReport(Report):
|
||||
if (self.center_person == None) :
|
||||
raise ReportError(_("Person %s is not in the Database") % pid )
|
||||
|
||||
lang = menu.get_option_by_name('trans').get_value()
|
||||
self._locale = self.set_locale(lang)
|
||||
|
||||
def get_name(self, person, maiden_name = None):
|
||||
"""
|
||||
Return person's name, unless maiden_name given, unless married_name
|
||||
@ -142,10 +153,24 @@ class BirthdayReport(Report):
|
||||
for day in range(1, 32):
|
||||
holiday_names = holiday_table.get_holidays(month, day)
|
||||
for holiday_name in holiday_names:
|
||||
self.add_day_item(holiday_name, month, day)
|
||||
self.add_day_item(self._(holiday_name), month, day)
|
||||
# FIXME translation only works for a limited set of things
|
||||
# (the right fix is to somehow feed the locale into the
|
||||
# HolidayTable class in plugins/lib/libholiday.py and then
|
||||
# probably changing all the holiday code to somehow defer
|
||||
# the translation of holidays, until it can be based
|
||||
# on the passed-in locale, but since that would probably
|
||||
# also mean checking every use of holidays I don't think
|
||||
# it is advisable to do, with a release so imminent)
|
||||
# it is also debatable whether it is worth bothering at
|
||||
# all, since it is hard for me to imagine why a user would
|
||||
# be wanting to generate a translated report with holidays
|
||||
# since I believe its main use will be for dates of people
|
||||
|
||||
def write_report(self):
|
||||
""" The short method that runs through each month and creates a page. """
|
||||
"""
|
||||
The short method that runs through each month and creates a page.
|
||||
"""
|
||||
# initialize the dict to fill:
|
||||
self.calendar = {}
|
||||
# get the information, first from holidays:
|
||||
@ -155,17 +180,27 @@ class BirthdayReport(Report):
|
||||
self.collect_data()
|
||||
# generate the report:
|
||||
self.doc.start_paragraph('BIR-Title')
|
||||
title = str(self.titletext) + ": " + str(self.year)
|
||||
if self.titletext == _(_TITLE0):
|
||||
title = self._(_TITLE0) + ": " + str(self.year)
|
||||
else:
|
||||
title = str(self.titletext) + ": " + str(self.year)
|
||||
# FIXME those concatenated strings won't work for RTL languages
|
||||
mark = IndexMark(title, INDEX_TYPE_TOC, 1)
|
||||
self.doc.write_text(title, mark)
|
||||
self.doc.end_paragraph()
|
||||
if self.text1.strip() != "":
|
||||
self.doc.start_paragraph('BIR-Text1style')
|
||||
self.doc.write_text(str(self.text1))
|
||||
text1 = str(self.text1)
|
||||
if text1 == _(_TITLE1):
|
||||
text1 = self._(_TITLE1)
|
||||
self.doc.write_text(text1)
|
||||
self.doc.end_paragraph()
|
||||
if self.text2.strip() != "":
|
||||
self.doc.start_paragraph('BIR-Text2style')
|
||||
self.doc.write_text(str(self.text2))
|
||||
text2 = str(self.text2)
|
||||
if text2 == _(_TITLE2):
|
||||
text2 = self._(_TITLE2)
|
||||
self.doc.write_text(text2)
|
||||
self.doc.end_paragraph()
|
||||
if self.text3.strip() != "":
|
||||
self.doc.start_paragraph('BIR-Text3style')
|
||||
@ -177,7 +212,7 @@ class BirthdayReport(Report):
|
||||
mark = ReportUtils.get_person_mark(self.database,
|
||||
self.center_person)
|
||||
# feature request 2356: avoid genitive form
|
||||
self.doc.write_text(_("Relationships shown are to %s") %
|
||||
self.doc.write_text(self._("Relationships shown are to %s") %
|
||||
self._name_display.display_name(name), mark)
|
||||
self.doc.end_paragraph()
|
||||
self._user.begin_progress(_('Birthday and Anniversary Report'),
|
||||
@ -190,8 +225,9 @@ class BirthdayReport(Report):
|
||||
def print_page(self, month):
|
||||
""" Prints a month as a page """
|
||||
year = self.year
|
||||
dd = self._locale.date_displayer
|
||||
self.doc.start_paragraph('BIR-Monthstyle')
|
||||
self.doc.write_text(_dd.long_months[month].capitalize())
|
||||
self.doc.write_text(dd.long_months[month].capitalize())
|
||||
self.doc.end_paragraph()
|
||||
current_date = datetime.date(year, month, 1)
|
||||
current_ord = current_date.toordinal()
|
||||
@ -226,7 +262,9 @@ class BirthdayReport(Report):
|
||||
self._user.step_progress)
|
||||
self._user.end_progress()
|
||||
|
||||
rel_calc = get_relationship_calculator()
|
||||
rel_calc = get_relationship_calculator(reinit=True,
|
||||
clocale=self._locale)
|
||||
ngettext = self._locale.translation.ngettext
|
||||
|
||||
self._user.begin_progress(_('Birthday and Anniversary Report'),
|
||||
_('Reading database...'), len(people))
|
||||
@ -278,11 +316,13 @@ class BirthdayReport(Report):
|
||||
relation = rel_calc.get_one_relationship(
|
||||
self.database,
|
||||
self.center_person,
|
||||
person)
|
||||
person,
|
||||
olocale=self._locale)
|
||||
if relation:
|
||||
# FIXME this won't work for RTL languages
|
||||
comment = " --- %s" % relation
|
||||
if nyears == 0:
|
||||
text = _('%(person)s, birth%(relation)s') % {
|
||||
text = self._('%(person)s, birth%(relation)s') % {
|
||||
'person' : short_name,
|
||||
'relation' : comment}
|
||||
else:
|
||||
@ -315,11 +355,11 @@ class BirthdayReport(Report):
|
||||
for event_ref in fam.get_event_ref_list():
|
||||
event = self.database.get_event_from_handle(event_ref.ref)
|
||||
if event.type in [EventType.MARRIAGE,
|
||||
EventType.MARR_ALT]:
|
||||
EventType.MARR_ALT]:
|
||||
are_married = event
|
||||
elif event.type in [EventType.DIVORCE,
|
||||
EventType.ANNULMENT,
|
||||
EventType.DIV_FILING]:
|
||||
EventType.ANNULMENT,
|
||||
EventType.DIV_FILING]:
|
||||
are_married = None
|
||||
if are_married is not None:
|
||||
for event_ref in fam.get_event_ref_list():
|
||||
@ -332,7 +372,7 @@ class BirthdayReport(Report):
|
||||
|
||||
if event_obj.is_valid():
|
||||
if nyears == 0:
|
||||
text = _("%(spouse)s and\n %(person)s, wedding") % {
|
||||
text = self._("%(spouse)s and\n %(person)s, wedding") % {
|
||||
'spouse' : spouse_name,
|
||||
'person' : short_name}
|
||||
else:
|
||||
@ -432,22 +472,23 @@ class BirthdayOptions(MenuReportOptions):
|
||||
option.set_help(_("Include relationships to center person (slower)"))
|
||||
menu.add_option(category_name, "relationships", option)
|
||||
|
||||
stdoptions.add_localization_option(menu, category_name)
|
||||
|
||||
category_name = _("Text Options")
|
||||
|
||||
titletext = StringOption(_("Title text"),
|
||||
_("Birthday and Anniversary Report"))
|
||||
titletext = StringOption(_("Title text"), _(_TITLE0))
|
||||
titletext.set_help(_("Title of report"))
|
||||
menu.add_option(category_name, "titletext", titletext)
|
||||
|
||||
text1 = StringOption(_("Text Area 1"), _("My Birthday Report"))
|
||||
text1 = StringOption(_("Text Area 1"), _(_TITLE1))
|
||||
text1.set_help(_("First line of text at bottom of report"))
|
||||
menu.add_option(category_name, "text1", text1)
|
||||
|
||||
text2 = StringOption(_("Text Area 2"), _("Produced with Gramps"))
|
||||
text2 = StringOption(_("Text Area 2"), _(_TITLE2))
|
||||
text2.set_help(_("Second line of text at bottom of report"))
|
||||
menu.add_option(category_name, "text2", text2)
|
||||
|
||||
text3 = StringOption(_("Text Area 3"), "http://gramps-project.org/",)
|
||||
text3 = StringOption(_("Text Area 3"), URL_HOMEPAGE,)
|
||||
text3.set_help(_("Third line of text at bottom of report"))
|
||||
menu.add_option(category_name, "text3", text3)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user