add name-format option, and deferred translation to report's second line
This commit is contained in:
parent
0657680432
commit
e25a2d23e2
@ -4,7 +4,7 @@
|
|||||||
#
|
#
|
||||||
# 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
|
# Copyright (C) 2013-2015 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
|
||||||
@ -91,11 +91,13 @@ def _find_death_date(db, person):
|
|||||||
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):
|
trans_text=glocale.translation.sgettext, name_format=None):
|
||||||
"""
|
"""
|
||||||
@param trans_text: allow deferred translation of strings
|
@param trans_text: allow deferred translation of strings
|
||||||
@type trans_text: a GrampsLocale sgettext instance
|
@type trans_text: a GrampsLocale sgettext instance
|
||||||
trans_text is a defined keyword (see po/update_po.py, po/genpot.sh)
|
trans_text is a defined keyword (see po/update_po.py, po/genpot.sh)
|
||||||
|
:param name_format: optional format to control display of person's name
|
||||||
|
:type name_format: None or int
|
||||||
"""
|
"""
|
||||||
|
|
||||||
today = datetime.date.today()
|
today = datetime.date.today()
|
||||||
@ -139,7 +141,8 @@ def find_records(db, filter, top_size, callname,
|
|||||||
# Birth date unknown or incomplete, so we can't calculate any age.
|
# Birth date unknown or incomplete, so we can't calculate any age.
|
||||||
continue
|
continue
|
||||||
|
|
||||||
name = _get_styled_primary_name(person, callname)
|
name = _get_styled_primary_name(person, callname,
|
||||||
|
name_format=name_format)
|
||||||
|
|
||||||
if death_date is None:
|
if death_date is None:
|
||||||
if probably_alive(person, db):
|
if probably_alive(person, db):
|
||||||
@ -238,8 +241,10 @@ def find_records(db, filter, top_size, callname,
|
|||||||
mother = db.get_person_from_handle(mother_handle)
|
mother = db.get_person_from_handle(mother_handle)
|
||||||
|
|
||||||
name = StyledText(trans_text("%(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)}
|
name_format=name_format),
|
||||||
|
'mother': _get_styled_primary_name(mother, callname,
|
||||||
|
name_format=name_format)}
|
||||||
|
|
||||||
_record(None, family_mostchildren,
|
_record(None, family_mostchildren,
|
||||||
len(family.get_child_ref_list()),
|
len(family.get_child_ref_list()),
|
||||||
@ -349,7 +354,7 @@ CALLNAME_DONTUSE = 0
|
|||||||
CALLNAME_REPLACE = 1
|
CALLNAME_REPLACE = 1
|
||||||
CALLNAME_UNDERLINE_ADD = 2
|
CALLNAME_UNDERLINE_ADD = 2
|
||||||
|
|
||||||
def _get_styled(name, callname, placeholder=False):
|
def _get_styled(name, callname, placeholder=False, name_format=None):
|
||||||
"""
|
"""
|
||||||
Return a StyledText object with the name formatted according to the
|
Return a StyledText object with the name formatted according to the
|
||||||
parameters:
|
parameters:
|
||||||
@ -383,7 +388,11 @@ def _get_styled(name, callname, placeholder=False):
|
|||||||
'call': n.call,
|
'call': n.call,
|
||||||
'first': n.first_name}
|
'first': n.first_name}
|
||||||
|
|
||||||
|
real_format = name_displayer.get_default_format()
|
||||||
|
if name_format is not None:
|
||||||
|
name_displayer.set_default_format(name_format)
|
||||||
text = name_displayer.display_name(n)
|
text = name_displayer.display_name(n)
|
||||||
|
name_displayer.set_default_format(real_format)
|
||||||
tags = []
|
tags = []
|
||||||
|
|
||||||
if n.call:
|
if n.call:
|
||||||
@ -398,7 +407,8 @@ def _get_styled(name, callname, placeholder=False):
|
|||||||
|
|
||||||
return StyledText(text, tags)
|
return StyledText(text, tags)
|
||||||
|
|
||||||
def _get_styled_primary_name(person, callname, placeholder=False):
|
def _get_styled_primary_name(person, callname,
|
||||||
|
placeholder=False, name_format=None):
|
||||||
"""
|
"""
|
||||||
Return a StyledText object with the person's name formatted according to
|
Return a StyledText object with the person's name formatted according to
|
||||||
the parameters:
|
the parameters:
|
||||||
@ -410,4 +420,5 @@ def _get_styled_primary_name(person, callname, placeholder=False):
|
|||||||
placeholder if first name or surname are missing.
|
placeholder if first name or surname are missing.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
return _get_styled(person.get_primary_name(), callname, placeholder)
|
return _get_styled(person.get_primary_name(), callname,
|
||||||
|
placeholder, name_format)
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
#
|
#
|
||||||
# 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-2014 Paul Franklin
|
# Copyright (C) 2013-2015 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
|
||||||
@ -84,13 +84,16 @@ class RecordsReport(Report):
|
|||||||
self._lang = options.menu.get_option_by_name('trans').get_value()
|
self._lang = options.menu.get_option_by_name('trans').get_value()
|
||||||
self._locale = self.set_locale(self._lang)
|
self._locale = self.set_locale(self._lang)
|
||||||
|
|
||||||
|
self._nf = stdoptions.run_name_format_option(self, menu)
|
||||||
|
|
||||||
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,
|
records = find_records(self.database, self.filter,
|
||||||
self.callname, trans_text=self._)
|
self.top_size, self.callname,
|
||||||
|
trans_text=self._, name_format=self._nf)
|
||||||
|
|
||||||
self.doc.start_paragraph('REC-Title')
|
self.doc.start_paragraph('REC-Title')
|
||||||
title = self._("Records")
|
title = self._("Records")
|
||||||
@ -98,25 +101,9 @@ class RecordsReport(Report):
|
|||||||
self.doc.write_text(title, mark)
|
self.doc.write_text(title, mark)
|
||||||
self.doc.end_paragraph()
|
self.doc.end_paragraph()
|
||||||
|
|
||||||
if self._lang == 'default':
|
|
||||||
self.doc.start_paragraph('REC-Subtitle')
|
self.doc.start_paragraph('REC-Subtitle')
|
||||||
self.doc.write_text(self.filter.get_name())
|
self.doc.write_text(self.filter.get_name(self._locale))
|
||||||
self.doc.end_paragraph()
|
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]:
|
||||||
@ -185,6 +172,9 @@ class RecordsReportOptions(MenuReportOptions):
|
|||||||
menu.add_option(category_name, "pid", self.__pid)
|
menu.add_option(category_name, "pid", self.__pid)
|
||||||
self.__pid.connect('value-changed', self.__update_filters)
|
self.__pid.connect('value-changed', self.__update_filters)
|
||||||
|
|
||||||
|
self._nf = stdoptions.add_name_format_option(menu, category_name)
|
||||||
|
self._nf.connect('value-changed', self.__update_filters)
|
||||||
|
|
||||||
self.__update_filters()
|
self.__update_filters()
|
||||||
|
|
||||||
top_size = NumberOption(_("Number of ranks to display"), 3, 1, 100)
|
top_size = NumberOption(_("Number of ranks to display"), 3, 1, 100)
|
||||||
@ -218,7 +208,10 @@ class RecordsReportOptions(MenuReportOptions):
|
|||||||
"""
|
"""
|
||||||
gid = self.__pid.get_value()
|
gid = self.__pid.get_value()
|
||||||
person = self.__db.get_person_from_gramps_id(gid)
|
person = self.__db.get_person_from_gramps_id(gid)
|
||||||
filter_list = ReportUtils.get_person_filters(person, False)
|
nfv = self._nf.get_value()
|
||||||
|
filter_list = ReportUtils.get_person_filters(person,
|
||||||
|
include_single=False,
|
||||||
|
name_format=nfv)
|
||||||
self.__filter.set_filters(filter_list)
|
self.__filter.set_filters(filter_list)
|
||||||
|
|
||||||
def __filter_changed(self):
|
def __filter_changed(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user