diff --git a/src/gen/lib/styledtext.py b/src/gen/lib/styledtext.py index 63253528d..ea922687f 100644 --- a/src/gen/lib/styledtext.py +++ b/src/gen/lib/styledtext.py @@ -126,6 +126,43 @@ class StyledText(object): def __ne__(self, other): return self._string != other._string or self._tags != other._tags + def __mod__(self, other): + """Implement '%' operation on the class.""" + + # test whether the formatting operation is valid at all + self._string % other + + result = self.__class__(self._string, self._tags) + + i0 = 0 + while True: + i1 = result._string.find('%', i0) + if i1 < 0: + break + if result._string[i1+1] == '(': + i2 = result._string.find(')', i1+3) + param_name = result._string[i1+2:i2] + else: + i2 = i1 + param_name = None + for i3 in range(i2+1, len(result._string)): + if result._string[i3] in 'diouxXeEfFgGcrs%': + break + if param_name is not None: + param = other[param_name] + elif isinstance(other, tuple): + param = other[0] + other = other[1:] + else: + param = other + if not isinstance(param, StyledText): + param = StyledText('%' + result._string[i2+1:i3+1] % param) + (before, after) = result.split(result._string[i1:i3+1], 1) + result = before + param + after + i0 = i3 + 1 + + return result + # private methods diff --git a/src/plugins/Records.py b/src/plugins/Records.py index 6bf451ecd..9d0781483 100644 --- a/src/plugins/Records.py +++ b/src/plugins/Records.py @@ -215,10 +215,9 @@ def _find_records(db, filter, callname): father = db.get_person_from_handle(father_handle) mother = db.get_person_from_handle(mother_handle) - name = StyledText("").join([ - _Person_get_styled_primary_name(father, callname), - _(" and "), - _Person_get_styled_primary_name(mother, callname)]) + name = StyledText(_("%(father)s and %(mother)s")) % { + 'father': _Person_get_styled_primary_name(father, callname), + 'mother': _Person_get_styled_primary_name(mother, callname)} _record(None, family_mostchildren, len(family.get_child_ref_list()),