defer translation for one more date, and cleanup translation

svn: r22231
This commit is contained in:
Paul Franklin 2013-05-09 22:25:55 +00:00
parent fca6091ebd
commit 26b785b3e8
6 changed files with 67 additions and 51 deletions

View File

@ -6,6 +6,7 @@
# Copyright (C) 2010 Jakim Friant
# Copyright (C) 2011 Adam Stein <adam@csh.rit.edu>
# Copyright (C) 2011 Tim G L Lyons
# Copyright (C) 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
@ -31,7 +32,6 @@ from ...lib import NoteType, Citation
from ...const import GRAMPS_LOCALE as glocale
_ = glocale.translation.gettext
from ...utils.string import confidence
from ...datehandler import displayer
def add_endnote_styles(style_sheet):
"""
@ -103,10 +103,13 @@ def cite_source(bibliography, database, obj):
return txt
def write_endnotes(bibliography, database, doc, printnotes=False, links=False,
trans_text=glocale.translation.gettext):
elocale=glocale):
"""
Write all the entries in the bibliography as endnotes.
If elocale is passed in (a GrampsLocale), then (insofar as possible)
the translated values will be returned instead.
@param bibliography: The bibliography that contains the citations.
@type bibliography: L{Bibliography}
@param database: The database that the sources come from.
@ -118,12 +121,14 @@ def write_endnotes(bibliography, database, doc, printnotes=False, links=False,
@type printnotes: bool
@param links: Indicate if URL links should be makde 'clickable'.
@type links: bool
@param trans_text: allow deferred translation of "Endnotes" Endnotes-Header
@type trans_text: a GrampsLocale gettext instance
@param elocale: allow deferred translation of dates and strings
@type elocale: a GrampsLocale instance
"""
if bibliography.get_citation_count() == 0:
return
trans_text = elocale.translation.gettext
doc.start_paragraph('Endnotes-Header')
doc.write_text(trans_text('Endnotes'))
doc.end_paragraph()
@ -143,7 +148,7 @@ def write_endnotes(bibliography, database, doc, printnotes=False, links=False,
for key, ref in citation.get_ref_list():
doc.start_paragraph('Endnotes-Ref', "%s:" % key)
doc.write_text(_format_ref_text(ref, key), links=links)
doc.write_text(_format_ref_text(ref, key, elocale), links=links)
doc.end_paragraph()
if printnotes:
@ -174,7 +179,7 @@ def _format_source_text(source):
return src_txt
def _format_ref_text(ref, key):
def _format_ref_text(ref, key, elocale):
if not ref: return ""
ref_txt = ""
@ -185,14 +190,27 @@ def _format_ref_text(ref, key):
datepresent = True
if datepresent:
if ref.get_page():
ref_txt = "%s - %s" % (ref.get_page(), displayer.display(date))
ref_txt = "%s - %s" % (ref.get_page(), elocale.get_date(date))
else:
ref_txt = displayer.display(date)
ref_txt = elocale.get_date(date)
else:
ref_txt = ref.get_page()
# Print only confidence level if it is not Normal
if ref.get_confidence_level() != Citation.CONF_NORMAL:
if (ref.get_confidence_level() != Citation.CONF_NORMAL
and elocale == glocale): # FIXME
# the correct fix would be to enable deferred translation for at
# least the "confidence" list of strings (in gen/utils/string.py),
# and possibly others too if they need deferred translation, but that
# would require searching out every use of a "confidence" string and
# translating it there, either to the UI language or to a "deferred"
# language (e.g. when used in a report, as here in this module), but
# that would require an immense amount of time and testing and since
# a release is imminent this is not the time to consider that, so I
# have instead added the above line, which will disable the typeout
# of any "confidence" rating /if/ a translated value is needed, while
# continuing to show the "confidence" for the normal case of a user
# running a report in their own language (when elocale==glocale)
ref_txt += " [" + confidence[ref.get_confidence_level()] + "]"
return ref_txt

View File

@ -1350,13 +1350,17 @@ class Narrator(object):
Narrator is a class which provides narration text.
"""
def __init__(self, dbase, verbose=True, use_call_name=False,use_fulldate=False,
def __init__(self, dbase, verbose=True,
use_call_name=False, use_fulldate=False,
empty_date="", empty_place="",
locale=None,
nlocale=glocale,
get_endnote_numbers=_get_empty_endnote_numbers):
"""
Initialize the narrator class.
If nlocale is passed in (a GrampsLocale), then
the translated values will be returned instead.
:param dbase: The database that contains the data to be narrated.
:type dbase: :class:`~gen.db.base,DbBase`
:param verbose: Specifies whether complete sentences should be used.
@ -1368,9 +1372,6 @@ class Narrator(object):
:type empty_date: str
:param empty_place: String to use when a place is not known.
:type empty_place: str
:param translate_text: A function that returns a translated message
string given a message id (similar to gettext).
:type translate_text: callable(str)
:param get_endnote_numbers: A callable to use for getting a string
representing endnote numbers.
The function takes a :class:`~gen.lib.CitationBase` instance.
@ -1378,6 +1379,8 @@ class Narrator(object):
would represent a reference to an endnote in a document.
:type get_endnote_numbers:
callable( :class:`~gen.lib.CitationBase` )
@param nlocale: allow deferred translation of dates and strings
@type nlocale: a GrampsLocale instance
"""
self.__db = dbase
self.__verbose = verbose
@ -1390,11 +1393,9 @@ class Narrator(object):
self.__first_name = ""
self.__first_name_used = False
if locale is None:
locale = glocale
self.__translate_text = locale.translation.gettext
self.__get_date = locale.get_date
self._locale = locale
self.__translate_text = nlocale.translation.gettext
self.__get_date = nlocale.get_date
self._locale = nlocale
def set_subject(self, person):
"""

View File

@ -4,7 +4,7 @@
# Copyright (C) 2000-2007 Donald N. Allingham
# Copyright (C) 2007-2009 Brian G. Matherly
# 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
@ -43,8 +43,7 @@ _ = glocale.translation.gettext
from gramps.gen.display.name import displayer as global_name_display
from gramps.gen.errors import ReportError
from gramps.gen.lib import ChildRefType
from gramps.gen.plug.menu import (BooleanOption, NumberOption, PersonOption,
StringOption)
from gramps.gen.plug.menu import (BooleanOption, NumberOption, PersonOption)
from gramps.gen.plug.docgen import (IndexMark, FontStyle, ParagraphStyle,
FONT_SANS_SERIF, INDEX_TYPE_TOC,
PARA_ALIGN_CENTER)
@ -113,13 +112,10 @@ class AncestorReport(Report):
self._name_display.set_default_format(name_format)
lang = menu.get_option_by_name('trans').get_value()
locale = self.set_locale(lang)
self.__narrator = Narrator(self.database, use_fulldate=True,
locale=locale)
rlocale = self.set_locale(lang)
title_name = self._name_display.display_formal(self.center_person)
title_format = menu.get_option_by_name('title_format').get_value()
self.title = self._(title_format) % title_name
self.__narrator = Narrator(self.database, use_fulldate=True,
nlocale=rlocale)
def apply_filter(self, person_handle, index, generation=1):
"""
@ -190,9 +186,12 @@ class AncestorReport(Report):
# Write the title line. Set in INDEX marker so that this section will be
# identified as a major category if this is included in a Book report.
mark = IndexMark(self.title, INDEX_TYPE_TOC, 1)
name = self._name_display.display_formal(self.center_person)
# feature request 2356: avoid genitive form
title = self._("Ahnentafel Report for %s") % name
mark = IndexMark(title, INDEX_TYPE_TOC, 1)
self.doc.start_paragraph("AHN-Title")
self.doc.write_text(self.title, mark)
self.doc.write_text(title, mark)
self.doc.end_paragraph()
# get the entries out of the map, and sort them.
@ -288,11 +287,6 @@ class AncestorOptions(MenuReportOptions):
namebrk.set_help(_("Indicates if a line break should follow the name."))
menu.add_option(category_name, "namebrk", namebrk)
title_format_string = _("Ahnentafel Report for %s")
title_format = StringOption(_('Title format'), title_format_string)
title_format.set_help(_("How the title will be shown."))
menu.add_option(category_name, "title_format", title_format)
stdoptions.add_localization_option(menu, category_name)
def make_default_style(self, default_style):

View File

@ -9,6 +9,7 @@
# Copyright (C) 2010 Jakim Friant
# Copyright (C) 2010 Vlada Peri\u0107
# Copyright (C) 2011 Tim G L Lyons
# Copyright (C) 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
@ -159,10 +160,11 @@ class DetAncestorReport(Report):
empty_place = ""
lang = menu.get_option_by_name('trans').get_value()
locale = self.set_locale(lang)
self._locale = self.set_locale(lang)
self.__narrator = Narrator(self.database, self.verbose, use_call,
use_fulldate, empty_date, empty_place,
locale=locale,
nlocale=self._locale,
get_endnote_numbers=self.endnotes)
self.bibli = Bibliography(Bibliography.MODE_DATE|Bibliography.MODE_PAGE)
@ -231,7 +233,7 @@ class DetAncestorReport(Report):
# it ignores language set for Note type (use locale)
endnotes.write_endnotes(self.bibli, self.database, self.doc,
printnotes=self.inc_srcnotes,
trans_text=self._)
elocale=self._locale)
def write_person(self, key):
"""Output birth, death, parentage, marriage and notes information """

View File

@ -11,6 +11,7 @@
# Copyright (C) 2010 Vlada Peri\u0107
# Copyright (C) 2011 Matt Keenan <matt.keenan@gmail.com>
# Copyright (C) 2011 Tim G L Lyons
# Copyright (C) 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
@ -171,7 +172,6 @@ class DetDescendantReport(Report):
else:
empty_place = ""
# Copy the global NameDisplay so that we don't change application
# defaults.
self._name_display = copy.deepcopy(global_name_display)
@ -179,14 +179,14 @@ class DetDescendantReport(Report):
if name_format != 0:
self._name_display.set_default_format(name_format)
locale = self.set_locale(get_value('trans'))
self._locale = self.set_locale(get_value('trans'))
self.__narrator = Narrator(self.database, self.verbose,
use_call, use_fulldate,
empty_date, empty_place,
locale=locale,
nlocale=self._locale,
get_endnote_numbers=self.endnotes)
self.bibli = Bibliography(Bibliography.MODE_DATE|Bibliography.MODE_PAGE)
def apply_henry_filter(self,person_handle, index, pid, cur_gen=1):
@ -311,7 +311,7 @@ class DetDescendantReport(Report):
# it ignores language set for Note type (use locale)
endnotes.write_endnotes(self.bibli, self.database, self.doc,
printnotes=self.inc_srcnotes,
trans_text=self._)
elocale=self._locale)
def write_path(self, person):
path = []

View File

@ -199,7 +199,8 @@ class IndivCompleteReport(Report):
if name_format != 0:
self._name_display.set_default_format(name_format)
self.set_locale(menu.get_option_by_name('trans').get_value())
lang = menu.get_option_by_name('trans').get_value()
self._locale = self.set_locale(lang)
def write_fact(self, event_ref, event, event_group):
"""
@ -671,7 +672,7 @@ class IndivCompleteReport(Report):
self.doc.page_break()
Endnotes.write_endnotes(self.bibli, self.database, self.doc,
printnotes=self.use_srcs_notes,
trans_text=self._)
elocale=self._locale)
#------------------------------------------------------------------------
#