From 2c2f1d61c88b26b6452a870700168af2decfac9e Mon Sep 17 00:00:00 2001 From: Paul Franklin Date: Wed, 9 Apr 2014 10:30:49 -0700 Subject: [PATCH] 7585: provide translated output for Ancestor Tree and Descendant Tree reports --- gramps/plugins/drawreport/ancestortree.py | 69 +++++---- gramps/plugins/drawreport/descendtree.py | 174 ++++++++++++---------- gramps/plugins/lib/libsubstkeyword.py | 57 ++++--- gramps/plugins/lib/libtreebase.py | 19 ++- 4 files changed, 172 insertions(+), 147 deletions(-) diff --git a/gramps/plugins/drawreport/ancestortree.py b/gramps/plugins/drawreport/ancestortree.py index cd0e287a8..3f3ec878a 100644 --- a/gramps/plugins/drawreport/ancestortree.py +++ b/gramps/plugins/drawreport/ancestortree.py @@ -4,6 +4,7 @@ # Copyright (C) 2007-2008 Brian G. Matherly # Copyright (C) 2010 Jakim Friant # Copyright (C) 2010 Craig J. Anderson +# Copyright (C) 2014 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 @@ -39,29 +40,23 @@ def log2(val): X_INDEX = log2 -from gramps.gen.const import GRAMPS_LOCALE as glocale -_ = glocale.translation.sgettext - #------------------------------------------------------------------------ # # GRAMPS modules # #------------------------------------------------------------------------ -#from gramps.gen.errors import ReportError - -from gramps.gen.plug.menu import BooleanOption -from gramps.gen.plug.menu import NumberOption -from gramps.gen.plug.menu import StringOption -from gramps.gen.plug.menu import EnumeratedListOption -from gramps.gen.plug.menu import TextOption -from gramps.gen.plug.menu import PersonOption - -from gramps.gen.plug.report import Report +from gramps.gen.const import GRAMPS_LOCALE as glocale +_ = glocale.translation.sgettext +from gramps.gen.plug.menu import (TextOption, NumberOption, BooleanOption, + EnumeratedListOption, StringOption, + PersonOption) +from gramps.gen.plug.report import Report, MenuReportOptions, stdoptions 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.plug.docgen import (FontStyle, ParagraphStyle, GraphicsStyle, + FONT_SANS_SERIF, PARA_ALIGN_CENTER) +from gramps.plugins.lib.libtreebase import * PT2CM = ReportUtils.pt2cm #cm2pt = ReportUtils.cm2pt @@ -71,11 +66,9 @@ PT2CM = ReportUtils.pt2cm # Constants # #------------------------------------------------------------------------ -_BORN = _('short for born|b.') -_DIED = _('short for died|d.') -_MARR = _('short for married|m.') - -from gramps.plugins.lib.libtreebase import * +_BORN = _("birth abbreviation|b."), +_DIED = _("death abbreviation|d."), +_MARR = _("marriage abbreviation|m."), #------------------------------------------------------------------------ # @@ -132,19 +125,21 @@ class FamilyBox(AncestorBoxBase): class TitleN(TitleNoDisplay): """No Title class for the report """ - def __init__(self, doc): + def __init__(self, doc, locale): TitleNoDisplay.__init__(self, doc, "AC2-Title") + self._ = locale.translation.sgettext def calc_title(self, center): """Calculate the title of the report""" #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 = '' class TitleA(TitleBox): """Title class for the report """ - def __init__(self, doc): + def __init__(self, doc, locale): TitleBox.__init__(self, doc, "AC2-Title") + self._ = locale.translation.sgettext def calc_title(self, center): """Calculate the title of the report""" @@ -153,7 +148,7 @@ class TitleA(TitleBox): name = name_displayer.display(center) # 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() @@ -172,7 +167,7 @@ class CalcItems(object): #str = "" #if self.get_val('miss_val'): # str = "_____" - self.__calc_l = CalcLines(dbase, []) + self.__calc_l = CalcLines(dbase, [], __gui._locale) self.__blank_father = None self.__blank_mother = None @@ -628,9 +623,10 @@ class GUIConnect(): def __init__(self): #We are BORG! self.__dict__ = self.__shared_state - def set__opts(self, options): + def set__opts(self, options, locale): """ Set only once as we are BORG. """ self.__opts = options + self._locale = locale def get_val(self, val): """ Get a GUI value. """ @@ -644,7 +640,10 @@ class GUIConnect(): """ Return a class that holds the proper title based off of the GUI options """ 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._user = user + lang = options.menu.get_option_by_name('trans').get_value() + self._locale = self.set_locale(lang) + def begin_report(self): """ This report needs the following parameters (class variables) @@ -692,7 +694,7 @@ class AncestorTree(Report): database = self.database 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. style_sheet = self.doc.get_style_sheet() @@ -743,7 +745,7 @@ class AncestorTree(Report): if self.connect.get_val("inc_note"): note_box = NoteBox(self.doc, "AC2-note-box", 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( self.connect.get_val('note_disp')) self.canvas.add_note(note_box) @@ -783,7 +785,7 @@ class AncestorTree(Report): ##################### #Vars 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? @@ -821,8 +823,6 @@ class AncestorTree(Report): """ 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.set_shadow(graph_style.get_shadow(), 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")) menu.add_option(category_name, "center_uses", centerDisp) + stdoptions.add_localization_option(menu, category_name) + ################## category_name = _("Display") @@ -1090,9 +1092,6 @@ class AncestorTreeOptions(MenuReportOptions): def make_default_style(self, default_style): """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: font = FontStyle() font.set_size(9) diff --git a/gramps/plugins/drawreport/descendtree.py b/gramps/plugins/drawreport/descendtree.py index 1235a1ce3..3b74576c1 100644 --- a/gramps/plugins/drawreport/descendtree.py +++ b/gramps/plugins/drawreport/descendtree.py @@ -1,10 +1,11 @@ # # Gramps - a GTK+/GNOME based genealogy program # -# Copyright (C) 2000-2007 Donald N. Allingham -# Copyright (C) 2007-2008 Brian G. Matherly -# Copyright (C) 2010 Jakim Friant -# Copyright (C) 2009-2010 Craig J. Anderson +# Copyright (C) 2000-2007 Donald N. Allingham +# Copyright (C) 2007-2008 Brian G. Matherly +# Copyright (C) 2010 Jakim Friant +# Copyright (C) 2009-2010 Craig J. Anderson +# Copyright (C) 2014 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 @@ -36,20 +37,15 @@ from __future__ import division #------------------------------------------------------------------------ from gramps.gen.const import GRAMPS_LOCALE as glocale _ = glocale.translation.sgettext - from gramps.gen.errors import ReportError - -from gramps.gen.plug.menu import TextOption -from gramps.gen.plug.menu import NumberOption -from gramps.gen.plug.menu import EnumeratedListOption -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.menu import (TextOption, NumberOption, BooleanOption, + EnumeratedListOption, StringOption, + PersonOption, FamilyOption) +from gramps.gen.plug.report import Report, MenuReportOptions, stdoptions 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 @@ -58,14 +54,12 @@ PT2CM = ReportUtils.pt2cm # Constants # #------------------------------------------------------------------------ -_BORN = _('short for born|b.') -_DIED = _('short for died|d.') -_MARR = _('short for married|m.') +_BORN = _("birth abbreviation|b."), +_DIED = _("death abbreviation|d."), +_MARR = _("marriage abbreviation|m."), _RPT_NAME = 'descend_chart' -from gramps.plugins.lib.libtreebase import * - #------------------------------------------------------------------------ # # Box classes @@ -137,9 +131,10 @@ class PlaceHolderBox(BoxBase): # #------------------------------------------------------------------------ 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) self.database = dbase + self._ = locale.translation.sgettext def descendant_print(self, person_list, person_list2 = []): """ calculate the Descendant title @@ -158,36 +153,37 @@ class DescendantTitleBase(TitleBox): names2 = self._get_names(person_list2) if len(names) + len(names2) == 3: if len(names) == 1: - title = _("Descendant Chart for %(person)s and " - "%(father1)s, %(mother1)s") % \ - {'person': names[0], - 'father1': names2[0], - 'mother1': names2[1], - } + title = self._("Descendant Chart for %(person)s and " + "%(father1)s, %(mother1)s") % { + 'person': names[0], + 'father1': names2[0], + 'mother1': names2[1], + } else: # Should be 2 items in names list - title = _("Descendant Chart for %(person)s, %(father1)s " - "and %(mother1)s") % \ - {'father1': names[0], - 'mother1': names[1], - 'person': names2[0], - } + title = self._("Descendant Chart for %(person)s, " + "%(father1)s and %(mother1)s") % { + 'father1': names[0], + 'mother1': names[1], + 'person': names2[0], + } else: # Should be 2 items in both names and names2 lists - title = _("Descendant Chart for %(father1)s, %(father2)s " - "and %(mother1)s, %(mother2)s") % \ - {'father1': names[0], - 'mother1': names[1], - 'father2': names2[0], - 'mother2': names2[1], - } + title = self._("Descendant Chart for %(father1)s, %(father2)s " + "and %(mother1)s, %(mother2)s") % { + 'father1': names[0], + 'mother1': names[1], + 'father2': names2[0], + 'mother2': names2[1], + } else: # No person_list2: Just one family if len(names) == 1: - title = _("Descendant Chart for %(person)s") % \ - {'person': names[0]} + title = self._("Descendant Chart for %(person)s") % { + 'person': names[0]} else: # Should be two items in names list - title = _("Descendant Chart for %(father)s and %(mother)s") % \ - {'father': names[0], - 'mother': names[1], - } + title = self._("Descendant Chart for %(father)s and " + "%(mother)s") % { + 'father': names[0], + 'mother': names[1], + } return title def get_parents(self, family_id): @@ -205,21 +201,22 @@ class DescendantTitleBase(TitleBox): class TitleNone(TitleNoDisplay): """No Title class for the report """ - def __init__(self, dbase, doc): + def __init__(self, dbase, doc, locale): TitleNoDisplay.__init__(self, doc, "CG2-Title") + self._ = locale.translation.sgettext def calc_title(self, persons): """Calculate the title of the report""" #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 = '' class TitleDPY(DescendantTitleBase): """Descendant (Person yes start with parents) 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, person_id): """Calculate the title of the report""" @@ -245,8 +242,8 @@ class TitleDPN(DescendantTitleBase): """Descendant (Person no start with parents) 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, person_id): """Calculate the title of the report""" @@ -261,8 +258,8 @@ class TitleDFY(DescendantTitleBase): """Descendant (Family yes start with parents) 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 get_parent_list(self, person): """ return a list of my parents. If none, return me """ @@ -301,8 +298,8 @@ class TitleDFN(DescendantTitleBase): """Descendant (Family no start with parents) 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): """Calculate the title of the report""" @@ -313,8 +310,9 @@ class TitleDFN(DescendantTitleBase): class TitleF(DescendantTitleBase): """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): """Calculate the title of the report""" @@ -323,10 +321,11 @@ class TitleF(DescendantTitleBase): names = self._get_names(parents) 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: - title = _("Family Chart for %(father1)s and %(mother1)s") % \ - {'father1': names[0], 'mother1': names[1] } + title = self._("Family Chart for %(father1)s and %(mother1)s") % { + 'father1': names[0], 'mother1': names[1] } #else: # title = str(tmp) + " " + str(len(tmp)) self.text = title @@ -334,8 +333,9 @@ class TitleF(DescendantTitleBase): class TitleC(DescendantTitleBase): """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): """Calculate the title of the report""" @@ -346,9 +346,11 @@ class TitleC(DescendantTitleBase): for kid in family.get_child_ref_list()] #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() @@ -1189,9 +1191,10 @@ class GuiConnect(): def __init__(self): #We are BORG! self.__dict__ = self.__shared_state - def set__opts(self, options, which): + def set__opts(self, options, which, locale): self._opts = options self._which_report = which.split(",")[0] + self._locale = locale def get_val(self, val): """ Get a GUI value. """ @@ -1204,24 +1207,24 @@ class GuiConnect(): def Title_class(self, database, doc): Title_type = self.get_val('report_title') if Title_type == 0: #None - return TitleNone(database, doc) + return TitleNone(database, doc, self._locale) if Title_type == 1: #Descendant Chart if self._which_report == _RPT_NAME: if self.get_val('show_parents'): - return TitleDPY(database, doc) + return TitleDPY(database, doc, self._locale) else: - return TitleDPN(database, doc) + return TitleDPN(database, doc, self._locale) else: if self.get_val('show_parents'): - return TitleDFY(database, doc) + return TitleDFY(database, doc, self._locale) else: - return TitleDFN(database, doc) + return TitleDFN(database, doc, self._locale) if Title_type == 2: - return TitleF(database, doc) + return TitleF(database, doc, self._locale) else: #Title_type == 3 - return TitleC(database, doc) + return TitleC(database, doc, self._locale) def Make_Tree(self, database, canvas): if self._which_report == _RPT_NAME: @@ -1235,7 +1238,7 @@ class GuiConnect(): #str = "" #if self.get_val('miss_val'): # str = "_____" - return CalcLines(database, display_repl) + return CalcLines(database, display_repl, self._locale) def working_lines(self, box): display = self.get_val("descend_disp") @@ -1275,6 +1278,9 @@ class DescendTree(Report): self.options = options self.database = database + lang = options.menu.get_option_by_name('trans').get_value() + self._locale = self.set_locale(lang) + def begin_report(self): """ make the report in its full size and pages to print on scale one or both as needed/desired. @@ -1283,7 +1289,8 @@ class DescendTree(Report): database = self.database 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() 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"): note_box = NoteBox(self.doc, "CG2-note-box", 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( self.Connect.get_val('note_disp')) self.canvas.add_note(note_box) @@ -1365,7 +1372,7 @@ class DescendTree(Report): #p = self.doc.get_style_sheet().get_paragraph_style("CG2-Normal") #font = p.get_font() 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? @@ -1512,6 +1519,8 @@ class DescendTreeOptions(MenuReportOptions): "resulting in a smaller tree")) menu.add_option(category_name, "compress_tree", compresst) + stdoptions.add_localization_option(menu, category_name) + ################## category_name = _("Display") @@ -1622,6 +1631,12 @@ class DescendTreeOptions(MenuReportOptions): self.title = EnumeratedListOption(_("Report Title"), 0) self.title.add_item( 0, _("Do not include a title")) 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")) menu.add_option(category_name, "report_title", self.title) self.showparents.connect('value-changed', self.__Title_enum) @@ -1685,9 +1700,6 @@ class DescendTreeOptions(MenuReportOptions): def make_default_style(self, default_style): """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: font = FontStyle() font.set_size(16) diff --git a/gramps/plugins/lib/libsubstkeyword.py b/gramps/plugins/lib/libsubstkeyword.py index 36adb2e63..1cbe3d0b5 100644 --- a/gramps/plugins/lib/libsubstkeyword.py +++ b/gramps/plugins/lib/libsubstkeyword.py @@ -1,7 +1,10 @@ # # 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) 2014 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 @@ -22,7 +25,7 @@ """ 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) 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.datehandler import displayer 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.constfunc import STRTYPE, cuni 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 """ - def __init__(self, string_in): + def __init__(self, string_in, qlocale=glocale): self.string_in = string_in + self._locale = qlocale def _default_format(self, item): """ The default format if there is no format string """ @@ -198,7 +202,7 @@ class DateFormat(GenericFormat): return None def _default_format(self, date): - return displayer.display(date) + return self._locale.date_displayer.display(date) def __count_chars(self, char, max_amount): """ count the year/month/day codes """ @@ -255,13 +259,14 @@ class DateFormat(GenericFormat): tmp = "0" + month return tmp[-2:] elif count == 3: # found 'mmm' - return displayer.short_months[int(month)] + return self._locale.date_displayer.short_months[int(month)] else: # found 'mmmm' - return displayer.long_months[int(month)] + return self._locale.date_displayer.long_months[int(month)] 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(): """ The day part only """ @@ -279,9 +284,11 @@ class DateFormat(GenericFormat): def modifier(): #ui_mods taken from date.py def lookup_modifier(self, modifier): - ui_mods = ["", _("before"), _("after"), _("about"), - "", "", ""] - return ui_mods[date.get_modifier()].capitalize() + # trans_text is a defined keyword (in po/update_po.py, po/genpot.sh) + trans_text = self._locale.translation.gettext + ui_mods = ["", trans_text("before"), trans_text("after"), + trans_text("about"), "", "", ""] + return ui_mods[date.get_modifier()] code = "ymdMo" @@ -359,9 +366,9 @@ class EventFormat(GenericFormat): dates and places can have their own format strings """ - def __init__(self, database, _in): + def __init__(self, database, _in, locale): self.database = database - GenericFormat.__init__(self, _in) + GenericFormat.__init__(self, _in, locale) def _default_format(self, event): if event is None: @@ -388,7 +395,7 @@ class EventFormat(GenericFormat): def format_date(): """ 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)) def format_place(): @@ -483,9 +490,9 @@ class GalleryFormat(GenericFormat): dates (no places) can have their own format strings """ - def __init__(self, database, _in): + def __init__(self, database, _in, locale): self.database = database - GenericFormat.__init__(self, _in) + GenericFormat.__init__(self, _in, locale) def _default_format(self, photo): if photo is None: @@ -512,7 +519,7 @@ class GalleryFormat(GenericFormat): def format_date(): """ 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)) def format_attrib(): @@ -776,10 +783,11 @@ class AttributeParse(object): class VariableParse(object): """ Parse the individual variables """ - def __init__(self, friend, database, consumer_in): + def __init__(self, friend, database, consumer_in, locale): self.friend = friend self.database = database self._in = consumer_in + self._locale = locale def is_a(self): """ check """ @@ -838,7 +846,7 @@ class VariableParse(object): """ sub to process a date Given an event, get the date object, process the format, return the result """ - date_f = DateFormat(self._in) + date_f = DateFormat(self._in, self._locale) date = date_f.get_date(event) if self.empty_item(date): return @@ -867,7 +875,7 @@ class VariableParse(object): def __parse_event(self, person, attrib_parse): 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: return event_f.parse_format(event) else: @@ -886,7 +894,7 @@ class VariableParse(object): return None 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: return photo_f.parse_empty() photo = self.__get_photo(person_or_marriage) @@ -997,7 +1005,7 @@ class VariableParse(object): #person event return self.__parse_event(self.friend.person, attrib_parse) elif next_char == "t": - #person event + #family event return self.__parse_event(self.friend.family, attrib_parse) elif next_char == 'p': @@ -1031,7 +1039,7 @@ class SubstKeywords(object): this will specify the specific family/spouse to work with. 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""" self.database = database @@ -1039,6 +1047,7 @@ class SubstKeywords(object): self.family = None self.spouse = None self.line = None # Consumable_string - set below + self._locale = locale if self.person is None: return @@ -1082,7 +1091,7 @@ class SubstKeywords(object): #First we are going take care of all variables/groups #break down all {} (groups) and $ (vars) into either #(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: if self.line.this == "{": diff --git a/gramps/plugins/lib/libtreebase.py b/gramps/plugins/lib/libtreebase.py index c6ab88af0..f123cc7f7 100644 --- a/gramps/plugins/lib/libtreebase.py +++ b/gramps/plugins/lib/libtreebase.py @@ -1,7 +1,8 @@ # # 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 # 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] return: [Text] ready for a box. """ - def __init__(self, dbase, repl): + def __init__(self, dbase, repl, locale): self.database = dbase self.display_repl = repl #self.default_string = default_str + self._locale = locale def calc_lines(self, _indi_handle, _fams_handle, workinglines): """ @@ -69,7 +71,8 @@ class CalcLines(object): #################### #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) #################### @@ -700,15 +703,17 @@ class PageNumberBox(BoxBase): do not put in a value for PageNumberBox.text. this will be calculated for each page """ - def __init__(self, doc, boxstr): + def __init__(self, doc, boxstr, locale): """ initialize the page number box """ BoxBase.__init__(self) self.doc = doc self.boxstr = boxstr + self._ = locale.translation.sgettext def __calc_position(self, page): """ 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_name = style_sheet.get_draw_style(self.boxstr) @@ -778,10 +783,10 @@ class NoteType(object): class NoteBox(BoxBase, NoteType): """ 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 """ BoxBase.__init__(self) - NoteType.__init__(self, locale, exclude) + NoteType.__init__(self, box_corner, exclude) self.doc = doc self.boxstr = boxstr