Added name format form: if surrounded in double quotes, only use % codes
svn: r11612
This commit is contained in:
parent
bd27cd20a1
commit
3785b8e74e
@ -334,45 +334,57 @@ class NameDisplay:
|
|||||||
Create the name display function and handles dependent
|
Create the name display function and handles dependent
|
||||||
punctuation.
|
punctuation.
|
||||||
"""
|
"""
|
||||||
|
# d is a dict: dict[code] = (expr, word, translated word)
|
||||||
|
|
||||||
# First, go through and do internationalization-based
|
# First, go through and do internationalization-based
|
||||||
# key-word replacement. Just replace ikeywords with
|
# key-word replacement. Just replace ikeywords with
|
||||||
# %codes (ie, replace "irstnamefay" with "%f", and
|
# %codes (ie, replace "irstnamefay" with "%f", and
|
||||||
# "IRSTNAMEFAY" for %F)
|
# "IRSTNAMEFAY" for %F)
|
||||||
d_keys = [(code, d[code][2]) for code in d.keys()]
|
if (len(format_str) > 2 and
|
||||||
d_keys.sort(_make_cmp) # reverse sort by ikeyword
|
format_str[0] == '"' and
|
||||||
for (code, ikeyword) in d_keys:
|
format_str[-1] == '"'):
|
||||||
exp, keyword, ikeyword = d[code]
|
pass
|
||||||
ikeyword = unicode(ikeyword, "utf8")
|
else:
|
||||||
format_str = format_str.replace(ikeyword,"%"+ code)
|
d_keys = [(code, d[code][2]) for code in d.keys()]
|
||||||
format_str = format_str.replace(ikeyword.title(),"%"+ code)
|
d_keys.sort(_make_cmp) # reverse sort by ikeyword
|
||||||
format_str = format_str.replace(ikeyword.upper(),"%"+ code.upper())
|
for (code, ikeyword) in d_keys:
|
||||||
|
exp, keyword, ikeyword = d[code]
|
||||||
|
ikeyword = unicode(ikeyword, "utf8")
|
||||||
|
format_str = format_str.replace(ikeyword,"%"+ code)
|
||||||
|
format_str = format_str.replace(ikeyword.title(),"%"+ code)
|
||||||
|
format_str = format_str.replace(ikeyword.upper(),"%"+ code.upper())
|
||||||
# Next, go through and do key-word replacement.
|
# Next, go through and do key-word replacement.
|
||||||
# Just replace keywords with
|
# Just replace keywords with
|
||||||
# %codes (ie, replace "firstname" with "%f", and
|
# %codes (ie, replace "firstname" with "%f", and
|
||||||
# "FIRSTNAME" for %F)
|
# "FIRSTNAME" for %F)
|
||||||
d_keys = [(code, d[code][1]) for code in d.keys()]
|
if (len(format_str) > 2 and
|
||||||
d_keys.sort(_make_cmp) # reverse sort by keyword
|
format_str[0] == '"' and
|
||||||
for (code, keyword) in d_keys:
|
format_str[-1] == '"'):
|
||||||
exp, keyword, ikeyword = d[code]
|
format_str = format_str[1:-1]
|
||||||
keyword = unicode(keyword, "utf8")
|
else:
|
||||||
format_str = format_str.replace(keyword,"%"+ code)
|
d_keys = [(code, d[code][1]) for code in d.keys()]
|
||||||
format_str = format_str.replace(keyword.title(),"%"+ code)
|
d_keys.sort(_make_cmp) # reverse sort by keyword
|
||||||
format_str = format_str.replace(keyword.upper(),"%"+ code.upper())
|
# if in double quotes, just use % codes
|
||||||
|
for (code, keyword) in d_keys:
|
||||||
|
exp, keyword, ikeyword = d[code]
|
||||||
|
keyword = unicode(keyword, "utf8")
|
||||||
|
format_str = format_str.replace(keyword,"%"+ code)
|
||||||
|
format_str = format_str.replace(keyword.title(),"%"+ code)
|
||||||
|
format_str = format_str.replace(keyword.upper(),"%"+ code.upper())
|
||||||
# Get lower and upper versions of codes:
|
# Get lower and upper versions of codes:
|
||||||
codes = d.keys() + [c.upper() for c in d.keys()]
|
codes = d.keys() + [c.upper() for c in d.keys()]
|
||||||
# Next, list out the matching patterns:
|
# Next, list out the matching patterns:
|
||||||
# If it starts with "!" however, treat the punctuation verbatim:
|
# If it starts with "!" however, treat the punctuation verbatim:
|
||||||
if len(format_str) > 0 and format_str[0] == "!":
|
if len(format_str) > 0 and format_str[0] == "!":
|
||||||
format_str = format_str[1:]
|
|
||||||
patterns = ["%(" + ("|".join(codes)) + ")", # %s
|
patterns = ["%(" + ("|".join(codes)) + ")", # %s
|
||||||
]
|
]
|
||||||
|
format_str = format_str[1:]
|
||||||
else:
|
else:
|
||||||
patterns = [",\W*\(%(" + ("|".join(codes)) + ")\)", # ,\W*(%s)
|
patterns = [",\W*\(%(" + ("|".join(codes)) + ")\)", # ,\W*(%s)
|
||||||
",\W*%(" + ("|".join(codes)) + ")", # ,\W*%s
|
",\W*%(" + ("|".join(codes)) + ")", # ,\W*%s
|
||||||
"\(%(" + ("|".join(codes)) + ")\)", # (%s)
|
"\(%(" + ("|".join(codes)) + ")\)", # (%s)
|
||||||
"%(" + ("|".join(codes)) + ")", # %s
|
"%(" + ("|".join(codes)) + ")", # %s
|
||||||
]
|
]
|
||||||
|
|
||||||
new_fmt = format_str
|
new_fmt = format_str
|
||||||
|
|
||||||
# replace the specific format string flags with a
|
# replace the specific format string flags with a
|
||||||
@ -408,7 +420,6 @@ def fn(%s):
|
|||||||
else:
|
else:
|
||||||
return p + str + s
|
return p + str + s
|
||||||
return "%s" %% (%s)""" % (args, new_fmt, ",".join(param))
|
return "%s" %% (%s)""" % (args, new_fmt, ",".join(param))
|
||||||
|
|
||||||
exec(s)
|
exec(s)
|
||||||
|
|
||||||
return fn
|
return fn
|
||||||
|
@ -502,14 +502,24 @@ class GrampsPreferences(ManagedWindow.ManagedWindow):
|
|||||||
if len(new_text) > 0 and text != new_text:
|
if len(new_text) > 0 and text != new_text:
|
||||||
# build a pattern from translated pattern:
|
# build a pattern from translated pattern:
|
||||||
pattern = new_text
|
pattern = new_text
|
||||||
for key in Utils.get_translations():
|
if (len(new_text) > 2 and
|
||||||
if key in pattern:
|
new_text[0] == '"' and
|
||||||
pattern = pattern.replace(key, Utils.get_keyword_from_translation(key))
|
new_text[-1] == '"'):
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
for key in Utils.get_translations():
|
||||||
|
if key in pattern:
|
||||||
|
pattern = pattern.replace(key, Utils.get_keyword_from_translation(key))
|
||||||
# now build up a proper translation:
|
# now build up a proper translation:
|
||||||
translation = pattern
|
translation = pattern
|
||||||
for key in Utils.get_keywords():
|
if (len(new_text) > 2 and
|
||||||
if key in translation:
|
new_text[0] == '"' and
|
||||||
translation = translation.replace(key, Utils.get_translation_from_keyword(key))
|
new_text[-1] == '"'):
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
for key in Utils.get_keywords():
|
||||||
|
if key in translation:
|
||||||
|
translation = translation.replace(key, Utils.get_translation_from_keyword(key))
|
||||||
num, name, fmt = self.selected_fmt[COL_NUM:COL_EXPL]
|
num, name, fmt = self.selected_fmt[COL_NUM:COL_EXPL]
|
||||||
node = self.fmt_model.get_iter(path)
|
node = self.fmt_model.get_iter(path)
|
||||||
oldname = self.fmt_model.get_value(node, COL_NAME)
|
oldname = self.fmt_model.get_value(node, COL_NAME)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user