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
|
||||
punctuation.
|
||||
"""
|
||||
# d is a dict: dict[code] = (expr, word, translated word)
|
||||
|
||||
# First, go through and do internationalization-based
|
||||
# key-word replacement. Just replace ikeywords with
|
||||
# %codes (ie, replace "irstnamefay" with "%f", and
|
||||
# "IRSTNAMEFAY" for %F)
|
||||
d_keys = [(code, d[code][2]) for code in d.keys()]
|
||||
d_keys.sort(_make_cmp) # reverse sort by ikeyword
|
||||
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())
|
||||
if (len(format_str) > 2 and
|
||||
format_str[0] == '"' and
|
||||
format_str[-1] == '"'):
|
||||
pass
|
||||
else:
|
||||
d_keys = [(code, d[code][2]) for code in d.keys()]
|
||||
d_keys.sort(_make_cmp) # reverse sort by ikeyword
|
||||
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.
|
||||
# Just replace keywords with
|
||||
# %codes (ie, replace "firstname" with "%f", and
|
||||
# "FIRSTNAME" for %F)
|
||||
d_keys = [(code, d[code][1]) for code in d.keys()]
|
||||
d_keys.sort(_make_cmp) # reverse sort by keyword
|
||||
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())
|
||||
if (len(format_str) > 2 and
|
||||
format_str[0] == '"' and
|
||||
format_str[-1] == '"'):
|
||||
format_str = format_str[1:-1]
|
||||
else:
|
||||
d_keys = [(code, d[code][1]) for code in d.keys()]
|
||||
d_keys.sort(_make_cmp) # reverse sort by keyword
|
||||
# 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:
|
||||
codes = d.keys() + [c.upper() for c in d.keys()]
|
||||
# Next, list out the matching patterns:
|
||||
# If it starts with "!" however, treat the punctuation verbatim:
|
||||
if len(format_str) > 0 and format_str[0] == "!":
|
||||
format_str = format_str[1:]
|
||||
patterns = ["%(" + ("|".join(codes)) + ")", # %s
|
||||
]
|
||||
format_str = format_str[1:]
|
||||
else:
|
||||
patterns = [",\W*\(%(" + ("|".join(codes)) + ")\)", # ,\W*(%s)
|
||||
",\W*%(" + ("|".join(codes)) + ")", # ,\W*%s
|
||||
"\(%(" + ("|".join(codes)) + ")\)", # (%s)
|
||||
"%(" + ("|".join(codes)) + ")", # %s
|
||||
]
|
||||
|
||||
new_fmt = format_str
|
||||
|
||||
# replace the specific format string flags with a
|
||||
@ -408,7 +420,6 @@ def fn(%s):
|
||||
else:
|
||||
return p + str + s
|
||||
return "%s" %% (%s)""" % (args, new_fmt, ",".join(param))
|
||||
|
||||
exec(s)
|
||||
|
||||
return fn
|
||||
|
@ -502,14 +502,24 @@ class GrampsPreferences(ManagedWindow.ManagedWindow):
|
||||
if len(new_text) > 0 and text != new_text:
|
||||
# build a pattern from translated pattern:
|
||||
pattern = new_text
|
||||
for key in Utils.get_translations():
|
||||
if key in pattern:
|
||||
pattern = pattern.replace(key, Utils.get_keyword_from_translation(key))
|
||||
if (len(new_text) > 2 and
|
||||
new_text[0] == '"' and
|
||||
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:
|
||||
translation = pattern
|
||||
for key in Utils.get_keywords():
|
||||
if key in translation:
|
||||
translation = translation.replace(key, Utils.get_translation_from_keyword(key))
|
||||
if (len(new_text) > 2 and
|
||||
new_text[0] == '"' and
|
||||
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]
|
||||
node = self.fmt_model.get_iter(path)
|
||||
oldname = self.fmt_model.get_value(node, COL_NAME)
|
||||
|
Loading…
Reference in New Issue
Block a user