add DeferredFilter class (a subclass of GenericFilter)

This commit is contained in:
Paul Franklin 2015-03-26 21:45:47 -07:00 committed by Ross Gammon
parent e6cb3b1360
commit 82d6e5d215

View File

@ -380,3 +380,28 @@ def GenericFilterFactory(namespace):
return GenericRepoFilter return GenericRepoFilter
elif namespace == 'Note': elif namespace == 'Note':
return GenericNoteFilter return GenericNoteFilter
class DeferredFilter(GenericFilter):
"""
Filter class allowing for deferred translation of the filter name
"""
def __init__(self, filter_name, person_name):
GenericFilter.__init__(self, None)
self.name_pair = [filter_name, person_name]
def get_name(self, ulocale=glocale):
"""
return the filter name, possibly translated
If ulocale is passed in (a :class:`.GrampsLocale`) then
the translated value will be returned instead.
:param ulocale: allow deferred translation of strings
:type ulocale: a :class:`.GrampsLocale` instance
"""
self._ = ulocale.translation.gettext
if self.name_pair[1]:
return self._(self.name_pair[0]) % self.name_pair[1]
return self._(self.name_pair[0])