enable translated output for this report
svn: r22207
This commit is contained in:
parent
0fb88fb531
commit
086732a6b4
@ -3,7 +3,8 @@
|
|||||||
# Gramps - a GTK+/GNOME based genealogy program - Records plugin
|
# Gramps - a GTK+/GNOME based genealogy program - Records plugin
|
||||||
#
|
#
|
||||||
# Copyright (C) 2008-2011 Reinhard Müller
|
# Copyright (C) 2008-2011 Reinhard Müller
|
||||||
# Copyright (C) 2010 Jakim Friant
|
# Copyright (C) 2010 Jakim Friant
|
||||||
|
# Copyright (C) 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
|
||||||
@ -28,19 +29,47 @@
|
|||||||
#
|
#
|
||||||
#------------------------------------------------------------------------
|
#------------------------------------------------------------------------
|
||||||
import datetime
|
import datetime
|
||||||
from gramps.gen.const import GRAMPS_LOCALE as glocale
|
|
||||||
_ = glocale.translation.sgettext
|
|
||||||
|
|
||||||
#------------------------------------------------------------------------
|
#------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
# GRAMPS modules
|
# GRAMPS modules
|
||||||
#
|
#
|
||||||
#------------------------------------------------------------------------
|
#------------------------------------------------------------------------
|
||||||
|
from gramps.gen.const import GRAMPS_LOCALE as glocale
|
||||||
|
_ = glocale.translation.sgettext
|
||||||
from gramps.gen.lib import (ChildRefType, Date, Span, Name, StyledText,
|
from gramps.gen.lib import (ChildRefType, Date, Span, Name, StyledText,
|
||||||
StyledTextTag, StyledTextTagType)
|
StyledTextTag, StyledTextTagType)
|
||||||
from gramps.gen.display.name import displayer as name_displayer
|
from gramps.gen.display.name import displayer as name_displayer
|
||||||
from gramps.gen.utils.alive import probably_alive
|
from gramps.gen.utils.alive import probably_alive
|
||||||
|
|
||||||
|
#------------------------------------------------------------------------
|
||||||
|
#
|
||||||
|
# List of records
|
||||||
|
#
|
||||||
|
#------------------------------------------------------------------------
|
||||||
|
|
||||||
|
def _T_(value): # enable deferred translations (see Python docs 22.1.3.4)
|
||||||
|
return value
|
||||||
|
|
||||||
|
RECORDS = [
|
||||||
|
(_T_("Youngest living person"), 'person_youngestliving', True),
|
||||||
|
(_T_("Oldest living person"), 'person_oldestliving', True),
|
||||||
|
(_T_("Person died at youngest age"), 'person_youngestdied', False),
|
||||||
|
(_T_("Person died at oldest age"), 'person_oldestdied', True),
|
||||||
|
(_T_("Person married at youngest age"), 'person_youngestmarried', True),
|
||||||
|
(_T_("Person married at oldest age"), 'person_oldestmarried', True),
|
||||||
|
(_T_("Person divorced at youngest age"), 'person_youngestdivorced', False),
|
||||||
|
(_T_("Person divorced at oldest age"), 'person_oldestdivorced', False),
|
||||||
|
(_T_("Youngest father"), 'person_youngestfather', True),
|
||||||
|
(_T_("Youngest mother"), 'person_youngestmother', True),
|
||||||
|
(_T_("Oldest father"), 'person_oldestfather', True),
|
||||||
|
(_T_("Oldest mother"), 'person_oldestmother', True),
|
||||||
|
(_T_("Couple with most children"), 'family_mostchildren', True),
|
||||||
|
(_T_("Living couple married most recently"), 'family_youngestmarried',True),
|
||||||
|
(_T_("Living couple married most long ago"), 'family_oldestmarried', True),
|
||||||
|
(_T_("Shortest past marriage"), 'family_shortest', False),
|
||||||
|
(_T_("Longest past marriage"), 'family_longest', True)]
|
||||||
|
|
||||||
#------------------------------------------------------------------------
|
#------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
# Global functions
|
# Global functions
|
||||||
@ -62,7 +91,12 @@ def _find_death_date(db, person):
|
|||||||
return event.get_date_object()
|
return event.get_date_object()
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def find_records(db, filter, top_size, callname):
|
def find_records(db, filter, top_size, callname,
|
||||||
|
trans_text=glocale.translation.sgettext):
|
||||||
|
"""
|
||||||
|
@param trans_text: allow deferred translation of strings
|
||||||
|
@type trans_text: a GrampsLocale sgettext instance
|
||||||
|
"""
|
||||||
|
|
||||||
today = datetime.date.today()
|
today = datetime.date.today()
|
||||||
today_date = Date(today.year, today.month, today.day)
|
today_date = Date(today.year, today.month, today.day)
|
||||||
@ -89,6 +123,7 @@ def find_records(db, filter, top_size, callname):
|
|||||||
for person_handle in person_handle_list:
|
for person_handle in person_handle_list:
|
||||||
person = db.get_person_from_handle(person_handle)
|
person = db.get_person_from_handle(person_handle)
|
||||||
|
|
||||||
|
# FIXME this should check for a "fallback" birth also/instead
|
||||||
birth_ref = person.get_birth_ref()
|
birth_ref = person.get_birth_ref()
|
||||||
|
|
||||||
if not birth_ref:
|
if not birth_ref:
|
||||||
@ -156,6 +191,7 @@ def find_records(db, filter, top_size, callname):
|
|||||||
|
|
||||||
child = db.get_person_from_handle(child_ref.ref)
|
child = db.get_person_from_handle(child_ref.ref)
|
||||||
|
|
||||||
|
# FIXME this should check for a "fallback" birth also/instead
|
||||||
child_birth_ref = child.get_birth_ref()
|
child_birth_ref = child.get_birth_ref()
|
||||||
if not child_birth_ref:
|
if not child_birth_ref:
|
||||||
continue
|
continue
|
||||||
@ -201,7 +237,7 @@ def find_records(db, filter, top_size, callname):
|
|||||||
father = db.get_person_from_handle(father_handle)
|
father = db.get_person_from_handle(father_handle)
|
||||||
mother = db.get_person_from_handle(mother_handle)
|
mother = db.get_person_from_handle(mother_handle)
|
||||||
|
|
||||||
name = StyledText(_("%(father)s and %(mother)s")) % {
|
name = StyledText(trans_text("%(father)s and %(mother)s")) % {
|
||||||
'father': _get_styled_primary_name(father, callname),
|
'father': _get_styled_primary_name(father, callname),
|
||||||
'mother': _get_styled_primary_name(mother, callname)}
|
'mother': _get_styled_primary_name(mother, callname)}
|
||||||
|
|
||||||
@ -272,7 +308,7 @@ def find_records(db, filter, top_size, callname):
|
|||||||
duration, name, 'Family', family.handle, top_size)
|
duration, name, 'Family', family.handle, top_size)
|
||||||
#python 3 workaround: assign locals to tmp so we work with runtime version
|
#python 3 workaround: assign locals to tmp so we work with runtime version
|
||||||
tmp = locals()
|
tmp = locals()
|
||||||
return [(text, varname, tmp[varname])
|
return [(trans_text(text), varname, tmp[varname])
|
||||||
for (text, varname, default) in RECORDS]
|
for (text, varname, default) in RECORDS]
|
||||||
|
|
||||||
def _record(lowest, highest, value, text, handle_type, handle, top_size):
|
def _record(lowest, highest, value, text, handle_type, handle, top_size):
|
||||||
@ -372,27 +408,3 @@ def _get_styled_primary_name(person, callname, placeholder=False):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
return _get_styled(person.get_primary_name(), callname, placeholder)
|
return _get_styled(person.get_primary_name(), callname, placeholder)
|
||||||
|
|
||||||
#------------------------------------------------------------------------
|
|
||||||
#
|
|
||||||
# List of records
|
|
||||||
#
|
|
||||||
#------------------------------------------------------------------------
|
|
||||||
RECORDS = [
|
|
||||||
(_("Youngest living person"), 'person_youngestliving', True),
|
|
||||||
(_("Oldest living person"), 'person_oldestliving', True),
|
|
||||||
(_("Person died at youngest age"), 'person_youngestdied', False),
|
|
||||||
(_("Person died at oldest age"), 'person_oldestdied', True),
|
|
||||||
(_("Person married at youngest age"), 'person_youngestmarried', True),
|
|
||||||
(_("Person married at oldest age"), 'person_oldestmarried', True),
|
|
||||||
(_("Person divorced at youngest age"), 'person_youngestdivorced', False),
|
|
||||||
(_("Person divorced at oldest age"), 'person_oldestdivorced', False),
|
|
||||||
(_("Youngest father"), 'person_youngestfather', True),
|
|
||||||
(_("Youngest mother"), 'person_youngestmother', True),
|
|
||||||
(_("Oldest father"), 'person_oldestfather', True),
|
|
||||||
(_("Oldest mother"), 'person_oldestmother', True),
|
|
||||||
(_("Couple with most children"), 'family_mostchildren', True),
|
|
||||||
(_("Living couple married most recently"), 'family_youngestmarried', True),
|
|
||||||
(_("Living couple married most long ago"), 'family_oldestmarried', True),
|
|
||||||
(_("Shortest past marriage"), 'family_shortest', False),
|
|
||||||
(_("Longest past marriage"), 'family_longest', True)]
|
|
||||||
|
@ -3,7 +3,8 @@
|
|||||||
# Gramps - a GTK+/GNOME based genealogy program - Records plugin
|
# Gramps - a GTK+/GNOME based genealogy program - Records plugin
|
||||||
#
|
#
|
||||||
# Copyright (C) 2008-2011 Reinhard Müller
|
# Copyright (C) 2008-2011 Reinhard Müller
|
||||||
# Copyright (C) 2010 Jakim Friant
|
# Copyright (C) 2010 Jakim Friant
|
||||||
|
# Copyright (C) 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
|
||||||
@ -27,23 +28,28 @@
|
|||||||
# Standard Python modules
|
# Standard Python modules
|
||||||
#
|
#
|
||||||
#------------------------------------------------------------------------
|
#------------------------------------------------------------------------
|
||||||
from gramps.gen.const import GRAMPS_LOCALE as glocale
|
|
||||||
_ = glocale.translation.sgettext
|
|
||||||
|
|
||||||
#------------------------------------------------------------------------
|
#------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
# GRAMPS modules
|
# GRAMPS modules
|
||||||
#
|
#
|
||||||
#------------------------------------------------------------------------
|
#------------------------------------------------------------------------
|
||||||
|
from gramps.gen.const import GRAMPS_LOCALE as glocale
|
||||||
|
_ = glocale.translation.sgettext
|
||||||
from gramps.plugins.lib.librecords import (RECORDS, find_records,
|
from gramps.plugins.lib.librecords import (RECORDS, find_records,
|
||||||
CALLNAME_DONTUSE, CALLNAME_REPLACE, CALLNAME_UNDERLINE_ADD)
|
CALLNAME_DONTUSE, CALLNAME_REPLACE,
|
||||||
from gramps.gen.plug.docgen import (FontStyle, ParagraphStyle, FONT_SANS_SERIF,
|
CALLNAME_UNDERLINE_ADD)
|
||||||
PARA_ALIGN_CENTER, IndexMark, INDEX_TYPE_TOC)
|
from gramps.gen.plug.docgen import (FontStyle, ParagraphStyle,
|
||||||
|
FONT_SANS_SERIF, PARA_ALIGN_CENTER,
|
||||||
|
IndexMark, INDEX_TYPE_TOC)
|
||||||
from gramps.gen.plug.menu import (BooleanOption, EnumeratedListOption,
|
from gramps.gen.plug.menu import (BooleanOption, EnumeratedListOption,
|
||||||
FilterOption, NumberOption, PersonOption, StringOption)
|
FilterOption, NumberOption,
|
||||||
|
PersonOption, StringOption)
|
||||||
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.lib import Span
|
||||||
from gramps.gen.constfunc import cuni
|
from gramps.gen.constfunc import cuni
|
||||||
|
|
||||||
#------------------------------------------------------------------------
|
#------------------------------------------------------------------------
|
||||||
@ -70,44 +76,70 @@ class RecordsReport(Report):
|
|||||||
for (text, varname, default) in RECORDS:
|
for (text, varname, default) in RECORDS:
|
||||||
self.include[varname] = menu.get_option_by_name(varname).get_value()
|
self.include[varname] = menu.get_option_by_name(varname).get_value()
|
||||||
|
|
||||||
|
self._lang = options.menu.get_option_by_name('trans').get_value()
|
||||||
|
self._locale = self.set_locale(self._lang)
|
||||||
|
|
||||||
def write_report(self):
|
def write_report(self):
|
||||||
"""
|
"""
|
||||||
Build the actual report.
|
Build the actual report.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
records = find_records(self.database, self.filter, self.top_size, self.callname)
|
records = find_records(self.database, self.filter, self.top_size,
|
||||||
|
self.callname, trans_text=self._)
|
||||||
|
|
||||||
self.doc.start_paragraph('REC-Title')
|
self.doc.start_paragraph('REC-Title')
|
||||||
title = _("Records")
|
title = self._("Records")
|
||||||
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()
|
||||||
|
|
||||||
self.doc.start_paragraph('REC-Subtitle')
|
if self._lang == 'default':
|
||||||
self.doc.write_text(self.filter.get_name())
|
self.doc.start_paragraph('REC-Subtitle')
|
||||||
self.doc.end_paragraph()
|
self.doc.write_text(self.filter.get_name())
|
||||||
|
self.doc.end_paragraph()
|
||||||
|
else:
|
||||||
|
# The only way which I thought of to get a desired non-English
|
||||||
|
# filter name if the starting UI is a non-English one, was to
|
||||||
|
# change ReportUtils.get_person_filters so that it creates the
|
||||||
|
# filters with English (untranslated) names, but that would mean
|
||||||
|
# changing every filter.get_name() in every place that the
|
||||||
|
# get_person_filters filters are used, to always translate the
|
||||||
|
# get_name, and I wasn't in the mood to do that to all of them,
|
||||||
|
# so until that happen -- assuming it works, since I didn't try
|
||||||
|
# it to see, since the person's name will be in get_person_filters
|
||||||
|
# but the deferred translation will be where the filter.get_name()
|
||||||
|
# is, so it might not work at all -- but until it does, or another
|
||||||
|
# way is found, there will be no translated subtitle, only a
|
||||||
|
# subtitle if the report's output is in the main/UI language
|
||||||
|
pass # FIXME
|
||||||
|
|
||||||
for (text, varname, top) in records:
|
for (text, varname, top) in records:
|
||||||
if not self.include[varname]:
|
if not self.include[varname]:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
self.doc.start_paragraph('REC-Heading')
|
self.doc.start_paragraph('REC-Heading')
|
||||||
self.doc.write_text(text)
|
self.doc.write_text(self._(text))
|
||||||
self.doc.end_paragraph()
|
self.doc.end_paragraph()
|
||||||
|
|
||||||
last_value = None
|
last_value = None
|
||||||
rank = 0
|
rank = 0
|
||||||
for (number, (sort, value, name, handletype, handle)) in enumerate(top):
|
for (number,
|
||||||
|
(sort, value, name, handletype, handle)) in enumerate(top):
|
||||||
|
# FIXME check whether person or family, if a family mark BOTH
|
||||||
person = self.database.get_person_from_handle(handle)
|
person = self.database.get_person_from_handle(handle)
|
||||||
mark = ReportUtils.get_person_mark(self.database, person)
|
mark = ReportUtils.get_person_mark(self.database, person)
|
||||||
if value != last_value:
|
if value != last_value:
|
||||||
last_value = value
|
last_value = value
|
||||||
rank = number
|
rank = number
|
||||||
self.doc.start_paragraph('REC-Normal')
|
self.doc.start_paragraph('REC-Normal')
|
||||||
self.doc.write_text(_("%(number)s. ") % {'number': rank+1})
|
# FIXME this won't work for RTL languages:
|
||||||
|
self.doc.write_text(self._("%(number)s. ") % {'number': rank+1})
|
||||||
self.doc.write_markup(cuni(name), name.get_tags(), mark)
|
self.doc.write_markup(cuni(name), name.get_tags(), mark)
|
||||||
self.doc.write_text(_(" (%(value)s)") % {'value': str(value)})
|
if isinstance(value, Span):
|
||||||
|
tvalue = value.get_repr(dlocale=self._locale)
|
||||||
|
else:
|
||||||
|
tvalue = value
|
||||||
|
self.doc.write_text(" (%s)" % tvalue)
|
||||||
self.doc.end_paragraph()
|
self.doc.end_paragraph()
|
||||||
|
|
||||||
self.doc.start_paragraph('REC-Footer')
|
self.doc.start_paragraph('REC-Footer')
|
||||||
@ -139,7 +171,7 @@ class RecordsReportOptions(MenuReportOptions):
|
|||||||
|
|
||||||
self.__filter = FilterOption(_("Filter"), 0)
|
self.__filter = FilterOption(_("Filter"), 0)
|
||||||
self.__filter.set_help(
|
self.__filter.set_help(
|
||||||
_("Determines what people are included in the report."))
|
_("Determines what people are included in the report."))
|
||||||
menu.add_option(category_name, "filter", self.__filter)
|
menu.add_option(category_name, "filter", self.__filter)
|
||||||
self.__filter.connect('value-changed', self.__filter_changed)
|
self.__filter.connect('value-changed', self.__filter_changed)
|
||||||
|
|
||||||
@ -163,15 +195,16 @@ class RecordsReportOptions(MenuReportOptions):
|
|||||||
footer = StringOption(_("Footer text"), "")
|
footer = StringOption(_("Footer text"), "")
|
||||||
menu.add_option(category_name, "footer", footer)
|
menu.add_option(category_name, "footer", footer)
|
||||||
|
|
||||||
|
stdoptions.add_localization_option(menu, category_name)
|
||||||
|
|
||||||
for (text, varname, default) in RECORDS:
|
for (text, varname, default) in RECORDS:
|
||||||
option = BooleanOption(text, default)
|
option = BooleanOption(_(text), default)
|
||||||
if varname.startswith('person'):
|
if varname.startswith('person'):
|
||||||
category_name = _("Person Records")
|
category_name = _("Person Records")
|
||||||
elif varname.startswith('family'):
|
elif varname.startswith('family'):
|
||||||
category_name = _("Family Records")
|
category_name = _("Family Records")
|
||||||
menu.add_option(category_name, varname, option)
|
menu.add_option(category_name, varname, option)
|
||||||
|
|
||||||
|
|
||||||
def __update_filters(self):
|
def __update_filters(self):
|
||||||
"""
|
"""
|
||||||
Update the filter list based on the selected person
|
Update the filter list based on the selected person
|
||||||
@ -181,7 +214,6 @@ class RecordsReportOptions(MenuReportOptions):
|
|||||||
filter_list = ReportUtils.get_person_filters(person, False)
|
filter_list = ReportUtils.get_person_filters(person, False)
|
||||||
self.__filter.set_filters(filter_list)
|
self.__filter.set_filters(filter_list)
|
||||||
|
|
||||||
|
|
||||||
def __filter_changed(self):
|
def __filter_changed(self):
|
||||||
"""
|
"""
|
||||||
Handle filter change. If the filter is not specific to a person,
|
Handle filter change. If the filter is not specific to a person,
|
||||||
@ -195,7 +227,6 @@ class RecordsReportOptions(MenuReportOptions):
|
|||||||
# The rest don't
|
# The rest don't
|
||||||
self.__pid.set_available(False)
|
self.__pid.set_available(False)
|
||||||
|
|
||||||
|
|
||||||
def make_default_style(self, default_style):
|
def make_default_style(self, default_style):
|
||||||
|
|
||||||
#Paragraph Styles
|
#Paragraph Styles
|
||||||
|
Loading…
Reference in New Issue
Block a user