Fix translated dates in Ancestor Report. Currently, dates for other than the current locale will print in ISO format.
svn: r13758
This commit is contained in:
parent
04a1da3daf
commit
c3546880fc
@ -165,7 +165,6 @@ src/gen/plug/menu/_string.py
|
||||
src/gen/plug/menu/_style.py
|
||||
src/gen/plug/menu/_surnamecolor.py
|
||||
src/gen/plug/menu/_text.py
|
||||
src/gen/plug/menu/_translation.py
|
||||
src/gen/plug/docgen/__init__.py
|
||||
src/gen/plug/docgen/basedoc.py
|
||||
src/gen/plug/docgen/drawdoc.py
|
||||
@ -449,6 +448,7 @@ src/plugins/lib/libmapservice.py
|
||||
src/plugins/lib/libnarrate.py
|
||||
src/plugins/lib/libodfbackend.py
|
||||
src/plugins/lib/libplugins.gpr.py
|
||||
src/plugins/lib/libtranslate.py
|
||||
|
||||
# plugins/mapservices directory
|
||||
src/plugins/mapservices/eniroswedenmap.py
|
||||
|
@ -54,8 +54,8 @@ class DateDisplay(object):
|
||||
u"June", u"July", u"August", u"September", u"October",
|
||||
u"November", u"December" )
|
||||
|
||||
short_months = ( u"", u"Jan", u"Feb", u"Mar", u"Apr", u"May", u"Jun", u"Jul",
|
||||
u"Aug", u"Sep", u"Oct", u"Nov", u"Dec" )
|
||||
short_months = ( u"", u"Jan", u"Feb", u"Mar", u"Apr", u"May", u"Jun",
|
||||
u"Jul", u"Aug", u"Sep", u"Oct", u"Nov", u"Dec" )
|
||||
|
||||
_tformat = GrampsLocale.tformat
|
||||
|
||||
|
@ -72,6 +72,12 @@ def setup_gettext():
|
||||
#following installs _ as a python function, we avoid this as TransUtils is
|
||||
#used sometimes:
|
||||
#gettext.install(LOCALEDOMAIN, LOCALEDIR, unicode=1)
|
||||
|
||||
def get_localedomain():
|
||||
"""
|
||||
Get the LOCALEDOMAIN used for the Gramps application.
|
||||
"""
|
||||
return LOCALEDOMAIN
|
||||
|
||||
def get_addon_translator(filename, domain="addon"):
|
||||
"""
|
||||
@ -173,48 +179,3 @@ def sngettext(singular, plural, n, sep='|'):
|
||||
sep_idx = singular.rfind(sep)
|
||||
msgval = singular[sep_idx+1:]
|
||||
return msgval
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# Translator
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
class Translator:
|
||||
"""
|
||||
This class provides translated strings for the configured language.
|
||||
"""
|
||||
DEFAULT_TRANSLATION_STR = "default"
|
||||
|
||||
def __init__(self, lang=DEFAULT_TRANSLATION_STR):
|
||||
"""
|
||||
:param lang: The language to translate to.
|
||||
The language can be:
|
||||
* The name of any installed .mo file
|
||||
* "en" to use the message strings in the code
|
||||
* "default" to use the default translation being used by gettext.
|
||||
:type lang: string
|
||||
:return: nothing
|
||||
|
||||
"""
|
||||
if lang == Translator.DEFAULT_TRANSLATION_STR:
|
||||
self.trans = None
|
||||
else:
|
||||
# fallback=True will cause the translator to use English if
|
||||
# lang = "en" or if something goes wrong.
|
||||
self.trans = gettext.translation(LOCALEDOMAIN, languages=[lang],
|
||||
fallback=True)
|
||||
|
||||
def gettext(self, message):
|
||||
"""
|
||||
Return the translated string.
|
||||
|
||||
:param message: The message to be translated.
|
||||
:type message: string
|
||||
:returns: The translated message
|
||||
:rtype: unicode
|
||||
|
||||
"""
|
||||
if self.trans is None:
|
||||
return gettext.gettext(message)
|
||||
else:
|
||||
return self.trans.gettext(message)
|
||||
|
@ -25,8 +25,7 @@ pkgdata_PYTHON = \
|
||||
_string.py \
|
||||
_style.py \
|
||||
_surnamecolor.py \
|
||||
_text.py \
|
||||
_translation.py
|
||||
_text.py
|
||||
|
||||
pkgpyexecdir = @pkgpyexecdir@/gen/plug/menu
|
||||
pkgpythondir = @pkgpythondir@/gen/plug/menu
|
||||
|
@ -1,73 +0,0 @@
|
||||
#
|
||||
# Gramps - a GTK+/GNOME based genealogy program
|
||||
#
|
||||
# Copyright (C) 2009 Brian G. Matherly
|
||||
#
|
||||
# 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
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
# $Id: _filter.py 12756 2009-07-02 20:01:28Z gbritton $
|
||||
|
||||
"""
|
||||
Option class representing a list of available translators.
|
||||
"""
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
#
|
||||
# python modules
|
||||
#
|
||||
#------------------------------------------------------------------------
|
||||
from gettext import gettext as _
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# gramps modules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
from gen.plug.menu import EnumeratedListOption
|
||||
from TransUtils import get_available_translations, Translator
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# TranslationOption class
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
class TranslationOption(EnumeratedListOption):
|
||||
"""
|
||||
This class describes an option that provides a list of available
|
||||
translations. Each possible value represents one of the possible
|
||||
translations.
|
||||
"""
|
||||
def __init__(self, label):
|
||||
"""
|
||||
@param label: A friendly label to be applied to this option.
|
||||
Example: "Translation"
|
||||
@type label: string
|
||||
@return: nothing
|
||||
"""
|
||||
EnumeratedListOption.__init__(self, label,
|
||||
Translator.DEFAULT_TRANSLATION_STR)
|
||||
|
||||
self.add_item(Translator.DEFAULT_TRANSLATION_STR, _("default"))
|
||||
for tran in get_available_translations():
|
||||
self.add_item(tran, tran)
|
||||
|
||||
def get_translator(self):
|
||||
"""
|
||||
Return a translator for the currently selected translation.
|
||||
|
||||
@return: a translator object
|
||||
@rtype: TransUtils.Translator
|
||||
"""
|
||||
return Translator(self.get_value())
|
@ -17,7 +17,8 @@ pkgdata_PYTHON = \
|
||||
libmapservice.py\
|
||||
libmixin.py\
|
||||
libodfbackend.py\
|
||||
libplugins.gpr.py
|
||||
libplugins.gpr.py\
|
||||
libtranslate.py
|
||||
|
||||
pkgpyexecdir = @pkgpyexecdir@/plugins/lib
|
||||
pkgpythondir = @pkgpythondir@/plugins/lib
|
||||
|
@ -24,13 +24,6 @@
|
||||
Narrator class for use by plugins.
|
||||
"""
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# Standard Python modules
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
import gettext
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
#
|
||||
# GRAMPS modules
|
||||
@ -42,9 +35,9 @@ from gen.lib.eventroletype import EventRoleType
|
||||
from gen.lib.eventtype import EventType
|
||||
from gen.lib.familyreltype import FamilyRelType
|
||||
from BasicUtils import name_displayer as _nd
|
||||
import DateHandler
|
||||
import Utils
|
||||
from ReportBase import ReportUtils
|
||||
from libtranslate import Translator
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
@ -1461,7 +1454,7 @@ class Narrator(object):
|
||||
|
||||
def __init__(self, dbase, verbose=True, use_call_name=False,
|
||||
empty_date="", empty_place="",
|
||||
translate_text=gettext.gettext,
|
||||
translator=None,
|
||||
get_endnote_numbers=_get_empty_endnote_numbers):
|
||||
"""
|
||||
Initialize the narrator class.
|
||||
@ -1494,10 +1487,15 @@ class Narrator(object):
|
||||
self.__empty_date = empty_date
|
||||
self.__empty_place = empty_place
|
||||
self.__get_endnote_numbers = get_endnote_numbers
|
||||
self.__translate_text = translate_text
|
||||
self.__person = None
|
||||
self.__first_name = ""
|
||||
self.__first_name_used = False
|
||||
|
||||
if translator is None:
|
||||
translator = Translator(Translator.DEFAULT_TRANSLATION_STR)
|
||||
|
||||
self.__translate_text = translator.get_text
|
||||
self.__get_date = translator.get_date
|
||||
|
||||
def set_subject(self, person):
|
||||
"""
|
||||
@ -1546,7 +1544,7 @@ class Narrator(object):
|
||||
if birth_ref and birth_ref.ref:
|
||||
birth_event = self.__db.get_event_from_handle(birth_ref.ref)
|
||||
if birth_event:
|
||||
bdate = DateHandler.get_date(birth_event)
|
||||
bdate = self.__get_date(birth_event.get_date_object())
|
||||
bplace_handle = birth_event.get_place_handle()
|
||||
if bplace_handle:
|
||||
place = self.__db.get_place_from_handle(bplace_handle)
|
||||
@ -1657,7 +1655,7 @@ class Narrator(object):
|
||||
if death_ref and death_ref.ref:
|
||||
death_event = self.__db.get_event_from_handle(death_ref.ref)
|
||||
if death_event:
|
||||
ddate = DateHandler.get_date(death_event)
|
||||
ddate = self.__get_date(death_event.get_date_object())
|
||||
dplace_handle = death_event.get_place_handle()
|
||||
if dplace_handle:
|
||||
place = self.__db.get_place_from_handle(dplace_handle)
|
||||
@ -1773,7 +1771,7 @@ class Narrator(object):
|
||||
break
|
||||
|
||||
if burial:
|
||||
bdate = DateHandler.get_date(burial)
|
||||
bdate = self.__get_date(burial.get_date_object())
|
||||
bplace_handle = burial.get_place_handle()
|
||||
if bplace_handle:
|
||||
place = self.__db.get_place_from_handle(bplace_handle)
|
||||
@ -1880,7 +1878,7 @@ class Narrator(object):
|
||||
break
|
||||
|
||||
if baptism:
|
||||
bdate = DateHandler.get_date(baptism)
|
||||
bdate = self.__get_date(baptism.get_date_object())
|
||||
bplace_handle = baptism.get_place_handle()
|
||||
if bplace_handle:
|
||||
place = self.__db.get_place_from_handle(bplace_handle)
|
||||
@ -1987,7 +1985,7 @@ class Narrator(object):
|
||||
break
|
||||
|
||||
if christening:
|
||||
cdate = DateHandler.get_date(christening)
|
||||
cdate = self.__get_date(christening.get_date_object())
|
||||
cplace_handle = christening.get_place_handle()
|
||||
if cplace_handle:
|
||||
place = self.__db.get_place_from_handle(cplace_handle)
|
||||
@ -2088,7 +2086,7 @@ class Narrator(object):
|
||||
spouse_name = _nd.display(spouse)
|
||||
|
||||
if event:
|
||||
mdate = DateHandler.get_date(event)
|
||||
mdate = self.__get_date(event.get_date_object())
|
||||
if mdate:
|
||||
date = mdate
|
||||
place_handle = event.get_place_handle()
|
||||
|
@ -26,7 +26,6 @@
|
||||
# libcairo
|
||||
#
|
||||
#------------------------------------------------------------------------
|
||||
|
||||
register(GENERAL,
|
||||
id = 'libcairodoc',
|
||||
name = "Cairodoc lib",
|
||||
@ -45,7 +44,6 @@ authors_email = ["http://gramps-project.org"],
|
||||
# libformatting
|
||||
#
|
||||
#------------------------------------------------------------------------
|
||||
|
||||
register(GENERAL,
|
||||
id = 'libformatting',
|
||||
name = "FormattingHelper lib",
|
||||
@ -63,7 +61,6 @@ authors_email = ["http://gramps-project.org"],
|
||||
# libgrampsxml
|
||||
#
|
||||
#------------------------------------------------------------------------
|
||||
|
||||
register(GENERAL,
|
||||
id = 'libgrampsxml',
|
||||
name = "Grampsxml lib",
|
||||
@ -82,7 +79,6 @@ authors_email = ["http://gramps-project.org"],
|
||||
# libgrdb
|
||||
#
|
||||
#------------------------------------------------------------------------
|
||||
|
||||
register(GENERAL,
|
||||
id = 'libgrdb',
|
||||
name = "grdb lib",
|
||||
@ -100,7 +96,6 @@ authors_email = ["http://gramps-project.org"],
|
||||
# libholiday
|
||||
#
|
||||
#------------------------------------------------------------------------
|
||||
|
||||
register(GENERAL,
|
||||
id = 'libholiday',
|
||||
name = "holiday lib",
|
||||
@ -118,7 +113,6 @@ authors_email = ["http://gramps-project.org"],
|
||||
# llibhtmlbackend
|
||||
#
|
||||
#------------------------------------------------------------------------
|
||||
|
||||
register(GENERAL,
|
||||
id = 'libhtmlbackend',
|
||||
name = "htmlbackend lib",
|
||||
@ -136,7 +130,6 @@ authors_email = ["http://gramps-project.org"],
|
||||
# libhtmlconst
|
||||
#
|
||||
#------------------------------------------------------------------------
|
||||
|
||||
register(GENERAL,
|
||||
id = 'libhtmlconst',
|
||||
name = "htmlconst lib",
|
||||
@ -154,7 +147,6 @@ authors_email = ["http://gramps-project.org"],
|
||||
# libhtml
|
||||
#
|
||||
#------------------------------------------------------------------------
|
||||
|
||||
register(GENERAL,
|
||||
id = 'libhtml',
|
||||
name = "html lib",
|
||||
@ -172,7 +164,6 @@ authors_email = ["gerald.britton@gmail.com"],
|
||||
# libmapservice
|
||||
#
|
||||
#------------------------------------------------------------------------
|
||||
|
||||
register(GENERAL,
|
||||
id = 'libmapservice',
|
||||
name = "mapservice lib",
|
||||
@ -205,7 +196,6 @@ authors_email = ["brian@gramps-project.org"],
|
||||
# libodfbackend
|
||||
#
|
||||
#------------------------------------------------------------------------
|
||||
|
||||
register(GENERAL,
|
||||
id = 'libodfbackend',
|
||||
name = "odfbackend lib",
|
||||
@ -216,3 +206,19 @@ fname = 'libodfbackend.py',
|
||||
authors = ["The Gramps project"],
|
||||
authors_email = ["http://gramps-project.org"],
|
||||
)
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
#
|
||||
# libtranslate
|
||||
#
|
||||
#------------------------------------------------------------------------
|
||||
register(GENERAL,
|
||||
id = 'libtranslate',
|
||||
name = "translation lib",
|
||||
description = _("Provides Textual Translation.") ,
|
||||
version = '1.0',
|
||||
status = STABLE,
|
||||
fname = 'libtranslate.py',
|
||||
authors = ["Brian Matherly"],
|
||||
authors_email = ["brian@gramps-project.org"],
|
||||
)
|
||||
|
100
src/plugins/lib/libtranslate.py
Normal file
100
src/plugins/lib/libtranslate.py
Normal file
@ -0,0 +1,100 @@
|
||||
#
|
||||
# Gramps - a GTK+/GNOME based genealogy program
|
||||
#
|
||||
# Copyright (C) 2009 Brian G. Matherly
|
||||
#
|
||||
# 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
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
|
||||
# $Id: $
|
||||
|
||||
"""
|
||||
Translator class for use by plugins.
|
||||
"""
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
#
|
||||
# python modules
|
||||
#
|
||||
#------------------------------------------------------------------------
|
||||
import gettext
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
#
|
||||
# GRAMPS modules
|
||||
#
|
||||
#------------------------------------------------------------------------
|
||||
import TransUtils
|
||||
import DateHandler
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# Translator
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
class Translator:
|
||||
"""
|
||||
This class provides translated strings for the configured language.
|
||||
"""
|
||||
DEFAULT_TRANSLATION_STR = "default"
|
||||
|
||||
def __init__(self, lang=DEFAULT_TRANSLATION_STR):
|
||||
"""
|
||||
:param lang: The language to translate to.
|
||||
The language can be:
|
||||
* The name of any installed .mo file
|
||||
* "en" to use the message strings in the code
|
||||
* "default" to use the default translation being used by gettext.
|
||||
:type lang: string
|
||||
:return: nothing
|
||||
|
||||
"""
|
||||
if lang == Translator.DEFAULT_TRANSLATION_STR:
|
||||
self.__trans = None
|
||||
self.__dd = DateHandler.displayer
|
||||
else:
|
||||
# fallback=True will cause the translator to use English if
|
||||
# lang = "en" or if something goes wrong.
|
||||
self.__trans = gettext.translation(TransUtils.get_localedomain(),
|
||||
languages=[lang],
|
||||
fallback=True)
|
||||
self.__dd = DateHandler.LANG_TO_DISPLAY[lang](None)
|
||||
|
||||
def get_text(self, message):
|
||||
"""
|
||||
Return the translated string.
|
||||
|
||||
:param message: The message to be translated.
|
||||
:type message: string
|
||||
:returns: The translated message
|
||||
:rtype: unicode
|
||||
|
||||
"""
|
||||
if self.__trans is None:
|
||||
return gettext.gettext(message)
|
||||
else:
|
||||
return self.__trans.gettext(message)
|
||||
|
||||
def get_date(self, date):
|
||||
"""
|
||||
Return a string representing the date appropriate for the language being
|
||||
translated.
|
||||
|
||||
:param date: The date to be represented.
|
||||
:type date: :class:`~gen.lib.date.Date`
|
||||
:returns: The date as text in the proper language.
|
||||
:rtype: unicode
|
||||
"""
|
||||
return self.__dd.display(date)
|
@ -40,13 +40,14 @@ from BasicUtils import name_displayer
|
||||
from Errors import ReportError
|
||||
from gen.lib import ChildRefType
|
||||
from gen.plug.menu import BooleanOption, NumberOption, PersonOption, \
|
||||
TranslationOption
|
||||
EnumeratedListOption
|
||||
from gen.plug.docgen import (IndexMark, FontStyle, ParagraphStyle,
|
||||
FONT_SANS_SERIF, INDEX_TYPE_TOC,
|
||||
PARA_ALIGN_CENTER)
|
||||
from ReportBase import Report, ReportUtils, MenuReportOptions
|
||||
|
||||
import TransUtils
|
||||
from libnarrate import Narrator
|
||||
from libtranslate import Translator
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
#
|
||||
@ -98,10 +99,11 @@ class AncestorReport(Report):
|
||||
self.center_person = database.get_person_from_gramps_id(pid)
|
||||
if (self.center_person == None) :
|
||||
raise ReportError(_("Person %s is not in the Database") % pid )
|
||||
translator = menu.get_option_by_name('trans').get_translator()
|
||||
self._ = translator.gettext
|
||||
language = menu.get_option_by_name('trans').get_value()
|
||||
translator = Translator(language)
|
||||
self._ = translator.get_text
|
||||
self.__narrator = Narrator(self.database,
|
||||
translate_text = translator.gettext)
|
||||
translator=translator)
|
||||
|
||||
def apply_filter(self, person_handle, index, generation=1):
|
||||
"""
|
||||
@ -267,7 +269,11 @@ class AncestorOptions(MenuReportOptions):
|
||||
namebrk.set_help(_("Indicates if a line break should follow the name."))
|
||||
menu.add_option(category_name, "namebrk", namebrk)
|
||||
|
||||
trans = TranslationOption(_("Translation"))
|
||||
trans = EnumeratedListOption(_("Translation"),
|
||||
Translator.DEFAULT_TRANSLATION_STR)
|
||||
trans.add_item(Translator.DEFAULT_TRANSLATION_STR, _("default"))
|
||||
for language in TransUtils.get_available_translations():
|
||||
trans.add_item(language, language)
|
||||
trans.set_help(_("The translation to be used for the report."))
|
||||
menu.add_option(category_name, "trans", trans)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user