Added name format form: if surrounded in double quotes, only use % codes
svn: r11612
This commit is contained in:
parent
bd27cd20a1
commit
3785b8e74e
@ -334,10 +334,17 @@ 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)
|
||||||
|
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 = [(code, d[code][2]) for code in d.keys()]
|
||||||
d_keys.sort(_make_cmp) # reverse sort by ikeyword
|
d_keys.sort(_make_cmp) # reverse sort by ikeyword
|
||||||
for (code, ikeyword) in d_keys:
|
for (code, ikeyword) in d_keys:
|
||||||
@ -350,8 +357,14 @@ class NameDisplay:
|
|||||||
# 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)
|
||||||
|
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 = [(code, d[code][1]) for code in d.keys()]
|
||||||
d_keys.sort(_make_cmp) # reverse sort by keyword
|
d_keys.sort(_make_cmp) # reverse sort by keyword
|
||||||
|
# if in double quotes, just use % codes
|
||||||
for (code, keyword) in d_keys:
|
for (code, keyword) in d_keys:
|
||||||
exp, keyword, ikeyword = d[code]
|
exp, keyword, ikeyword = d[code]
|
||||||
keyword = unicode(keyword, "utf8")
|
keyword = unicode(keyword, "utf8")
|
||||||
@ -363,16 +376,15 @@ class NameDisplay:
|
|||||||
# 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,11 +502,21 @@ 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
|
||||||
|
if (len(new_text) > 2 and
|
||||||
|
new_text[0] == '"' and
|
||||||
|
new_text[-1] == '"'):
|
||||||
|
pass
|
||||||
|
else:
|
||||||
for key in Utils.get_translations():
|
for key in Utils.get_translations():
|
||||||
if key in pattern:
|
if key in pattern:
|
||||||
pattern = pattern.replace(key, Utils.get_keyword_from_translation(key))
|
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
|
||||||
|
if (len(new_text) > 2 and
|
||||||
|
new_text[0] == '"' and
|
||||||
|
new_text[-1] == '"'):
|
||||||
|
pass
|
||||||
|
else:
|
||||||
for key in Utils.get_keywords():
|
for key in Utils.get_keywords():
|
||||||
if key in translation:
|
if key in translation:
|
||||||
translation = translation.replace(key, Utils.get_translation_from_keyword(key))
|
translation = translation.replace(key, Utils.get_translation_from_keyword(key))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user