7585: provide translated output for Ancestor Tree and Descendant Tree reports

This commit is contained in:
Paul Franklin 2014-04-09 10:30:49 -07:00
parent d238ad9044
commit 2c2f1d61c8
4 changed files with 172 additions and 147 deletions

View File

@ -4,6 +4,7 @@
# Copyright (C) 2007-2008 Brian G. Matherly # Copyright (C) 2007-2008 Brian G. Matherly
# Copyright (C) 2010 Jakim Friant # Copyright (C) 2010 Jakim Friant
# Copyright (C) 2010 Craig J. Anderson # Copyright (C) 2010 Craig J. Anderson
# Copyright (C) 2014 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
@ -39,29 +40,23 @@ def log2(val):
X_INDEX = log2 X_INDEX = log2
from gramps.gen.const import GRAMPS_LOCALE as glocale
_ = glocale.translation.sgettext
#------------------------------------------------------------------------ #------------------------------------------------------------------------
# #
# GRAMPS modules # GRAMPS modules
# #
#------------------------------------------------------------------------ #------------------------------------------------------------------------
#from gramps.gen.errors import ReportError from gramps.gen.const import GRAMPS_LOCALE as glocale
_ = glocale.translation.sgettext
from gramps.gen.plug.menu import BooleanOption from gramps.gen.plug.menu import (TextOption, NumberOption, BooleanOption,
from gramps.gen.plug.menu import NumberOption EnumeratedListOption, StringOption,
from gramps.gen.plug.menu import StringOption PersonOption)
from gramps.gen.plug.menu import EnumeratedListOption from gramps.gen.plug.report import Report, MenuReportOptions, stdoptions
from gramps.gen.plug.menu import TextOption
from gramps.gen.plug.menu import PersonOption
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.display.name import displayer as name_displayer from gramps.gen.display.name import displayer as name_displayer
from gramps.gen.plug.docgen import (FontStyle, ParagraphStyle, GraphicsStyle,
FONT_SANS_SERIF, PARA_ALIGN_CENTER)
from gramps.plugins.lib.libtreebase import *
PT2CM = ReportUtils.pt2cm PT2CM = ReportUtils.pt2cm
#cm2pt = ReportUtils.cm2pt #cm2pt = ReportUtils.cm2pt
@ -71,11 +66,9 @@ PT2CM = ReportUtils.pt2cm
# Constants # Constants
# #
#------------------------------------------------------------------------ #------------------------------------------------------------------------
_BORN = _('short for born|b.') _BORN = _("birth abbreviation|b."),
_DIED = _('short for died|d.') _DIED = _("death abbreviation|d."),
_MARR = _('short for married|m.') _MARR = _("marriage abbreviation|m."),
from gramps.plugins.lib.libtreebase import *
#------------------------------------------------------------------------ #------------------------------------------------------------------------
# #
@ -132,19 +125,21 @@ class FamilyBox(AncestorBoxBase):
class TitleN(TitleNoDisplay): class TitleN(TitleNoDisplay):
"""No Title class for the report """ """No Title class for the report """
def __init__(self, doc): def __init__(self, doc, locale):
TitleNoDisplay.__init__(self, doc, "AC2-Title") TitleNoDisplay.__init__(self, doc, "AC2-Title")
self._ = locale.translation.sgettext
def calc_title(self, center): def calc_title(self, center):
"""Calculate the title of the report""" """Calculate the title of the report"""
#we want no text, but need a text for the TOC in a book! #we want no text, but need a text for the TOC in a book!
self.mark_text = _("Ancestor Graph") self.mark_text = self._("Ancestor Graph")
self.text = '' self.text = ''
class TitleA(TitleBox): class TitleA(TitleBox):
"""Title class for the report """ """Title class for the report """
def __init__(self, doc): def __init__(self, doc, locale):
TitleBox.__init__(self, doc, "AC2-Title") TitleBox.__init__(self, doc, "AC2-Title")
self._ = locale.translation.sgettext
def calc_title(self, center): def calc_title(self, center):
"""Calculate the title of the report""" """Calculate the title of the report"""
@ -153,7 +148,7 @@ class TitleA(TitleBox):
name = name_displayer.display(center) name = name_displayer.display(center)
# feature request 2356: avoid genitive form # feature request 2356: avoid genitive form
self.text = _("Ancestor Graph for %s") % name self.text = self._("Ancestor Graph for %s") % name
self.set_box_height_width() self.set_box_height_width()
@ -172,7 +167,7 @@ class CalcItems(object):
#str = "" #str = ""
#if self.get_val('miss_val'): #if self.get_val('miss_val'):
# str = "_____" # str = "_____"
self.__calc_l = CalcLines(dbase, []) self.__calc_l = CalcLines(dbase, [], __gui._locale)
self.__blank_father = None self.__blank_father = None
self.__blank_mother = None self.__blank_mother = None
@ -628,9 +623,10 @@ class GUIConnect():
def __init__(self): #We are BORG! def __init__(self): #We are BORG!
self.__dict__ = self.__shared_state self.__dict__ = self.__shared_state
def set__opts(self, options): def set__opts(self, options, locale):
""" Set only once as we are BORG. """ """ Set only once as we are BORG. """
self.__opts = options self.__opts = options
self._locale = locale
def get_val(self, val): def get_val(self, val):
""" Get a GUI value. """ """ Get a GUI value. """
@ -644,7 +640,10 @@ class GUIConnect():
""" Return a class that holds the proper title based off of the """ Return a class that holds the proper title based off of the
GUI options """ GUI options """
title_type = self.get_val('report_title') title_type = self.get_val('report_title')
return TitleA(doc) if title_type else TitleN(doc) if title_type:
return TitleA(doc, self._locale)
else:
return TitleN(doc, self._locale)
#------------------------------------------------------------------------ #------------------------------------------------------------------------
# #
@ -670,6 +669,9 @@ class AncestorTree(Report):
self.database = database self.database = database
self._user = user self._user = user
lang = options.menu.get_option_by_name('trans').get_value()
self._locale = self.set_locale(lang)
def begin_report(self): def begin_report(self):
""" """
This report needs the following parameters (class variables) This report needs the following parameters (class variables)
@ -692,7 +694,7 @@ class AncestorTree(Report):
database = self.database database = self.database
self.connect = GUIConnect() self.connect = GUIConnect()
self.connect.set__opts(self.options.menu) self.connect.set__opts(self.options.menu, self._locale)
#Set up the canvas that we will print on. #Set up the canvas that we will print on.
style_sheet = self.doc.get_style_sheet() style_sheet = self.doc.get_style_sheet()
@ -743,7 +745,7 @@ class AncestorTree(Report):
if self.connect.get_val("inc_note"): if self.connect.get_val("inc_note"):
note_box = NoteBox(self.doc, "AC2-note-box", note_box = NoteBox(self.doc, "AC2-note-box",
self.connect.get_val("note_place")) self.connect.get_val("note_place"))
subst = SubstKeywords(self.database, None, None) subst = SubstKeywords(self.database, self._locale, None, None)
note_box.text = subst.replace_and_clean( note_box.text = subst.replace_and_clean(
self.connect.get_val('note_disp')) self.connect.get_val('note_disp'))
self.canvas.add_note(note_box) self.canvas.add_note(note_box)
@ -783,7 +785,7 @@ class AncestorTree(Report):
##################### #####################
#Vars #Vars
if prnnum: if prnnum:
page_num_box = PageNumberBox(self.doc, 'AC2-box') page_num_box = PageNumberBox(self.doc, 'AC2-box', self._locale)
##################### #####################
#ok, everyone is now ready to print on the canvas. Paginate? #ok, everyone is now ready to print on the canvas. Paginate?
@ -821,8 +823,6 @@ class AncestorTree(Report):
""" """
style_sheet = self.doc.get_style_sheet() style_sheet = self.doc.get_style_sheet()
from gramps.gen.plug.docgen import GraphicsStyle
graph_style = style_sheet.get_draw_style("AC2-box") graph_style = style_sheet.get_draw_style("AC2-box")
graph_style.set_shadow(graph_style.get_shadow(), graph_style.set_shadow(graph_style.get_shadow(),
self.canvas.report_opts.box_shadow * scale) self.canvas.report_opts.box_shadow * scale)
@ -928,6 +928,8 @@ class AncestorTreeOptions(MenuReportOptions):
centerDisp.set_help(_("Which Display format to use the center person")) centerDisp.set_help(_("Which Display format to use the center person"))
menu.add_option(category_name, "center_uses", centerDisp) menu.add_option(category_name, "center_uses", centerDisp)
stdoptions.add_localization_option(menu, category_name)
################## ##################
category_name = _("Display") category_name = _("Display")
@ -1090,9 +1092,6 @@ class AncestorTreeOptions(MenuReportOptions):
def make_default_style(self, default_style): def make_default_style(self, default_style):
"""Make the default output style for the Ancestor Tree.""" """Make the default output style for the Ancestor Tree."""
from gramps.gen.plug.docgen import (FontStyle, ParagraphStyle, GraphicsStyle,
FONT_SANS_SERIF, PARA_ALIGN_CENTER)
## Paragraph Styles: ## Paragraph Styles:
font = FontStyle() font = FontStyle()
font.set_size(9) font.set_size(9)

