From 82d6e5d2150533ec2eb811fe86b6120c39c0747c Mon Sep 17 00:00:00 2001 From: Paul Franklin Date: Thu, 26 Mar 2015 21:45:47 -0700 Subject: [PATCH] add DeferredFilter class (a subclass of GenericFilter) --- gramps/gen/filters/_genericfilter.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/gramps/gen/filters/_genericfilter.py b/gramps/gen/filters/_genericfilter.py index a69bd3119..6fd1f55ec 100644 --- a/gramps/gen/filters/_genericfilter.py +++ b/gramps/gen/filters/_genericfilter.py @@ -380,3 +380,28 @@ def GenericFilterFactory(namespace): return GenericRepoFilter elif namespace == 'Note': 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])