enable translated output for this report

svn: r22262
This commit is contained in:
Paul Franklin 2013-05-11 19:21:55 +00:00
parent 25047a6918
commit 5bf3a88dd6

View File

@ -4,7 +4,7 @@
# Copyright (C) 2008-2009 Brian G. Matherly # Copyright (C) 2008-2009 Brian G. Matherly
# Copyright (C) 2009 Rob G. Healey <robhealey1@gmail.com> # Copyright (C) 2009 Rob G. Healey <robhealey1@gmail.com>
# Copyright (C) 2010 Jakim Friant # 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 # 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
@ -29,9 +29,6 @@
# #
#------------------------------------------------------------------------ #------------------------------------------------------------------------
import copy import copy
from gramps.gen.const import GRAMPS_LOCALE as glocale
_ = glocale.translation.gettext
ngettext = glocale.translation.ngettext
import datetime, time import datetime, time
#------------------------------------------------------------------------ #------------------------------------------------------------------------
@ -39,25 +36,36 @@ import datetime, time
# GRAMPS modules # 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.display.name import displayer as global_name_display
from gramps.gen.errors import ReportError from gramps.gen.errors import ReportError
from gramps.gen.lib import NameType, EventType, Name, Date, Person, Surname from gramps.gen.lib import NameType, EventType, Name, Date, Person, Surname
from gramps.gen.relationship import get_relationship_calculator from gramps.gen.relationship import get_relationship_calculator
from gramps.gen.plug.docgen import (FontStyle, ParagraphStyle, GraphicsStyle, from gramps.gen.plug.docgen import (FontStyle, ParagraphStyle, GraphicsStyle,
FONT_SERIF, PARA_ALIGN_RIGHT, FONT_SERIF, PARA_ALIGN_RIGHT,
PARA_ALIGN_LEFT, PARA_ALIGN_CENTER, PARA_ALIGN_LEFT, PARA_ALIGN_CENTER,
IndexMark, INDEX_TYPE_TOC) IndexMark, INDEX_TYPE_TOC)
from gramps.gen.plug.menu import (BooleanOption, StringOption, NumberOption, 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 Report
from gramps.gen.plug.report import utils as ReportUtils from gramps.gen.plug.report import utils as ReportUtils
from gramps.gen.plug.report import MenuReportOptions from gramps.gen.plug.report import MenuReportOptions
from gramps.gen.plug.report import stdoptions from gramps.gen.plug.report import stdoptions
from gramps.gen.utils.alive import probably_alive 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 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 # BirthdayReport
@ -98,7 +106,10 @@ class BirthdayReport(Report):
self.center_person = database.get_person_from_gramps_id(pid) self.center_person = database.get_person_from_gramps_id(pid)
if (self.center_person == None) : if (self.center_person == None) :
raise ReportError(_("Person %s is not in the Database") % pid ) 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): def get_name(self, person, maiden_name = None):
""" """
@ -142,10 +153,24 @@ class BirthdayReport(Report):
for day in range(1, 32): for day in range(1, 32):
holiday_names = holiday_table.get_holidays(month, day) holiday_names = holiday_table.get_holidays(month, day)
for holiday_name in holiday_names: 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): 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: # initialize the dict to fill:
self.calendar = {} self.calendar = {}
# get the information, first from holidays: # get the information, first from holidays:
@ -155,17 +180,27 @@ class BirthdayReport(Report):
self.collect_data() self.collect_data()
# generate the report: # generate the report:
self.doc.start_paragraph('BIR-Title') 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) mark = IndexMark(title, INDEX_TYPE_TOC, 1)
self.doc.write_text(title, mark) self.doc.write_text(title, mark)
self.doc.end_paragraph() self.doc.end_paragraph()
if self.text1.strip() != "": if self.text1.strip() != "":
self.doc.start_paragraph('BIR-Text1style') 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() self.doc.end_paragraph()
if self.text2.strip() != "": if self.text2.strip() != "":
self.doc.start_paragraph('BIR-Text2style') 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() self.doc.end_paragraph()
if self.text3.strip() != "": if self.text3.strip() != "":
self.doc.start_paragraph('BIR-Text3style') self.doc.start_paragraph('BIR-Text3style')
@ -177,7 +212,7 @@ class BirthdayReport(Report):
mark = ReportUtils.get_person_mark(self.database, mark = ReportUtils.get_person_mark(self.database,
self.center_person) self.center_person)
# feature request 2356: avoid genitive form # 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._name_display.display_name(name), mark)
self.doc.end_paragraph() self.doc.end_paragraph()
self._user.begin_progress(_('Birthday and Anniversary Report'), self._user.begin_progress(_('Birthday and Anniversary Report'),
@ -190,8 +225,9 @@ class BirthdayReport(Report):
def print_page(self, month): def print_page(self, month):
""" Prints a month as a page """ """ Prints a month as a page """
year = self.year year = self.year
dd = self._locale.date_displayer
self.doc.start_paragraph('BIR-Monthstyle') 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() self.doc.end_paragraph()
current_date = datetime.date(year, month, 1) current_date = datetime.date(year, month, 1)
current_ord = current_date.toordinal() current_ord = current_date.toordinal()
@ -226,7 +262,9 @@ class BirthdayReport(Report):
self._user.step_progress) self._user.step_progress)
self._user.end_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'), self._user.begin_progress(_('Birthday and Anniversary Report'),
_('Reading database...'), len(people)) _('Reading database...'), len(people))
@ -278,11 +316,13 @@ class BirthdayReport(Report):
relation = rel_calc.get_one_relationship( relation = rel_calc.get_one_relationship(
self.database, self.database,
self.center_person, self.center_person,
person) person,
olocale=self._locale)
if relation: if relation:
# FIXME this won't work for RTL languages
comment = " --- %s" % relation comment = " --- %s" % relation
if nyears == 0: if nyears == 0:
text = _('%(person)s, birth%(relation)s') % { text = self._('%(person)s, birth%(relation)s') % {
'person' : short_name, 'person' : short_name,
'relation' : comment} 'relation' : comment}
else: else:
@ -315,11 +355,11 @@ class BirthdayReport(Report):
for event_ref in fam.get_event_ref_list(): for event_ref in fam.get_event_ref_list():
event = self.database.get_event_from_handle(event_ref.ref) event = self.database.get_event_from_handle(event_ref.ref)
if event.type in [EventType.MARRIAGE, if event.type in [EventType.MARRIAGE,
EventType.MARR_ALT]: EventType.MARR_ALT]:
are_married = event are_married = event
elif event.type in [EventType.DIVORCE, elif event.type in [EventType.DIVORCE,
EventType.ANNULMENT, EventType.ANNULMENT,
EventType.DIV_FILING]: EventType.DIV_FILING]:
are_married = None are_married = None
if are_married is not None: if are_married is not None:
for event_ref in fam.get_event_ref_list(): for event_ref in fam.get_event_ref_list():
@ -332,7 +372,7 @@ class BirthdayReport(Report):
if event_obj.is_valid(): if event_obj.is_valid():
if nyears == 0: if nyears == 0:
text = _("%(spouse)s and\n %(person)s, wedding") % { text = self._("%(spouse)s and\n %(person)s, wedding") % {
'spouse' : spouse_name, 'spouse' : spouse_name,
'person' : short_name} 'person' : short_name}
else: else:
@ -432,22 +472,23 @@ class BirthdayOptions(MenuReportOptions):
option.set_help(_("Include relationships to center person (slower)")) option.set_help(_("Include relationships to center person (slower)"))
menu.add_option(category_name, "relationships", option) menu.add_option(category_name, "relationships", option)
stdoptions.add_localization_option(menu, category_name)
category_name = _("Text Options") category_name = _("Text Options")
titletext = StringOption(_("Title text"), titletext = StringOption(_("Title text"), _(_TITLE0))
_("Birthday and Anniversary Report"))
titletext.set_help(_("Title of report")) titletext.set_help(_("Title of report"))
menu.add_option(category_name, "titletext", titletext) 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")) text1.set_help(_("First line of text at bottom of report"))
menu.add_option(category_name, "text1", text1) 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")) text2.set_help(_("Second line of text at bottom of report"))
menu.add_option(category_name, "text2", text2) 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")) text3.set_help(_("Third line of text at bottom of report"))
menu.add_option(category_name, "text3", text3) menu.add_option(category_name, "text3", text3)