View File

@ -5,6 +5,7 @@
# Copyright (C) 2007-2008 Brian G. Matherly # Copyright (C) 2007-2008 Brian G. Matherly
# Copyright (C) 2010 Jakim Friant # Copyright (C) 2010 Jakim Friant
# Copyright (C) 2009-2010 Craig J. Anderson # Copyright (C) 2009-2010 Craig J. Anderson
# Copyright (C) 2014 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
@ -36,20 +37,15 @@ from __future__ import division
#------------------------------------------------------------------------ #------------------------------------------------------------------------
from gramps.gen.const import GRAMPS_LOCALE as glocale from gramps.gen.const import GRAMPS_LOCALE as glocale
_ = glocale.translation.sgettext _ = glocale.translation.sgettext
from gramps.gen.errors import ReportError from gramps.gen.errors import ReportError
from gramps.gen.plug.menu import (TextOption, NumberOption, BooleanOption,
from gramps.gen.plug.menu import TextOption EnumeratedListOption, StringOption,
from gramps.gen.plug.menu import NumberOption PersonOption, FamilyOption)
from gramps.gen.plug.menu import EnumeratedListOption from gramps.gen.plug.report import Report, MenuReportOptions, stdoptions
from gramps.gen.plug.menu import StringOption
from gramps.gen.plug.menu import BooleanOption
from gramps.gen.plug.menu import PersonOption
from gramps.gen.plug.menu import FamilyOption
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.docgen import (FontStyle, ParagraphStyle, GraphicsStyle,
FONT_SANS_SERIF, PARA_ALIGN_CENTER)
from gramps.plugins.lib.libtreebase import *
PT2CM = ReportUtils.pt2cm PT2CM = ReportUtils.pt2cm
@ -58,14 +54,12 @@ PT2CM = ReportUtils.pt2cm
# Constants # Constants
# #
#------------------------------------------------------------------------ #------------------------------------------------------------------------
_BORN = _('short for born|b.') _BORN = _("birth abbreviation|b."),
_DIED = _('short for died|d.') _DIED = _("death abbreviation|d."),
_MARR = _('short for married|m.') _MARR = _("marriage abbreviation|m."),
_RPT_NAME = 'descend_chart' _RPT_NAME = 'descend_chart'
from gramps.plugins.lib.libtreebase import *
#------------------------------------------------------------------------ #------------------------------------------------------------------------
# #
# Box classes # Box classes
@ -137,9 +131,10 @@ class PlaceHolderBox(BoxBase):
# #
#------------------------------------------------------------------------ #------------------------------------------------------------------------
class DescendantTitleBase(TitleBox): class DescendantTitleBase(TitleBox):
def __init__(self, dbase, doc, boxstr = "CG2-Title"): def __init__(self, dbase, doc, locale, boxstr = "CG2-Title"):
TitleBox.__init__(self, doc, boxstr) TitleBox.__init__(self, doc, boxstr)
self.database = dbase self.database = dbase
self._ = locale.translation.sgettext
def descendant_print(self, person_list, person_list2 = []): def descendant_print(self, person_list, person_list2 = []):
""" calculate the Descendant title """ calculate the Descendant title
@ -158,34 +153,35 @@ class DescendantTitleBase(TitleBox):
names2 = self._get_names(person_list2) names2 = self._get_names(person_list2)
if len(names) + len(names2) == 3: if len(names) + len(names2) == 3:
if len(names) == 1: if len(names) == 1:
title = _("Descendant Chart for %(person)s and " title = self._("Descendant Chart for %(person)s and "
"%(father1)s, %(mother1)s") % \ "%(father1)s, %(mother1)s") % {
{'person': names[0], 'person': names[0],
'father1': names2[0], 'father1': names2[0],
'mother1': names2[1], 'mother1': names2[1],
} }
else: # Should be 2 items in names list else: # Should be 2 items in names list
title = _("Descendant Chart for %(person)s, %(father1)s " title = self._("Descendant Chart for %(person)s, "
"and %(mother1)s") % \ "%(father1)s and %(mother1)s") % {
{'father1': names[0], 'father1': names[0],
'mother1': names[1], 'mother1': names[1],
'person': names2[0], 'person': names2[0],
} }
else: # Should be 2 items in both names and names2 lists else: # Should be 2 items in both names and names2 lists
title = _("Descendant Chart for %(father1)s, %(father2)s " title = self._("Descendant Chart for %(father1)s, %(father2)s "
"and %(mother1)s, %(mother2)s") % \ "and %(mother1)s, %(mother2)s") % {
{'father1': names[0], 'father1': names[0],
'mother1': names[1], 'mother1': names[1],
'father2': names2[0], 'father2': names2[0],
'mother2': names2[1], 'mother2': names2[1],
} }
else: # No person_list2: Just one family else: # No person_list2: Just one family
if len(names) == 1: if len(names) == 1:
title = _("Descendant Chart for %(person)s") % \ title = self._("Descendant Chart for %(person)s") % {
{'person': names[0]} 'person': names[0]}
else: # Should be two items in names list else: # Should be two items in names list
title = _("Descendant Chart for %(father)s and %(mother)s") % \ title = self._("Descendant Chart for %(father)s and "
{'father': names[0], "%(mother)s") % {
'father': names[0],
'mother': names[1], 'mother': names[1],
} }
return title return title
@ -205,21 +201,22 @@ class DescendantTitleBase(TitleBox):
class TitleNone(TitleNoDisplay): class TitleNone(TitleNoDisplay):
"""No Title class for the report """ """No Title class for the report """
def __init__(self, dbase, doc): def __init__(self, dbase, doc, locale):
TitleNoDisplay.__init__(self, doc, "CG2-Title") TitleNoDisplay.__init__(self, doc, "CG2-Title")
self._ = locale.translation.sgettext
def calc_title(self, persons): def calc_title(self, persons):
"""Calculate the title of the report""" """Calculate the title of the report"""
#we want no text, but need a text for the TOC in a book! #we want no text, but need a text for the TOC in a book!
self.mark_text = _('Descendant Graph') self.mark_text = self._('Descendant Graph')
self.text = '' self.text = ''
class TitleDPY(DescendantTitleBase): class TitleDPY(DescendantTitleBase):
"""Descendant (Person yes start with parents) Chart """Descendant (Person yes start with parents) Chart
Title class for the report """ Title class for the report """
def __init__(self, dbase, doc): def __init__(self, dbase, doc, locale):
DescendantTitleBase.__init__(self, dbase, doc) DescendantTitleBase.__init__(self, dbase, doc, locale)
def calc_title(self, person_id): def calc_title(self, person_id):
"""Calculate the title of the report""" """Calculate the title of the report"""
@ -245,8 +242,8 @@ class TitleDPN(DescendantTitleBase):
"""Descendant (Person no start with parents) Chart """Descendant (Person no start with parents) Chart
Title class for the report """ Title class for the report """
def __init__(self, dbase, doc): def __init__(self, dbase, doc, locale):
DescendantTitleBase.__init__(self, dbase, doc) DescendantTitleBase.__init__(self, dbase, doc, locale)
def calc_title(self, person_id): def calc_title(self, person_id):
"""Calculate the title of the report""" """Calculate the title of the report"""
@ -261,8 +258,8 @@ class TitleDFY(DescendantTitleBase):
"""Descendant (Family yes start with parents) Chart """Descendant (Family yes start with parents) Chart
Title class for the report """ Title class for the report """
def __init__(self, dbase, doc): def __init__(self, dbase, doc, locale):
DescendantTitleBase.__init__(self, dbase, doc) DescendantTitleBase.__init__(self, dbase, doc, locale)
def get_parent_list(self, person): def get_parent_list(self, person):
""" return a list of my parents. If none, return me """ """ return a list of my parents. If none, return me """
@ -301,8 +298,8 @@ class TitleDFN(DescendantTitleBase):
"""Descendant (Family no start with parents) Chart """Descendant (Family no start with parents) Chart
Title class for the report """ Title class for the report """
def __init__(self, dbase, doc): def __init__(self, dbase, doc, locale):
DescendantTitleBase.__init__(self, dbase, doc) DescendantTitleBase.__init__(self, dbase, doc, locale)
def calc_title(self, family_id): def calc_title(self, family_id):
"""Calculate the title of the report""" """Calculate the title of the report"""
@ -313,8 +310,9 @@ class TitleDFN(DescendantTitleBase):
class TitleF(DescendantTitleBase): class TitleF(DescendantTitleBase):
"""Family Chart Title class for the report """ """Family Chart Title class for the report """
def __init__(self, dbase, doc):
DescendantTitleBase.__init__(self, dbase, doc) def __init__(self, dbase, doc, locale):
DescendantTitleBase.__init__(self, dbase, doc, locale)
def calc_title(self, family_id): def calc_title(self, family_id):
"""Calculate the title of the report""" """Calculate the title of the report"""
@ -323,10 +321,11 @@ class TitleF(DescendantTitleBase):
names = self._get_names(parents) names = self._get_names(parents)
if len(parents) == 1: if len(parents) == 1:
title = _("Family Chart for %(person)s") % {'person': names[0] } title = self._("Family Chart for %(person)s") % {
'person': names[0] }
elif len(parents) == 2: elif len(parents) == 2:
title = _("Family Chart for %(father1)s and %(mother1)s") % \ title = self._("Family Chart for %(father1)s and %(mother1)s") % {
{'father1': names[0], 'mother1': names[1] } 'father1': names[0], 'mother1': names[1] }
#else: #else:
# title = str(tmp) + " " + str(len(tmp)) # title = str(tmp) + " " + str(len(tmp))
self.text = title self.text = title
@ -334,8 +333,9 @@ class TitleF(DescendantTitleBase):
class TitleC(DescendantTitleBase): class TitleC(DescendantTitleBase):
"""Cousin Chart Title class for the report """ """Cousin Chart Title class for the report """
def __init__(self, dbase, doc):
DescendantTitleBase.__init__(self, dbase, doc) def __init__(self, dbase, doc, locale):
DescendantTitleBase.__init__(self, dbase, doc, locale)
def calc_title(self, family_id): def calc_title(self, family_id):
"""Calculate the title of the report""" """Calculate the title of the report"""
@ -346,9 +346,11 @@ class TitleC(DescendantTitleBase):
for kid in family.get_child_ref_list()] for kid in family.get_child_ref_list()]
#ok we have the children. Make a title off of them #ok we have the children. Make a title off of them
tmp = self._get_names(kids) # translators: needed for Arabic, ignore otherwise
cousin_names = _(', ').join(self._get_names(kids))
self.text = _("Cousin Chart for " + ", ".join(self._get_names(kids))) # FIXME it should be reformatted, but that would mean new translations
self.text = self._("Cousin Chart for ") + cousin_names
self.set_box_height_width() self.set_box_height_width()
@ -1189,9 +1191,10 @@ class GuiConnect():
def __init__(self): #We are BORG! def __init__(self): #We are BORG!
self.__dict__ = self.__shared_state self.__dict__ = self.__shared_state
def set__opts(self, options, which): def set__opts(self, options, which, locale):
self._opts = options self._opts = options
self._which_report = which.split(",")[0] self._which_report = which.split(",")[0]
self._locale = locale
def get_val(self, val): def get_val(self, val):
""" Get a GUI value. """ """ Get a GUI value. """
@ -1204,24 +1207,24 @@ class GuiConnect():
def Title_class(self, database, doc): def Title_class(self, database, doc):
Title_type = self.get_val('report_title') Title_type = self.get_val('report_title')
if Title_type == 0: #None if Title_type == 0: #None
return TitleNone(database, doc) return TitleNone(database, doc, self._locale)
if Title_type == 1: #Descendant Chart if Title_type == 1: #Descendant Chart
if self._which_report == _RPT_NAME: if self._which_report == _RPT_NAME:
if self.get_val('show_parents'): if self.get_val('show_parents'):
return TitleDPY(database, doc) return TitleDPY(database, doc, self._locale)
else: else:
return TitleDPN(database, doc) return TitleDPN(database, doc, self._locale)
else: else:
if self.get_val('show_parents'): if self.get_val('show_parents'):
return TitleDFY(database, doc) return TitleDFY(database, doc, self._locale)
else: else:
return TitleDFN(database, doc) return TitleDFN(database, doc, self._locale)
if Title_type == 2: if Title_type == 2:
return TitleF(database, doc) return TitleF(database, doc, self._locale)
else: #Title_type == 3 else: #Title_type == 3
return TitleC(database, doc) return TitleC(database, doc, self._locale)
def Make_Tree(self, database, canvas): def Make_Tree(self, database, canvas):
if self._which_report == _RPT_NAME: if self._which_report == _RPT_NAME:
@ -1235,7 +1238,7 @@ class GuiConnect():
#str = "" #str = ""
#if self.get_val('miss_val'): #if self.get_val('miss_val'):
# str = "_____" # str = "_____"
return CalcLines(database, display_repl) return CalcLines(database, display_repl, self._locale)
def working_lines(self, box): def working_lines(self, box):
display = self.get_val("descend_disp") display = self.get_val("descend_disp")
@ -1275,6 +1278,9 @@ class DescendTree(Report):
self.options = options self.options = options
self.database = database self.database = database
lang = options.menu.get_option_by_name('trans').get_value()
self._locale = self.set_locale(lang)
def begin_report(self): def begin_report(self):
""" make the report in its full size and pages to print on """ make the report in its full size and pages to print on
scale one or both as needed/desired. scale one or both as needed/desired.
@ -1283,7 +1289,8 @@ class DescendTree(Report):
database = self.database database = self.database
self.Connect = GuiConnect() self.Connect = GuiConnect()
self.Connect.set__opts(self.options.menu, self.options.name) self.Connect.set__opts(self.options.menu, self.options.name,
self._locale)
style_sheet = self.doc.get_style_sheet() style_sheet = self.doc.get_style_sheet()
font_normal = style_sheet.get_paragraph_style("CG2-Normal").get_font() font_normal = style_sheet.get_paragraph_style("CG2-Normal").get_font()
@ -1320,7 +1327,7 @@ class DescendTree(Report):
if self.Connect.get_val("inc_note"): if self.Connect.get_val("inc_note"):
note_box = NoteBox(self.doc, "CG2-note-box", note_box = NoteBox(self.doc, "CG2-note-box",
self.Connect.get_val("note_place")) self.Connect.get_val("note_place"))
subst = SubstKeywords(self.database, None, None) subst = SubstKeywords(self.database, self._locale, None, None)
note_box.text = subst.replace_and_clean( note_box.text = subst.replace_and_clean(
self.Connect.get_val('note_disp')) self.Connect.get_val('note_disp'))
self.canvas.add_note(note_box) self.canvas.add_note(note_box)
@ -1365,7 +1372,7 @@ class DescendTree(Report):
#p = self.doc.get_style_sheet().get_paragraph_style("CG2-Normal") #p = self.doc.get_style_sheet().get_paragraph_style("CG2-Normal")
#font = p.get_font() #font = p.get_font()
if prnnum: if prnnum:
page_num_box = PageNumberBox(self.doc, 'CG2-box') page_num_box = PageNumberBox(self.doc, 'CG2-box', self._locale)
##################### #####################
#ok, everyone is now ready to print on the canvas. Paginate? #ok, everyone is now ready to print on the canvas. Paginate?
@ -1512,6 +1519,8 @@ class DescendTreeOptions(MenuReportOptions):
"resulting in a smaller tree")) "resulting in a smaller tree"))
menu.add_option(category_name, "compress_tree", compresst) menu.add_option(category_name, "compress_tree", compresst)
stdoptions.add_localization_option(menu, category_name)
################## ##################
category_name = _("Display") category_name = _("Display")
@ -1622,6 +1631,12 @@ class DescendTreeOptions(MenuReportOptions):
self.title = EnumeratedListOption(_("Report Title"), 0) self.title = EnumeratedListOption(_("Report Title"), 0)
self.title.add_item( 0, _("Do not include a title")) self.title.add_item( 0, _("Do not include a title"))
self.title.add_item( 1, _("Descendant Chart for [selected person(s)]")) self.title.add_item( 1, _("Descendant Chart for [selected person(s)]"))
if self.name.split(",")[0] != _RPT_NAME:
self.title.add_item(2,
_("Family Chart for [names of chosen family]"))
if self.showparents.get_value():
self.title.add_item(3,
_("Cousin Chart for [names of children]"))
self.title.set_help(_("Choose a title for the report")) self.title.set_help(_("Choose a title for the report"))
menu.add_option(category_name, "report_title", self.title) menu.add_option(category_name, "report_title", self.title)
self.showparents.connect('value-changed', self.__Title_enum) self.showparents.connect('value-changed', self.__Title_enum)
@ -1685,9 +1700,6 @@ class DescendTreeOptions(MenuReportOptions):
def make_default_style(self, default_style): def make_default_style(self, default_style):
"""Make the default output style for the Descendant Tree.""" """Make the default output style for the Descendant Tree."""
from gramps.gen.plug.docgen import (FontStyle, ParagraphStyle, GraphicsStyle,
FONT_SANS_SERIF, PARA_ALIGN_CENTER)
## Paragraph Styles: ## Paragraph Styles:
font = FontStyle() font = FontStyle()
font.set_size(16) font.set_size(16)

