From 262440fceaddb75bbc8c8180dafbe8c861c5c6ef Mon Sep 17 00:00:00 2001 From: Nick Hall Date: Thu, 8 Jun 2023 18:31:05 +0100 Subject: [PATCH] Add a new primary surname substitution keyword option Adds a new "p" option to display the primary surname with prefix if present as part of a name format. For example: $n(f p) to display a name as a first name with primary surname only. --- gramps/gen/lib/surnamebase.py | 12 ++++++++++++ gramps/plugins/lib/libsubstkeyword.py | 5 +++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/gramps/gen/lib/surnamebase.py b/gramps/gen/lib/surnamebase.py index 13ec123cb..1fc807f0b 100644 --- a/gramps/gen/lib/surnamebase.py +++ b/gramps/gen/lib/surnamebase.py @@ -197,6 +197,18 @@ class SurnameBase: 'second': fsurn} return totalsurn.strip() + def get_primary(self): + """ + Return a fully formatted primary surname + """ + primary = self.get_primary_surname() + partsurn = primary.get_surname() + if primary.get_prefix(): + fsurn = _('%(first)s %(second)s') % {'first': primary.get_prefix(), + 'second': partsurn} + else: + fsurn = partsurn + return fsurn.strip() def get_upper_surname(self): """Return a fully formatted surname capitalized""" diff --git a/gramps/plugins/lib/libsubstkeyword.py b/gramps/plugins/lib/libsubstkeyword.py index 23faa0a19..33971f154 100644 --- a/gramps/plugins/lib/libsubstkeyword.py +++ b/gramps/plugins/lib/libsubstkeyword.py @@ -177,7 +177,7 @@ class NameFormat(GenericFormat): return (name.get_call_name() or name.get_first_name().split(' ')[0]) - code = "tfcnxslg" + code = "tfcnxslgp" upper = code.upper() function = [name.get_title, # t name.get_first_name, # f @@ -186,7 +186,8 @@ class NameFormat(GenericFormat): common, # x name.get_suffix, # s name.get_surname, # l - name.get_family_nick_name # g + name.get_family_nick_name, # g + name.get_primary # p ] return self.generic_format(name, code, upper, function)