View File

@ -1,7 +1,10 @@
# #
# Gramps - a GTK+/GNOME based genealogy program # Gramps - a GTK+/GNOME based genealogy program
# #
# Copyright (C) 2000-2007 Donald N. Allingham
# Copyright (C) 2010 Peter G. Landgren
# Copyright (C) 2010 Craig J. Anderson # Copyright (C) 2010 Craig J. Anderson
# Copyright (C) 2014 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
@ -22,7 +25,7 @@
""" """
Provide the SubstKeywords class that will replace keywords in a passed Provide the SubstKeywords class that will replace keywords in a passed
string with information about the person/marriage/spouse. For sample: string with information about the person/marriage/spouse. For example:
foo = SubstKeywords(database, person_handle) foo = SubstKeywords(database, person_handle)
print foo.replace_and_clean(['$n was born on $b.']) print foo.replace_and_clean(['$n was born on $b.'])
@ -40,11 +43,11 @@ from __future__ import print_function
# #
#------------------------------------------------------------------------ #------------------------------------------------------------------------
from gramps.gen.display.name import displayer as name_displayer from gramps.gen.display.name import displayer as name_displayer
from gramps.gen.datehandler import displayer
from gramps.gen.lib import EventType, PlaceType, Location from gramps.gen.lib import EventType, PlaceType, Location
from gramps.gen.utils.db import get_birth_or_fallback, get_death_or_fallback from gramps.gen.utils.db import get_birth_or_fallback, get_death_or_fallback
from gramps.gen.constfunc import STRTYPE, cuni from gramps.gen.constfunc import STRTYPE, cuni
from gramps.gen.utils.location import get_main_location from gramps.gen.utils.location import get_main_location
from gramps.gen.const import GRAMPS_LOCALE as glocale
#------------------------------------------------------------------------ #------------------------------------------------------------------------
@ -72,8 +75,9 @@ class GenericFormat(object):
"""A Generic parsing class. Will be subclassed by specific format strings """A Generic parsing class. Will be subclassed by specific format strings
""" """
def __init__(self, string_in): def __init__(self, string_in, qlocale=glocale):
self.string_in = string_in self.string_in = string_in
self._locale = qlocale
def _default_format(self, item): def _default_format(self, item):
""" The default format if there is no format string """ """ The default format if there is no format string """
@ -198,7 +202,7 @@ class DateFormat(GenericFormat):
return None return None
def _default_format(self, date): def _default_format(self, date):
return displayer.display(date) return self._locale.date_displayer.display(date)
def __count_chars(self, char, max_amount): def __count_chars(self, char, max_amount):
""" count the year/month/day codes """ """ count the year/month/day codes """
@ -255,13 +259,14 @@ class DateFormat(GenericFormat):
tmp = "0" + month tmp = "0" + month
return tmp[-2:] return tmp[-2:]
elif count == 3: # found 'mmm' elif count == 3: # found 'mmm'
return displayer.short_months[int(month)] return self._locale.date_displayer.short_months[int(month)]
else: # found 'mmmm' else: # found 'mmmm'
return displayer.long_months[int(month)] return self._locale.date_displayer.long_months[int(month)]
def month_up(): def month_up():
return month("M").upper() tmp = month("M") # only call it ONCE, then use the value
if tmp:
return tmp.upper()
def day(): def day():
""" The day part only """ """ The day part only """
@ -279,9 +284,11 @@ class DateFormat(GenericFormat):
def modifier(): def modifier():
#ui_mods taken from date.py def lookup_modifier(self, modifier): #ui_mods taken from date.py def lookup_modifier(self, modifier):
ui_mods = ["", _("before"), _("after"), _("about"), # trans_text is a defined keyword (in po/update_po.py, po/genpot.sh)
"", "", ""] trans_text = self._locale.translation.gettext
return ui_mods[date.get_modifier()].capitalize() ui_mods = ["", trans_text("before"), trans_text("after"),
trans_text("about"), "", "", ""]
return ui_mods[date.get_modifier()]
code = "ymdMo" code = "ymdMo"
@ -359,9 +366,9 @@ class EventFormat(GenericFormat):
dates and places can have their own format strings dates and places can have their own format strings
""" """
def __init__(self, database, _in): def __init__(self, database, _in, locale):
self.database = database self.database = database
GenericFormat.__init__(self, _in) GenericFormat.__init__(self, _in, locale)
def _default_format(self, event): def _default_format(self, event):
if event is None: if event is None:
@ -388,7 +395,7 @@ class EventFormat(GenericFormat):
def format_date(): def format_date():
""" start formatting a date in this event """ """ start formatting a date in this event """
date_format = DateFormat(self.string_in) date_format = DateFormat(self.string_in, self._locale)
return date_format.parse_format(date_format.get_date(event)) return date_format.parse_format(date_format.get_date(event))
def format_place(): def format_place():
@ -483,9 +490,9 @@ class GalleryFormat(GenericFormat):
dates (no places) can have their own format strings dates (no places) can have their own format strings
""" """
def __init__(self, database, _in): def __init__(self, database, _in, locale):
self.database = database self.database = database
GenericFormat.__init__(self, _in) GenericFormat.__init__(self, _in, locale)
def _default_format(self, photo): def _default_format(self, photo):
if photo is None: if photo is None:
@ -512,7 +519,7 @@ class GalleryFormat(GenericFormat):
def format_date(): def format_date():
""" start formatting a date in this photo """ """ start formatting a date in this photo """
date_format = DateFormat(self.string_in) date_format = DateFormat(self.string_in, self._locale)
return date_format.parse_format(date_format.get_date(photo)) return date_format.parse_format(date_format.get_date(photo))
def format_attrib(): def format_attrib():
@ -776,10 +783,11 @@ class AttributeParse(object):
class VariableParse(object): class VariableParse(object):
""" Parse the individual variables """ """ Parse the individual variables """
def __init__(self, friend, database, consumer_in): def __init__(self, friend, database, consumer_in, locale):
self.friend = friend self.friend = friend
self.database = database self.database = database
self._in = consumer_in self._in = consumer_in
self._locale = locale
def is_a(self): def is_a(self):
""" check """ """ check """
@ -838,7 +846,7 @@ class VariableParse(object):
""" sub to process a date """ sub to process a date
Given an event, get the date object, process the format, Given an event, get the date object, process the format,
return the result """ return the result """
date_f = DateFormat(self._in) date_f = DateFormat(self._in, self._locale)
date = date_f.get_date(event) date = date_f.get_date(event)
if self.empty_item(date): if self.empty_item(date):
return return
@ -867,7 +875,7 @@ class VariableParse(object):
def __parse_event(self, person, attrib_parse): def __parse_event(self, person, attrib_parse):
event = self.get_event_by_name(person, attrib_parse.get_name()) event = self.get_event_by_name(person, attrib_parse.get_name())
event_f = EventFormat(self.database, self._in) event_f = EventFormat(self.database, self._in, self._locale)
if event: if event:
return event_f.parse_format(event) return event_f.parse_format(event)
else: else:
@ -886,7 +894,7 @@ class VariableParse(object):
return None return None
def __parse_photo(self, person_or_marriage): def __parse_photo(self, person_or_marriage):
photo_f = GalleryFormat(self.database, self._in) photo_f = GalleryFormat(self.database, self._in, self._locale)
if person_or_marriage is None: if person_or_marriage is None:
return photo_f.parse_empty() return photo_f.parse_empty()
photo = self.__get_photo(person_or_marriage) photo = self.__get_photo(person_or_marriage)
@ -997,7 +1005,7 @@ class VariableParse(object):
#person event #person event
return self.__parse_event(self.friend.person, attrib_parse) return self.__parse_event(self.friend.person, attrib_parse)
elif next_char == "t": elif next_char == "t":
#person event #family event
return self.__parse_event(self.friend.family, attrib_parse) return self.__parse_event(self.friend.family, attrib_parse)
elif next_char == 'p': elif next_char == 'p':
@ -1031,7 +1039,7 @@ class SubstKeywords(object):
this will specify the specific family/spouse to work with. this will specify the specific family/spouse to work with.
If none given, then the first/preferred family/spouse is used If none given, then the first/preferred family/spouse is used
""" """
def __init__(self, database, person_handle, family_handle=None): def __init__(self, database, locale, person_handle, family_handle=None):
"""get the person and find the family/spouse to use for this display""" """get the person and find the family/spouse to use for this display"""
self.database = database self.database = database
@ -1039,6 +1047,7 @@ class SubstKeywords(object):
self.family = None self.family = None
self.spouse = None self.spouse = None
self.line = None # Consumable_string - set below self.line = None # Consumable_string - set below
self._locale = locale
if self.person is None: if self.person is None:
return return
@ -1082,7 +1091,7 @@ class SubstKeywords(object):
#First we are going take care of all variables/groups #First we are going take care of all variables/groups
#break down all {} (groups) and $ (vars) into either #break down all {} (groups) and $ (vars) into either
#(TXT.text, resulting_string) or (TXT.remove, '') #(TXT.text, resulting_string) or (TXT.remove, '')
variable = VariableParse(self, self.database, self.line) # $ variable = VariableParse(self, self.database, self.line, self._locale) # $
while self.line.this: while self.line.this:
if self.line.this == "{": if self.line.this == "{":

View File

@ -2,6 +2,7 @@
# Gramps - a GTK+/GNOME based genealogy program # Gramps - a GTK+/GNOME based genealogy program
# #
# Copyright (C) 2008-2010 Craig J. Anderson # Copyright (C) 2008-2010 Craig J. Anderson
# Copyright (C) 2014 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
@ -55,10 +56,11 @@ class CalcLines(object):
Receive: Individual and family handle, and display format [string] Receive: Individual and family handle, and display format [string]
return: [Text] ready for a box. return: [Text] ready for a box.
""" """
def __init__(self, dbase, repl): def __init__(self, dbase, repl, locale):
self.database = dbase self.database = dbase
self.display_repl = repl self.display_repl = repl
#self.default_string = default_str #self.default_string = default_str
self._locale = locale
def calc_lines(self, _indi_handle, _fams_handle, workinglines): def calc_lines(self, _indi_handle, _fams_handle, workinglines):
""" """
@ -69,7 +71,8 @@ class CalcLines(object):
#################### ####################
#1.1 Get our line information here #1.1 Get our line information here
subst = SubstKeywords(self.database, _indi_handle, _fams_handle) subst = SubstKeywords(self.database, self._locale,
_indi_handle, _fams_handle)
lines = subst.replace_and_clean(workinglines) lines = subst.replace_and_clean(workinglines)
#################### ####################
@ -700,15 +703,17 @@ class PageNumberBox(BoxBase):
do not put in a value for PageNumberBox.text. this will be calculated for do not put in a value for PageNumberBox.text. this will be calculated for
each page """ each page """
def __init__(self, doc, boxstr): def __init__(self, doc, boxstr, locale):
""" initialize the page number box """ """ initialize the page number box """
BoxBase.__init__(self) BoxBase.__init__(self)
self.doc = doc self.doc = doc
self.boxstr = boxstr self.boxstr = boxstr
self._ = locale.translation.sgettext
def __calc_position(self, page): def __calc_position(self, page):
""" calculate where I am to print on the page(s) """ """ calculate where I am to print on the page(s) """
self.text = "(%d,%d)" # translators: needed for Arabic, ignore otherwise
self.text = self._("(%d,%d)")
style_sheet = self.doc.get_style_sheet() style_sheet = self.doc.get_style_sheet()
style_name = style_sheet.get_draw_style(self.boxstr) style_name = style_sheet.get_draw_style(self.boxstr)
@ -778,10 +783,10 @@ class NoteType(object):
class NoteBox(BoxBase, NoteType): class NoteBox(BoxBase, NoteType):
""" Box that will hold the note to display on the page """ """ Box that will hold the note to display on the page """
def __init__(self, doc, boxstr, locale, exclude=None): def __init__(self, doc, boxstr, box_corner, exclude=None):
""" initialize the NoteBox """ """ initialize the NoteBox """
BoxBase.__init__(self) BoxBase.__init__(self)
NoteType.__init__(self, locale, exclude) NoteType.__init__(self, box_corner, exclude)
self.doc = doc self.doc = doc
self.boxstr = boxstr self.boxstr = boxstr